Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix android build on Windows, start_apk function and Kotlin linking #109

Merged
merged 8 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ jobs:
profile: minimal
toolchain: stable
override: true
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: adopt
java-version: 11
- name: Install gradle
uses: gradle/gradle-build-action@v2
with:
distribution: temurin
gradle-version: 7.4
- name: Install Apple targets
run: |
rustup upgrade
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crossbow"
version = "0.1.5"
version = "0.1.6"
edition = "2021"
authors = ["DodoRare Team <support@dodorare.com>"]
description = "Cross-Platform Rust Toolkit for Games 🏹"
Expand All @@ -12,7 +12,7 @@ exclude = [".github/**/*"]

[dependencies]
# Platform-specific dependencies
crossbow-android = { path = "platform/android", version = "0.1.5", optional = true }
crossbow-android = { path = "platform/android", version = "0.1.6", optional = true }

[target.'cfg(target_os = "android")'.dependencies]
ndk-glue = "0.6.2"
Expand Down
4 changes: 2 additions & 2 deletions crossbundle/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crossbundle"
version = "0.1.5"
version = "0.1.6"
edition = "2021"
authors = ["DodoRare Team <support@dodorare.com>"]
description = "Build and publish apps for Android/iOS"
Expand All @@ -18,7 +18,7 @@ name = "crossbundle"
path = "src/main.rs"

