diff --git a/.github/scripts/publish_crates.sh b/.github/scripts/publish_crates.sh index df752379..4010d4cf 100755 --- a/.github/scripts/publish_crates.sh +++ b/.github/scripts/publish_crates.sh @@ -9,8 +9,9 @@ crates=( ./crossbundle/tools ./crossbundle/cli ./plugins/admob-android - ./plugins/play-games-services ./plugins/play-billing + ./plugins/play-core + ./plugins/play-games-services ) for crate in "${crates[@]}" do diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b6f36d86..49debc52 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -87,3 +87,10 @@ jobs: cd ./plugins/play-billing/android gradle build USERNAME=dodorare gradle publish + - name: Build and publish Crossbow Play Core library + env: + TOKEN: ${{ secrets.GH_CROSSBOW_PUBLISH_TOKEN }} + run: | + cd ./plugins/play-core/android + gradle build + USERNAME=dodorare gradle publish diff --git a/deny.toml b/deny.toml index d4163b15..715e2edb 100644 --- a/deny.toml +++ b/deny.toml @@ -5,7 +5,9 @@ vulnerability = "deny" unmaintained = "deny" yanked = "deny" notice = "deny" -ignore = [] +# Only needed because of https://github.com/netvl/xml-rs. +# TODO: Remove this when repository will be maintained again. +ignore = ["RUSTSEC-2022-0048"] [licenses] unlicensed = "deny" diff --git a/plugins/play-billing/Cargo.toml b/plugins/play-billing/Cargo.toml index b36415e9..ee659ed5 100644 --- a/plugins/play-billing/Cargo.toml +++ b/plugins/play-billing/Cargo.toml @@ -6,7 +6,7 @@ authors = ["DodoRare Team "] description = "Google Play Billing Plugin for Crossbow" repository = "https://github.com/dodorare/crossbow" license = "MIT OR Apache-2.0" -keywords = ["crossbow", "google", "admob", "android", "ads"] +keywords = ["crossbow", "google", "billing", "android"] readme = "README.md" exclude = ["android/"] diff --git a/plugins/play-billing/android/src/com/crossbow/play-billing/CrossbowPlayBilling.kt b/plugins/play-billing/android/src/com/crossbow/play_billing/CrossbowPlayBilling.kt similarity index 99% rename from plugins/play-billing/android/src/com/crossbow/play-billing/CrossbowPlayBilling.kt rename to plugins/play-billing/android/src/com/crossbow/play_billing/CrossbowPlayBilling.kt index 3e8e7ec9..b80c403f 100644 --- a/plugins/play-billing/android/src/com/crossbow/play-billing/CrossbowPlayBilling.kt +++ b/plugins/play-billing/android/src/com/crossbow/play_billing/CrossbowPlayBilling.kt @@ -29,7 +29,7 @@ import java.util.HashMap import java.util.Arrays import java.util.ArrayList -class CrossbowPlayBilling(crossbow: Crossbow?) : CrossbowPlugin(crossbow!!), +class CrossbowPlayBilling(crossbow: Crossbow) : CrossbowPlugin(crossbow), PurchasesUpdatedListener, BillingClientStateListener, PriceChangeConfirmationListener { private val billingClient: BillingClient private val skuDetailsCache = HashMap() @@ -49,7 +49,7 @@ class CrossbowPlayBilling(crossbow: Crossbow?) : CrossbowPlugin(crossbow!!), } override val pluginName: String - get() = "CrossbowPlayBilling" + get() = javaClass.simpleName override val pluginSignals: Set get() { @@ -308,4 +308,4 @@ class CrossbowPlayBilling(crossbow: Crossbow?) : CrossbowPlugin(crossbow!!), fun setObfuscatedProfileId(profileId: String) { obfuscatedProfileId = profileId } -} \ No newline at end of file +} diff --git a/plugins/play-billing/android/src/com/crossbow/play-billing/CrossbowPlayBillingUtils.kt b/plugins/play-billing/android/src/com/crossbow/play_billing/CrossbowPlayBillingUtils.kt similarity index 99% rename from plugins/play-billing/android/src/com/crossbow/play-billing/CrossbowPlayBillingUtils.kt rename to plugins/play-billing/android/src/com/crossbow/play_billing/CrossbowPlayBillingUtils.kt index 61242073..e7858c8d 100644 --- a/plugins/play-billing/android/src/com/crossbow/play-billing/CrossbowPlayBillingUtils.kt +++ b/plugins/play-billing/android/src/com/crossbow/play_billing/CrossbowPlayBillingUtils.kt @@ -90,4 +90,4 @@ object CrossbowPlayBillingUtils { } return skuDetailsDictionaries } -} \ No newline at end of file +} diff --git a/plugins/play-core/Cargo.toml b/plugins/play-core/Cargo.toml new file mode 100644 index 00000000..8a622620 --- /dev/null +++ b/plugins/play-core/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "play-core" +version = "0.2.0" +edition = "2021" +authors = ["DodoRare Team "] +description = "Google Play Core Plugin for Crossbow" +repository = "https://github.com/dodorare/crossbow" +license = "MIT OR Apache-2.0" +keywords = ["crossbow", "google", "core", "android"] +readme = "README.md" +exclude = ["android/"] + +[dependencies] +crossbow-android = { path = "../../platform/android", version = "0.2.0" } diff --git a/plugins/play-core/README.md b/plugins/play-core/README.md new file mode 100644 index 00000000..f2652cef --- /dev/null +++ b/plugins/play-core/README.md @@ -0,0 +1,65 @@ +# Crossbow Google Play Core Plugin + +[![Crate Info](https://img.shields.io/crates/v/play-core.svg)](https://crates.io/crates/play-core) +[![Documentation](https://img.shields.io/badge/docs.rs-play_core-green)](https://docs.rs/play-core/) +[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/dodorare/crossbow#license) +[![GitHub Stars](https://img.shields.io/github/stars/dodorare/crossbow.svg?style=social)](https://github.com/dodorare/crossbow/stargazers) + +## About + +This project is a Crossbow Plugin for [Google Play Core libraries](https://developer.android.com/guide/playcore) written in Rust and Kotlin. + +## Installation + +> **Important:** Before using this plugin please read more about [Google Play Core libraries](https://developer.android.com/guide/playcore) and [In-app updates](https://developer.android.com/guide/playcore/in-app-updates). + +Just add Rust dependencies like this: + +```toml +[dependencies] +crossbow = "0.2.0" +[target.'cfg(target_os = "android")'.dependencies] +play-core = "0.2.0" +``` + +And finally, add this to your Crossbow Android configuration: + +```toml +[package.metadata.android] +plugins_remote = ["com.crossbow.play_core:play_core:0.2.0"] +``` + +> That's it, now you can start using Play Core! + +## Usage + +First step is plugin initialization. In your rust project, you will need to initialize `Crossbow` instance and then get **Android** plugin: + +```rust +#![cfg(target_os = "android")] + +use crossbow::android::*; +let crossbow = CrossbowInstance::new(); +let play_core: play_core::PlayCorePlugin = crossbow.get_plugin()?; +``` + +After plugin initialization you can use supported features. For example to start connection and query purchases you can use: + +```rust +play_core.check_update()?; +play_core.in_progress_update()?; +``` + +To read signals: + +```rust +if let Ok(signal) = play_core.get_receiver().recv().await { + println!("Signal: {:?}", signal); +} +``` + +Complete documentation you can find [here](https://docs.rs/play-core/). + +## Future work + +Ideally we will get rid of the Java wrapper and will create C++ wrapper around [Google Play Core native](https://developer.android.com/reference/native/play/core) - so that it will support all features and will work faster than with JNI. If you want to help us with it - welcome! diff --git a/plugins/play-core/android/AndroidManifest.xml b/plugins/play-core/android/AndroidManifest.xml new file mode 100644 index 00000000..6c79cccb --- /dev/null +++ b/plugins/play-core/android/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/plugins/play-core/android/build.gradle b/plugins/play-core/android/build.gradle new file mode 100644 index 00000000..9360f3d5 --- /dev/null +++ b/plugins/play-core/android/build.gradle @@ -0,0 +1,77 @@ +buildscript { + apply from: "config.gradle" + repositories { + google() + mavenCentral() + mavenCrossbowGithub() + } + dependencies { + classpath libraries.androidGradlePlugin + classpath libraries.kotlinGradlePlugin + } +} + +apply plugin: "com.android.library" +apply plugin: "org.jetbrains.kotlin.android" +apply from: "config.gradle" +apply from: "publish.gradle" + +repositories { + google() + mavenCentral() + mavenCrossbowGithub() +} + +dependencies { + implementation libraries.kotlinStdLib + implementation libraries.androidxAppcompat + implementation "com.google.android.play:app-update-ktx:2.0.0" + + if (rootProject.findProject(":crossbow:lib")) { + implementation project(":crossbow:lib") + } else if(getCustomBuildMode()) { + // Custom build mode. In this scenario this project is the only one around and the Crossbow + // library is available through the pre-generated crossbow-lib.*.aar android archive files. + debugImplementation fileTree(dir: "../libs/debug", include: ["*.jar", "*.aar"]) + releaseImplementation fileTree(dir: "../libs/release", include: ["*.jar", "*.aar"]) + } else { + implementation libraries.crossbowLibrary + } +} + +android { + compileSdkVersion versions.compileSdk + buildToolsVersion versions.buildTools + + compileOptions { + sourceCompatibility versions.javaVersion + targetCompatibility versions.javaVersion + } + + kotlinOptions { + jvmTarget = versions.javaVersion + } + + defaultConfig { + versionCode 1 + versionName "1.0" + minSdkVersion versions.minSdk + targetSdkVersion versions.targetSdk + + missingDimensionStrategy "products", "template" + } + + lintOptions { + abortOnError false + disable "MissingTranslation", "UnusedResources" + } + + sourceSets { + main { + manifest.srcFile "AndroidManifest.xml" + java.srcDirs = ["src"] + assets.srcDirs = ["assets"] + res.srcDirs = ["res"] + } + } +} diff --git a/plugins/play-core/android/config.gradle b/plugins/play-core/android/config.gradle new file mode 100644 index 00000000..cb1d9746 --- /dev/null +++ b/plugins/play-core/android/config.gradle @@ -0,0 +1,42 @@ +ext.versions = [ + crossbowLibrary : "0.2.0", + androidGradlePlugin: "7.0.0", + compileSdk : 31, + minSdk : 19, + targetSdk : 30, + buildTools : "30.0.3", + kotlinVersion : "1.6.21", + appcompatVersion : "1.4.0", + javaVersion : 11, +] + +ext.libraries = [ + androidGradlePlugin: "com.android.tools.build:gradle:$versions.androidGradlePlugin", + kotlinGradlePlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion", + kotlinStdLib : "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlinVersion", + androidxAppcompat : "androidx.appcompat:appcompat:$versions.appcompatVersion", + crossbowLibrary : "com.crossbow.library:lib:$versions.crossbowLibrary" +] + +/** + * Parse the project properties for the 'custom_build_mode' property and return + * it for turning on custom build mode. + */ +ext.getCustomBuildMode = { -> + // Retrieve the custom_build_mode from the project property set by the Crossbow build command. + return project.hasProperty("custom_build_mode") ? project.property("custom_build_mode") : false +} + +/** + * Add Crossbow Gihub Maven repository with credentials to the project. + */ +ext.mavenCrossbowGithub = { + repositories.maven { + url = uri("https://maven.pkg.github.com/dodorare/crossbow") + credentials { + // Use this open machine user token because repo requires authentication + username = "token" + password = "\u0067hp_YQdtzsNYrpQM3lmZPOXYHpC5GXiord4Qodew" + } + } +} diff --git a/plugins/play-core/android/gradle.properties b/plugins/play-core/android/gradle.properties new file mode 100644 index 00000000..92516dbc --- /dev/null +++ b/plugins/play-core/android/gradle.properties @@ -0,0 +1,26 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +android.enableJetifier=true + +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true diff --git a/plugins/play-core/android/gradle/wrapper/gradle-wrapper.jar b/plugins/play-core/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..41d9927a Binary files /dev/null and b/plugins/play-core/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/plugins/play-core/android/gradle/wrapper/gradle-wrapper.properties b/plugins/play-core/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..41dfb879 --- /dev/null +++ b/plugins/play-core/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/plugins/play-core/android/gradlew b/plugins/play-core/android/gradlew new file mode 100755 index 00000000..1b6c7873 --- /dev/null +++ b/plugins/play-core/android/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/plugins/play-core/android/gradlew.bat b/plugins/play-core/android/gradlew.bat new file mode 100644 index 00000000..ac1b06f9 --- /dev/null +++ b/plugins/play-core/android/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/plugins/play-core/android/publish.gradle b/plugins/play-core/android/publish.gradle new file mode 100644 index 00000000..cba7af2a --- /dev/null +++ b/plugins/play-core/android/publish.gradle @@ -0,0 +1,49 @@ +apply plugin: "maven-publish" + +publishing { + repositories { + maven { + name = "com.crossbow.play_core" + version = versions.crossbowLibrary + description = "Crossbow Play Core Android Library" + url = uri("https://maven.pkg.github.com/dodorare/crossbow") + credentials { + username = project.findProperty("gpr.user") ?: System.getenv("USERNAME") + password = project.findProperty("gpr.key") ?: System.getenv("TOKEN") + } + } + } + publications { + gpr(MavenPublication) { + groupId = "com.crossbow.play_core" + artifact("$buildDir/outputs/aar/$artifactId-release.aar") + + pom.withXml { + final dependenciesNode = asNode().appendNode("dependencies") + ext.addDependency = { Dependency dep, String scope -> + if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified") + return + final dependencyNode = dependenciesNode.appendNode("dependency") + dependencyNode.appendNode("groupId", dep.group) + dependencyNode.appendNode("artifactId", dep.name) + dependencyNode.appendNode("version", dep.version) + dependencyNode.appendNode("scope", scope) + if (!dep.transitive) { + final exclusionNode = dependencyNode.appendNode("exclusions").appendNode("exclusion") + exclusionNode.appendNode("groupId", "*") + exclusionNode.appendNode("artifactId", "*") + } else if (!dep.properties.excludeRules.empty) { + final exclusionNode = dependencyNode.appendNode("exclusions").appendNode("exclusion") + dep.properties.excludeRules.each { ExcludeRule rule -> + exclusionNode.appendNode("groupId", rule.group ?: "*") + exclusionNode.appendNode("artifactId", rule.module ?: "*") + } + } + } + configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") } + // configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") } + // configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") } + } + } + } +} diff --git a/plugins/play-core/android/settings.gradle b/plugins/play-core/android/settings.gradle new file mode 100644 index 00000000..d9c46e61 --- /dev/null +++ b/plugins/play-core/android/settings.gradle @@ -0,0 +1,8 @@ +// Configure the root project. +rootProject.name = "play_core" + +if (System.getenv("TOKEN") == null) { + include ":crossbow" + project(":crossbow").projectDir = new File("../../../platform/android/java/") + include ":crossbow:lib" +} diff --git a/plugins/play-core/android/src/com/crossbow/play_core/CrossbowPlayCore.kt b/plugins/play-core/android/src/com/crossbow/play_core/CrossbowPlayCore.kt new file mode 100644 index 00000000..ba97a19b --- /dev/null +++ b/plugins/play-core/android/src/com/crossbow/play_core/CrossbowPlayCore.kt @@ -0,0 +1,62 @@ +@file:Suppress("DEPRECATION") + +package com.crossbow.play_core + +import androidx.collection.ArraySet +import com.crossbow.library.Crossbow +import com.crossbow.library.plugin.SignalInfo +import com.crossbow.library.plugin.CrossbowPlugin +import com.crossbow.library.plugin.ExposedToCrossbow + +import com.google.android.play.core.appupdate.AppUpdateManager +import com.google.android.play.core.appupdate.AppUpdateManagerFactory +import com.google.android.play.core.install.model.AppUpdateType +import com.google.android.play.core.install.model.UpdateAvailability + +class CrossbowPlayCore(crossbow: Crossbow) : CrossbowPlugin(crossbow) { + private var appUpdate: AppUpdateManager + private val REQUEST_CODE = 100 + + init { + appUpdate = AppUpdateManagerFactory.create(crossbow.activity!!) + } + + override val pluginName: String + get() = javaClass.simpleName + + override val pluginSignals: Set + get() { + val signals: MutableSet = ArraySet() + signals.add(SignalInfo("start_update_flow")) + signals.add(SignalInfo("continue_update_flow")) + return signals + } + + @ExposedToCrossbow + fun checkUpdate() { + // Checks that the platform will allow the specified type of update. + appUpdate.appUpdateInfo.addOnSuccessListener { appUpdateInfo -> + if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE + // This example applies an immediate update. To apply a flexible update + // instead, pass in AppUpdateType.FLEXIBLE + && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE) + ) { + // Request the update. + appUpdate.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, crossbow.activity, REQUEST_CODE) + emitSignal("start_update_flow") + } + } + } + + @ExposedToCrossbow + fun inProgressUpdate() { + // Checks that the platform will allow the specified type of update. + appUpdate.appUpdateInfo.addOnSuccessListener { appUpdateInfo -> + if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) { + // Request the update. + appUpdate.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, crossbow.activity, REQUEST_CODE) + emitSignal("continue_update_flow") + } + } + } +} diff --git a/plugins/play-core/src/lib.rs b/plugins/play-core/src/lib.rs new file mode 100644 index 00000000..b24b2f9e --- /dev/null +++ b/plugins/play-core/src/lib.rs @@ -0,0 +1,44 @@ +use crossbow_android::{error::*, jni::JavaVM, plugin::*}; +use std::sync::Arc; + +pub struct PlayCorePlugin { + singleton: Arc, + vm: Arc, +} + +impl CrossbowPlugin for PlayCorePlugin { + fn from_java_vm(vm: Arc) -> Result + where + Self: Sized, + { + let singleton = get_jni_singleton(Self::get_plugin_name()).ok_or_else(|| { + AndroidError::SingletonNotRegistered(Self::get_plugin_name().to_owned()) + })?; + Ok(Self { singleton, vm }) + } + + fn get_plugin_name() -> &'static str { + "CrossbowPlayCore" + } + + fn get_receiver(&self) -> &Receiver { + self.singleton.get_receiver() + } +} + +impl PlayCorePlugin { + pub fn check_update(&self) -> Result<()> { + let jnienv = self.vm.attach_current_thread_as_daemon()?; + self.singleton.call_method(&jnienv, "checkUpdate", &[])?; + jnienv.exception_check()?; + Ok(()) + } + + pub fn in_progress_update(&self) -> Result<()> { + let jnienv = self.vm.attach_current_thread_as_daemon()?; + self.singleton + .call_method(&jnienv, "inProgressUpdate", &[])?; + jnienv.exception_check()?; + Ok(()) + } +} diff --git a/plugins/play-games-services/Cargo.toml b/plugins/play-games-services/Cargo.toml index cb4129d4..a95aaef5 100644 --- a/plugins/play-games-services/Cargo.toml +++ b/plugins/play-games-services/Cargo.toml @@ -6,7 +6,7 @@ authors = ["DodoRare Team "] description = "Google Play Games Services Plugin for Crossbow" repository = "https://github.com/dodorare/crossbow" license = "MIT OR Apache-2.0" -keywords = ["crossbow", "google", "admob", "android", "ads"] +keywords = ["crossbow", "google", "games", "services", "android"] readme = "README.md" exclude = ["android/"] diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/ConnectionController.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/ConnectionController.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/ConnectionController.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/ConnectionController.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/CrossbowPlayGamesServices.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/CrossbowPlayGamesServices.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/CrossbowPlayGamesServices.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/CrossbowPlayGamesServices.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/accountinfo/PlayerInfoController.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/accountinfo/PlayerInfoController.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/accountinfo/PlayerInfoController.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/accountinfo/PlayerInfoController.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/accountinfo/PlayerInfoListener.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/accountinfo/PlayerInfoListener.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/accountinfo/PlayerInfoListener.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/accountinfo/PlayerInfoListener.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/achievements/AchievementsController.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/achievements/AchievementsController.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/achievements/AchievementsController.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/achievements/AchievementsController.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/achievements/AchievementsListener.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/achievements/AchievementsListener.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/achievements/AchievementsListener.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/achievements/AchievementsListener.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/events/EventsController.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/events/EventsController.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/events/EventsController.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/events/EventsController.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/events/EventsListener.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/events/EventsListener.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/events/EventsListener.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/events/EventsListener.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/leaderboards/LeaderBoardsListener.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/leaderboards/LeaderBoardsListener.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/leaderboards/LeaderBoardsListener.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/leaderboards/LeaderBoardsListener.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/leaderboards/LeaderboardsController.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/leaderboards/LeaderboardsController.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/leaderboards/LeaderboardsController.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/leaderboards/LeaderboardsController.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/model/Achivemements.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/model/Achivemements.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/model/Achivemements.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/model/Achivemements.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/model/PlayerInfo.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/model/PlayerInfo.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/model/PlayerInfo.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/model/PlayerInfo.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/model/PlayerStats.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/model/PlayerStats.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/model/PlayerStats.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/model/PlayerStats.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/savedgames/SavedGamesController.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/savedgames/SavedGamesController.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/savedgames/SavedGamesController.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/savedgames/SavedGamesController.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/savedgames/SavedGamesListener.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/savedgames/SavedGamesListener.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/savedgames/SavedGamesListener.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/savedgames/SavedGamesListener.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/signin/SignInController.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/signin/SignInController.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/signin/SignInController.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/signin/SignInController.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/signin/SignInListener.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/signin/SignInListener.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/signin/SignInListener.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/signin/SignInListener.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/stats/PlayerStatsController.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/stats/PlayerStatsController.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/stats/PlayerStatsController.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/stats/PlayerStatsController.kt diff --git a/plugins/play-games-services/android/src/com/crossbow/play-games-services/stats/PlayerStatsListener.kt b/plugins/play-games-services/android/src/com/crossbow/play_games_services/stats/PlayerStatsListener.kt similarity index 100% rename from plugins/play-games-services/android/src/com/crossbow/play-games-services/stats/PlayerStatsListener.kt rename to plugins/play-games-services/android/src/com/crossbow/play_games_services/stats/PlayerStatsListener.kt