diff --git a/android-build-tools/src/apk.rs b/android-build-tools/src/apk.rs index 65b01562..940c5432 100644 --- a/android-build-tools/src/apk.rs +++ b/android-build-tools/src/apk.rs @@ -37,6 +37,7 @@ impl ApkConfig { version_name: config.version_name, version_code: config.version_code, target_name: config.target_name, + debuggable: config.debuggable, target_sdk_version, min_sdk_version: metadata.min_sdk_version.unwrap_or(23), opengles_version: metadata.opengles_version.unwrap_or((3, 1)), diff --git a/android-build-tools/src/config.rs b/android-build-tools/src/config.rs index 17e576d3..2745228a 100644 --- a/android-build-tools/src/config.rs +++ b/android-build-tools/src/config.rs @@ -12,6 +12,7 @@ pub struct Config { pub version_name: String, pub version_code: u32, pub target_name: String, + pub debuggable: bool, pub assets: Option, pub res: Option, } diff --git a/android-build-tools/src/manifest.rs b/android-build-tools/src/manifest.rs index b2c16655..4f60f2bb 100644 --- a/android-build-tools/src/manifest.rs +++ b/android-build-tools/src/manifest.rs @@ -17,6 +17,7 @@ pub struct Manifest { pub permissions: Vec, pub icon: Option, pub fullscreen: bool, + pub debuggable: bool, } impl Manifest { @@ -54,6 +55,7 @@ impl Manifest { ApkBuilder<'a> { version_name: self.manifest.version.clone(), version_code: 1, target_name: artifact.name().to_string(), + debuggable: *self.cmd.profile() == Profile::Dev, assets: self.manifest.assets.clone(), res: self.manifest.res.clone(), }; @@ -97,6 +98,20 @@ impl<'a> ApkBuilder<'a> { apk.start()?; Ok(()) } + + pub fn gdb(&self, artifact: &Artifact) -> Result<(), NdkError> { + self.run(artifact)?; + let abi = self.ndk.detect_abi()?; + let target_dir = self.build_dir.join(artifact); + let jni_dir = target_dir.join("jni"); + std::fs::create_dir_all(&jni_dir)?; + std::fs::write( + jni_dir.join("Android.mk"), + format!("APP_ABI=\"{}\"\nTARGET_OUT=\"\"\n", abi.android_abi()), + )?; + Command::new("ndk-gdb").current_dir(target_dir).status()?; + Ok(()) + } } fn cargo_env_target_cfg(tool: &str, target: &str) -> String { diff --git a/cargo-ndk/src/main.rs b/cargo-ndk/src/main.rs index d138f03e..52a37150 100644 --- a/cargo-ndk/src/main.rs +++ b/cargo-ndk/src/main.rs @@ -1,11 +1,11 @@ use cargo_ndk::ApkBuilder; -use cargo_subcommand::Subcommand; +use cargo_subcommand::{Error, Subcommand}; use std::process::Command; fn main() -> Result<(), Box> { env_logger::init(); - let cmd = Subcommand::new("ndk")?; + let cmd = Subcommand::new("ndk", |_, _| Ok(false))?; let builder = ApkBuilder::from_subcommand(&cmd)?; match cmd.cmd() { @@ -17,6 +17,15 @@ fn main() -> Result<(), Box> { "run" => { if cmd.artifacts().len() == 1 { builder.run(&cmd.artifacts()[0])?; + } else { + return Err(Error::InvalidArgs.into()); + } + } + "gdb" => { + if cmd.artifacts().len() == 1 { + builder.gdb(&cmd.artifacts()[0])?; + } else { + return Err(Error::InvalidArgs.into()); } } _ => {