[dependencies]
crossbundle-tools = { path = "../tools", version = "0.1.5" }
crossbundle-tools = { path = "../tools", version = "0.1.6" }
android-tools = "0.2.8"
clap = { version = "3.2.8", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
Expand Down
9 changes: 9 additions & 0 deletions crossbundle/cli/src/commands/build/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use android_tools::java_tools::{AabKey, JarSigner};
use clap::Parser;
use crossbundle_tools::{
commands::android::{self, rust_compile},
error::CommandExt,
tools::*,
types::*,
utils::Config,
Expand Down Expand Up @@ -112,6 +113,14 @@ impl AndroidBuildCommand {
"Gradle project generated",
gradle_project_path.to_str().unwrap(),
)?;

config.status("Building Gradle project")?;
let mut gradle = android::gradle_init()?;
gradle
.arg("build")
.arg("-p")
.arg(dunce::simplified(&gradle_project_path));
gradle.output_err(true)?;
Ok((android_manifest, sdk, gradle_project_path))
}

Expand Down
18 changes: 15 additions & 3 deletions crossbundle/cli/src/commands/run/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ impl AndroidRunCommand {
config.status("Installing APKs file")?;
InstallApks::new(&apks_path).run()?;
config.status("Starting APK file")?;
android::start_apk(&sdk, &android_manifest.package)?;
android::start_apk(
&sdk,
&android_manifest.package,
"android.app.NativeActivity",
)?;
config.status("Run finished successfully")?;
} else if self.build_command.lib.is_some() {
config.status("Can not run dynamic library")?;
Expand All @@ -45,7 +49,11 @@ impl AndroidRunCommand {
config.status("Installing APK file")?;
android::install_apk(&sdk, &apk_path)?;
config.status("Starting APK file")?;
android::start_apk(&sdk, &android_manifest.package)?;
android::start_apk(
&sdk,
&android_manifest.package,
"android.app.NativeActivity",
)?;
config.status("Run finished successfully")?;
} else {
let (android_manifest, sdk, gradle_project_path) = self.build_command.build_gradle(
Expand All @@ -61,7 +69,11 @@ impl AndroidRunCommand {
.arg(dunce::simplified(&gradle_project_path));
gradle.output_err(true)?;
config.status("Starting APK file")?;
android::start_apk(&sdk, &android_manifest.package)?;
android::start_apk(
&sdk,
&android_manifest.package,
"com.crossbow.game.CrossbowApp",
)?;
config.status("Run finished successfully")?;
}
Ok(())
Expand Down
2 changes: 2 additions & 0 deletions crossbundle/cli/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct Metadata {
#[serde(default)]
pub android: AndroidConfig,
#[serde(default)]
pub apple: AppleConfig,
}
8 changes: 0 additions & 8 deletions crossbundle/cli/tests/cargo_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,8 @@ fn test_cargo_metadata() {
</intent-filter>
<meta-data android:name="android.app.lib_name" android:value="example" />
</activity>
<service android:name="UpdateService" />
<meta-data android:name="com.oculus.vr.focusaware" android:value="true" />
</application>
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="30" />
<uses-feature android:name="android.hardware.vulkan.level" android:required="true" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="30" />
<uses-permission-sdk-23 android:name="android.permission.INTERNET" android:maxSdkVersion="30" />
<queries>
<provider android:authorities="org.khronos.openxr.runtime_broker;org.khronos.openxr.system_runtime_broker" android:name="org.khronos.openxr" />
</queries>
</manifest>
"#;
let expected_manifest = from_str(expected_manifest).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crossbundle/tools/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crossbundle-tools"
version = "0.1.5"
version = "0.1.6"
edition = "2021"
authors = ["DodoRare Team <support@dodorare.com>"]
description = "Build and publish apps for Android/iOS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn get_settings_gradle(dependencies: &[GradleDependencyProject]) -> Result<Strin
);
}
result = format!(
"{}project(\"{}\").projectDir = new File(\"{}\")\n",
"{}project(\"{}\").projectDir = new File({:?})\n",
result,
dependency.include,
dir_path.to_string_lossy()
Expand Down
4 changes: 2 additions & 2 deletions crossbundle/tools/src/commands/android/start_apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use crate::tools::AndroidSdk;

/// Starts installed APK or AAB on emulator or connected device.
/// Runs `adb shell am start ...` command
pub fn start_apk(sdk: &AndroidSdk, package: &str) -> Result<()> {
pub fn start_apk(sdk: &AndroidSdk, package: &str, activity: &str) -> Result<()> {
let mut adb = sdk.platform_tool(bin!("adb"))?;
adb.arg("shell")
.arg("am")
.arg("start")
.arg("-a")
.arg("android.intent.action.MAIN")
.arg("-n")
.arg(format!("{}/android.app.NativeActivity", package));
.arg(format!("{}/{}", package, activity));
adb.output_err(true)?;
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ anyhow = "1.0"
macroquad = "0.3.7"
"#;

pub const MINIMAL_MQ_GRADLE_CARGO_TOML_VALUE: &str = r#"
[package]
name = "example"
version = "0.1.0"
authors = ["DodoRare Team <support@dodorare.com>"]
edition = "2021"

[dependencies]
crossbow = { git = "https://github.com/dodorare/crossbow" }
anyhow = "1.0"
macroquad = "0.3.7"

[package.metadata.android]
target_sdk_version = 30

[[package.metadata.android.plugins_local_projects]]
include = ":crossbow"
dont_implement = true
project_dir = "../../platform/android/java"

[[package.metadata.android.plugins_local_projects]]
include = ":crossbow:lib"
"#;

pub const CARGO_TOML_VALUE: &str = r#"
[package.metadata.android]
app_name = "example"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ pub fn gen_minimal_project(
let file_path = out_dir.join("Cargo.toml");
let mut file = File::create(file_path)?;
if macroquad_project {
file.write_all(MINIMAL_MQ_CARGO_TOML_VALUE.as_bytes())?;
file.write_all(MINIMAL_MQ_GRADLE_CARGO_TOML_VALUE.as_bytes())?;
} else if !minimal_cargo_toml {
file.write_all(CARGO_TOML_VALUE.as_bytes())?;
} else {
file.write_all(MINIMAL_BEVY_CARGO_TOML_VALUE.as_bytes())?;
}
if !minimal_cargo_toml {
file.write_all(CARGO_TOML_VALUE.as_bytes())?;
}
// Create src folder
let src_path = out_dir.join("src");
create_dir(&src_path)?;
Expand Down
3 changes: 3 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ allow = [
"Apache-2.0",
"BSD-3-Clause",
]
exceptions = [
{ name = "unicode-ident", allow = ["Unicode-DFS-2016"] },
]
default = "deny"

[[licenses.clarify]]
Expand Down
4 changes: 2 additions & 2 deletions examples/bevy-2d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "bevy-2d"
version = "0.1.5"
version = "0.1.6"
authors = ["DodoRare Team <support@dodorare.com>"]
edition = "2021"

[dependencies]
crossbow = { version = "0.1.5", path = "../../" }
crossbow = { version = "0.1.6", path = "../../" }
log = "0.4"
anyhow = "1.0"
bevy = { version = "0.7.0", features = ["mp3"] }
Expand Down
4 changes: 2 additions & 2 deletions examples/bevy-3d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "bevy-3d"
version = "0.1.5"
version = "0.1.6"
authors = ["DodoRare Team <support@dodorare.com>"]
edition = "2021"

[dependencies]
crossbow = { version = "0.1.5", path = "../../" }
crossbow = { version = "0.1.6", path = "../../" }
log = "0.4"
anyhow = "1.0"
bevy = "0.7.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy-explorer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy-explorer"
version = "0.1.5"
version = "0.1.6"
authors = ["DodoRare Team <support@dodorare.com>"]
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions examples/macroquad-3d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "macroquad-3d"
version = "0.1.5"
version = "0.1.6"
authors = ["DodoRare Team <support@dodorare.com>"]
edition = "2021"

[dependencies]
crossbow = { version = "0.1.5", path = "../../" }
crossbow = { version = "0.1.6", path = "../../" }
log = "0.4"
anyhow = "1.0"
macroquad = "0.3.7"
Expand Down
8 changes: 4 additions & 4 deletions examples/macroquad-permissions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "macroquad-permissions"
version = "0.1.5"
version = "0.1.6"
authors = ["DodoRare Team <support@dodorare.com>"]
edition = "2021"

[dependencies]
crossbow = { version = "0.1.5", path = "../../" }
crossbow-admob = { version = "0.1.5", path = "../../plugins/admob" }
crossbow = { version = "0.1.6", path = "../../" }
crossbow-admob = { version = "0.1.6", path = "../../plugins/admob" }
log = "0.4"
anyhow = "1.0"
macroquad = "0.3.7"
Expand All @@ -23,7 +23,7 @@ build_targets = ["aarch64-linux-android"]
assets = "assets"
res = "res/android"

# plugins_remote = ["com.crossbow.admob:admob:0.1.5"]
# plugins_remote = ["com.crossbow.admob:admob:0.1.6"]

[[package.metadata.android.plugins_local_projects]]
include = ":crossbow"
Expand Down
2 changes: 1 addition & 1 deletion platform/android/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crossbow-android"
version = "0.1.5"
version = "0.1.6"
edition = "2021"
authors = ["DodoRare Team <support@dodorare.com>"]
description = "Cross-Platform Rust Toolkit for Games 🏹"
Expand Down
2 changes: 2 additions & 0 deletions platform/android/java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ dependencies {

if (rootProject.findProject(":lib")) {
implementation project(":lib")
} else 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.
Expand Down
2 changes: 1 addition & 1 deletion platform/android/java/app/config.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext.versions = [
crossbowLibrary : "0.1.5",
crossbowLibrary : "0.1.6",
androidGradlePlugin: "7.0.0",
compileSdk : 31,
minSdk : 19,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ object CrossbowLib {
/**
* Invoked on the main thread to initialize Godot native layer.
*/
@JvmStatic
external fun initialize(
activity: Activity?,
instance: Crossbow?,
Expand All @@ -25,11 +26,13 @@ object CrossbowLib {
// * Invoked on the main thread to clean up Godot native layer.
// * @see androidx.fragment.app.Fragment.onDestroy
// */
// @JvmStatic
// external fun ondestroy()

// /**
// * Forward [Activity.onBackPressed] event from the main thread to the GL thread.
// */
// @JvmStatic
// external fun back()

/**
Expand All @@ -38,5 +41,6 @@ object CrossbowLib {
* @param permission Request permission
* @param result True if the permission was granted, false otherwise
*/
@JvmStatic
external fun requestPermissionResult(permission: String?, result: Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,16 @@ abstract class CrossbowPlugin(
* Used to setup a [CrossbowPlugin] instance.
* @param p_name Name of the instance.
*/
private external fun nativeRegisterSingleton(p_name: String, `object`: Any)
@JvmStatic
private external fun nativeRegisterSingleton(p_name: String, p_obj: Any)

/**
* Used to complete registration of the [CrossbowPlugin] instance's methods.
* @param p_sname Name of the instance
* @param p_name Name of the method to register
* @param p_sig Signature of the registered method
*/
@JvmStatic
private external fun nativeRegisterMethod(p_sname: String, p_name: String, p_sig: String)

/**
Expand All @@ -335,6 +337,7 @@ abstract class CrossbowPlugin(
* @param signalName Name of the signal to register
* @param signalParamTypes Signal parameters types
*/
@JvmStatic
private external fun nativeRegisterSignal(
pluginName: String,
signalName: String,
Expand All @@ -347,6 +350,7 @@ abstract class CrossbowPlugin(
* @param signalName Name of the signal to emit
* @param signalParams Signal parameters
*/
@JvmStatic
private external fun nativeEmitSignal(
pluginName: String,
signalName: String,
Expand Down
Loading