diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/cargo-apk2.iml b/.idea/cargo-apk2.iml
new file mode 100644
index 0000000..1f98b0e
--- /dev/null
+++ b/.idea/cargo-apk2.iml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..2905d96
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Cargo.toml b/Cargo.toml
index e88b581..26d22be 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,12 @@
+[workspace.dependencies]
+dunce = "1.0.5"
+serde = "1.0.214"
+thiserror = "2.0.3"
+
[workspace]
members = [
- "ndk-build",
+ "ndk-build2",
"ndk-examples",
- "cargo-apk",
+ "cargo-apk2",
]
+resolver = "2"
diff --git a/cargo-apk/Cargo.toml b/cargo-apk/Cargo.toml
deleted file mode 100644
index e242c19..0000000
--- a/cargo-apk/Cargo.toml
+++ /dev/null
@@ -1,24 +0,0 @@
-[package]
-name = "cargo-apk"
-version = "0.10.0"
-authors = ["The Rust Windowing contributors"]
-edition = "2018"
-description = "Helps cargo build APKs"
-license = "MIT OR Apache-2.0"
-keywords = ["android", "ndk", "apk"]
-documentation = "https://docs.rs/cargo-apk"
-homepage = "https://github.com/rust-mobile/cargo-apk"
-repository = "https://github.com/rust-mobile/cargo-apk"
-rust-version = "1.70"
-
-[dependencies]
-anyhow = "1.0.57"
-cargo-subcommand = "0.12"
-clap = { version = "4", features = ["derive"] }
-dunce = "1"
-env_logger = "0.10"
-log = "0.4"
-ndk-build = { path = "../ndk-build", version = "0.10.0" }
-serde = "1"
-thiserror = "1"
-toml = "0.5"
diff --git a/cargo-apk/CHANGELOG.md b/cargo-apk2/CHANGELOG.md
similarity index 94%
rename from cargo-apk/CHANGELOG.md
rename to cargo-apk2/CHANGELOG.md
index 5a2dc56..6b2eee3 100644
--- a/cargo-apk/CHANGELOG.md
+++ b/cargo-apk2/CHANGELOG.md
@@ -69,7 +69,7 @@
# 0.8.1 (2021-08-06)
-- Updated to use [ndk-build 0.4.2](../ndk-build/CHANGELOG.md#042-2021-08-06)
+- Updated to use [ndk-build 0.4.2](../ndk-build2/CHANGELOG.md#042-2021-08-06)
# 0.8.0 (2021-07-06)
@@ -89,11 +89,11 @@
# 0.5.6 (2020-11-25)
- Use `dunce::simplified` when extracting the manifest's assets and resource folder
-- Updated to use [ndk-build 0.1.4](../ndk-build/CHANGELOG.md#014-2020-11-25)
+- Updated to use [ndk-build 0.1.4](../ndk-build2/CHANGELOG.md#014-2020-11-25)
# 0.5.5 (2020-11-21)
-- Updated to use [ndk-build 0.1.3](../ndk-build/CHANGELOG.md#013-2020-11-21)
+- Updated to use [ndk-build 0.1.3](../ndk-build2/CHANGELOG.md#013-2020-11-21)
# 0.5.4 (2020-11-01)
@@ -106,14 +106,14 @@
# 0.5.2 (2020-09-15)
-- Updated to use [ndk-build 0.1.2](../ndk-build/CHANGELOG.md#012-2020-09-15)
+- Updated to use [ndk-build 0.1.2](../ndk-build2/CHANGELOG.md#012-2020-09-15)
# 0.5.1 (2020-07-15)
-- Updated to use [ndk-build 0.1.1](../ndk-build/CHANGELOG.md#011-2020-07-15)
+- Updated to use [ndk-build 0.1.1](../ndk-build2/CHANGELOG.md#011-2020-07-15)
# 0.5.0 (2020-04-22)
-- Updated to use [ndk-build 0.1.0](../ndk-build/CHANGELOG.md#010-2020-04-22)
+- Updated to use [ndk-build 0.1.0](../ndk-build2/CHANGELOG.md#010-2020-04-22)
- First release in almost 3 years! 🎉
- **Breaking:** A ton of things changed!
diff --git a/cargo-apk2/Cargo.toml b/cargo-apk2/Cargo.toml
new file mode 100644
index 0000000..7abb647
--- /dev/null
+++ b/cargo-apk2/Cargo.toml
@@ -0,0 +1,31 @@
+[package]
+name = "cargo-apk2"
+version = "0.10.0"
+authors = [
+ "SmileSky ",
+ "The Rust Windowing contributors"
+]
+edition = "2021"
+description = "Rust轻松构建安卓应用的Cargo扩展"
+license = "MIT OR Apache-2.0"
+keywords = ["android", "ndk", "apk"]
+repository = "https://github.com/mzdk100/cargo-apk2.git"
+rust-version = "1.82.0"
+
+[dependencies]
+anyhow = "1.0.93"
+cargo-subcommand = "0.12.0"
+dunce.workspace = true
+env_logger = "0.11.5"
+log = "0.4.22"
+serde.workspace = true
+thiserror.workspace = true
+toml = "0.8.19"
+
+[dependencies.ndk-build2]
+path = "../ndk-build2"
+version = "0.10.0"
+
+[dependencies.clap]
+version = "4.5.20"
+features = ["derive"]
diff --git a/cargo-apk/README.md b/cargo-apk2/README.md
similarity index 99%
rename from cargo-apk/README.md
rename to cargo-apk2/README.md
index 2dae917..b0fa9c6 100644
--- a/cargo-apk/README.md
+++ b/cargo-apk2/README.md
@@ -1,4 +1,4 @@
-# cargo apk
+# cargo apk2
[![Actions Status](https://github.com/rust-mobile/cargo-apk/actions/workflows/rust.yml/badge.svg)](https://github.com/rust-mobile/cargo-apk/actions)
[![Latest version](https://img.shields.io/crates/v/cargo-apk.svg?logo=rust)](https://crates.io/crates/cargo-apk)
@@ -102,7 +102,7 @@ shared_user_id = "my.shared.user.id"
# as ``, it is the uppercased profile name with `-` replaced with `_`.
#
# If present they take precedence over the signing information in the manifest.
-[package.metadata.android.signing.]
+[package.metadata.android.signing._profile_]
path = "relative/or/absolute/path/to/my.keystore"
keystore_password = "android"
diff --git a/cargo-apk/src/apk.rs b/cargo-apk2/src/apk.rs
similarity index 96%
rename from cargo-apk/src/apk.rs
rename to cargo-apk2/src/apk.rs
index a4be306..94d13ff 100644
--- a/cargo-apk/src/apk.rs
+++ b/cargo-apk2/src/apk.rs
@@ -1,13 +1,17 @@
-use crate::error::Error;
-use crate::manifest::{Inheritable, Manifest, Root};
+use crate::{
+ error::Error,
+ manifest::{Inheritable, Manifest, Root},
+};
use cargo_subcommand::{Artifact, ArtifactType, CrateType, Profile, Subcommand};
-use ndk_build::apk::{Apk, ApkConfig};
-use ndk_build::cargo::{cargo_ndk, VersionCode};
-use ndk_build::dylibs::get_libs_search_paths;
-use ndk_build::error::NdkError;
-use ndk_build::manifest::{IntentFilter, MetaData};
-use ndk_build::ndk::{Key, Ndk};
-use ndk_build::target::Target;
+use ndk_build2::{
+ apk::{Apk, ApkConfig},
+ cargo::{cargo_ndk, VersionCode},
+ dylibs::get_libs_search_paths,
+ error::NdkError,
+ manifest::{IntentFilter, MetaData},
+ ndk::{Key, Ndk},
+ target::Target,
+};
use std::path::PathBuf;
pub struct ApkBuilder<'a> {
@@ -278,7 +282,7 @@ impl<'a> ApkBuilder<'a> {
);
Key {
path,
- password: ndk_build::ndk::DEFAULT_DEV_KEYSTORE_PASSWORD.to_owned(),
+ password: ndk_build2::ndk::DEFAULT_DEV_KEYSTORE_PASSWORD.to_owned(),
}
}
(Some(path), None) => {
diff --git a/cargo-apk/src/error.rs b/cargo-apk2/src/error.rs
similarity index 96%
rename from cargo-apk/src/error.rs
rename to cargo-apk2/src/error.rs
index 9522865..d0ccea0 100644
--- a/cargo-apk/src/error.rs
+++ b/cargo-apk2/src/error.rs
@@ -1,5 +1,5 @@
use cargo_subcommand::Error as SubcommandError;
-use ndk_build::error::NdkError;
+use ndk_build2::error::NdkError;
use std::io::Error as IoError;
use thiserror::Error;
use toml::de::Error as TomlError;
diff --git a/cargo-apk/src/lib.rs b/cargo-apk2/src/lib.rs
similarity index 100%
rename from cargo-apk/src/lib.rs
rename to cargo-apk2/src/lib.rs
diff --git a/cargo-apk/src/main.rs b/cargo-apk2/src/main.rs
similarity index 90%
rename from cargo-apk/src/main.rs
rename to cargo-apk2/src/main.rs
index 95f8185..d858c09 100644
--- a/cargo-apk/src/main.rs
+++ b/cargo-apk2/src/main.rs
@@ -1,22 +1,14 @@
use std::collections::HashMap;
-use cargo_apk::{ApkBuilder, Error};
+use cargo_apk2::{ApkBuilder, Error};
use cargo_subcommand::Subcommand;
use clap::{CommandFactory, FromArgMatches, Parser};
#[derive(Parser)]
-struct Cmd {
+#[command(bin_name = "cargo")]
+enum Cmd {
#[clap(subcommand)]
- apk: ApkCmd,
-}
-
-#[derive(clap::Subcommand)]
-enum ApkCmd {
- /// Helps cargo build apks for Android
- Apk {
- #[clap(subcommand)]
- cmd: ApkSubCmd,
- },
+ Apk2(ApkSubCmd),
}
#[derive(Clone, Debug, Eq, PartialEq, Parser)]
@@ -30,6 +22,7 @@ struct Args {
}
#[derive(clap::Subcommand)]
+#[command(about = "Building Android Applications (APK) with Rust", version)]
enum ApkSubCmd {
/// Analyze the current package and report errors, but don't build object files nor an apk
#[clap(visible_alias = "c")]
@@ -51,8 +44,7 @@ enum ApkSubCmd {
/// Arguments passed to cargo. Some arguments will be used to configure
/// the environment similar to other `cargo apk` commands
- // TODO: This enum variant should parse into `Args` as soon as `clap` supports
- // parsing only unrecognized args into a side-buffer.
+ // TODO: 一旦“clap”支持将无法识别的参数解析到侧缓冲区中,这个枚举变量就应该解析为“Args”。
#[clap(trailing_var_arg = true, allow_hyphen_values = true)]
cargo_args: Vec,
},
@@ -70,17 +62,13 @@ enum ApkSubCmd {
#[clap(flatten)]
args: Args,
},
- /// Print the version of cargo-apk
- Version,
}
fn split_apk_and_cargo_args(input: Vec) -> (Args, Vec) {
- // Clap doesn't support parsing unknown args properly:
+ // Clap 不支持正确解析未知参数:
// https://github.com/clap-rs/clap/issues/1404
// https://github.com/clap-rs/clap/issues/4498
- // Introspect the `Args` struct and extract every known arg, and whether it takes a value. Use
- // this information to separate out known args from unknown args, and re-parse all the known
- // args into an `Args` struct.
+ // 检查 `Args` 结构并提取每个已知参数,以及它是否接受值。使用此信息将已知参数与未知参数分开,并将所有已知参数重新解析为 `Args` 结构。
let known_args_taking_value = Args::command()
.get_arguments()
@@ -140,9 +128,7 @@ fn iterator_single_item(mut iter: impl Iterator- ) -> Option {
fn main() -> anyhow::Result<()> {
env_logger::init();
- let Cmd {
- apk: ApkCmd::Apk { cmd },
- } = Cmd::parse();
+ let Cmd::Apk2(cmd) = Parser::parse();
match cmd {
ApkSubCmd::Check { args } => {
let cmd = Subcommand::new(args.subcommand_args)?;
@@ -178,9 +164,6 @@ fn main() -> anyhow::Result<()> {
let artifact = iterator_single_item(cmd.artifacts()).ok_or(Error::invalid_args())?;
builder.gdb(artifact)?;
}
- ApkSubCmd::Version => {
- println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
- }
}
Ok(())
}
diff --git a/cargo-apk/src/manifest.rs b/cargo-apk2/src/manifest.rs
similarity index 97%
rename from cargo-apk/src/manifest.rs
rename to cargo-apk2/src/manifest.rs
index de4460a..c76cd6e 100644
--- a/cargo-apk/src/manifest.rs
+++ b/cargo-apk2/src/manifest.rs
@@ -1,7 +1,5 @@
use crate::error::Error;
-use ndk_build::apk::StripConfig;
-use ndk_build::manifest::AndroidManifest;
-use ndk_build::target::Target;
+use ndk_build2::{apk::StripConfig, manifest::AndroidManifest, target::Target};
use serde::Deserialize;
use std::{
collections::HashMap,
diff --git a/ndk-build/Cargo.toml b/ndk-build/Cargo.toml
deleted file mode 100644
index c9e18ad..0000000
--- a/ndk-build/Cargo.toml
+++ /dev/null
@@ -1,20 +0,0 @@
-[package]
-name = "ndk-build"
-version = "0.10.0"
-authors = ["The Rust Windowing contributors"]
-edition = "2018"
-description = "Utilities for building Android binaries"
-license = "MIT OR Apache-2.0"
-keywords = ["android", "ndk", "apk"]
-documentation = "https://docs.rs/ndk-build"
-homepage = "https://github.com/rust-mobile/cargo-apk"
-repository = "https://github.com/rust-mobile/cargo-apk"
-rust-version = "1.60"
-
-[dependencies]
-dirs = "4"
-dunce = "1"
-quick-xml = { version = "0.26", features = ["serialize"] }
-serde = { version = "1", features = ["derive"] }
-thiserror = "1"
-which = "4"
diff --git a/ndk-build/CHANGELOG.md b/ndk-build2/CHANGELOG.md
similarity index 100%
rename from ndk-build/CHANGELOG.md
rename to ndk-build2/CHANGELOG.md
diff --git a/ndk-build2/Cargo.toml b/ndk-build2/Cargo.toml
new file mode 100644
index 0000000..065c80b
--- /dev/null
+++ b/ndk-build2/Cargo.toml
@@ -0,0 +1,28 @@
+[package]
+name = "ndk-build2"
+version = "0.10.0"
+authors = [
+ "SmileSky ",
+ "The Rust Windowing contributors",
+]
+edition = "2021"
+description = "用于构建 Android 二进制文件的实用程序"
+license = "MIT OR Apache-2.0"
+keywords = ["android", "ndk", "apk"]
+repository = "https://github.com/mzdk100/cargo-apk2.git"
+rust-version = "1.82.0"
+
+[dependencies]
+android-build = "0.1.0"
+dirs = "5.0.1"
+dunce.workspace = true
+thiserror.workspace = true
+which = "7.0.0"
+
+[dependencies.serde]
+workspace = true
+features = ["derive"]
+
+[dependencies.quick-xml]
+version = "0.37.0"
+features = ["serialize"]
diff --git a/ndk-build/README.md b/ndk-build2/README.md
similarity index 100%
rename from ndk-build/README.md
rename to ndk-build2/README.md
diff --git a/ndk-build/src/apk.rs b/ndk-build2/src/apk.rs
similarity index 95%
rename from ndk-build/src/apk.rs
rename to ndk-build2/src/apk.rs
index 66d2573..fcebd43 100644
--- a/ndk-build/src/apk.rs
+++ b/ndk-build2/src/apk.rs
@@ -1,13 +1,16 @@
-use crate::error::NdkError;
-use crate::manifest::AndroidManifest;
-use crate::ndk::{Key, Ndk};
-use crate::target::Target;
-use std::collections::HashMap;
-use std::collections::HashSet;
-use std::ffi::OsStr;
-use std::fs;
-use std::path::{Path, PathBuf};
-use std::process::Command;
+use crate::{
+ error::NdkError,
+ manifest::AndroidManifest,
+ ndk::{Key, Ndk},
+ target::Target,
+};
+use std::{
+ collections::{HashMap, HashSet},
+ ffi::OsStr,
+ fs::{copy, create_dir_all, read_dir},
+ path::{Path, PathBuf},
+ process::Command,
+};
/// The options for how to treat debug symbols that are present in any `.so`
/// files that are added to the APK.
@@ -66,7 +69,7 @@ impl ApkConfig {
}
pub fn create_apk(&self) -> Result {
- std::fs::create_dir_all(&self.build_dir)?;
+ create_dir_all(&self.build_dir)?;
self.manifest.write_to(&self.build_dir)?;
let target_sdk_version = self
@@ -124,11 +127,11 @@ impl<'a> UnalignedApk<'a> {
let abi = target.android_abi();
let lib_path = Path::new("lib").join(abi).join(path.file_name().unwrap());
let out = self.config.build_dir.join(&lib_path);
- std::fs::create_dir_all(out.parent().unwrap())?;
+ create_dir_all(out.parent().unwrap())?;
match self.config.strip {
StripConfig::Default => {
- std::fs::copy(path, out)?;
+ copy(path, out)?;
}
StripConfig::Strip | StripConfig::Split => {
let obj_copy = self.config.ndk.toolchain_bin("objcopy", target)?;
@@ -186,7 +189,7 @@ impl<'a> UnalignedApk<'a> {
search_paths: &[&Path],
) -> Result<(), NdkError> {
let abi_dir = path.join(target.android_abi());
- for entry in fs::read_dir(&abi_dir).map_err(|e| NdkError::IoPathError(abi_dir, e))? {
+ for entry in read_dir(&abi_dir).map_err(|e| NdkError::IoPathError(abi_dir, e))? {
let entry = entry?;
let path = entry.path();
if path.extension() == Some(OsStr::new("so")) {
diff --git a/ndk-build/src/cargo.rs b/ndk-build2/src/cargo.rs
similarity index 100%
rename from ndk-build/src/cargo.rs
rename to ndk-build2/src/cargo.rs
diff --git a/ndk-build/src/dylibs.rs b/ndk-build2/src/dylibs.rs
similarity index 94%
rename from ndk-build/src/dylibs.rs
rename to ndk-build2/src/dylibs.rs
index 1434760..04862d8 100644
--- a/ndk-build/src/dylibs.rs
+++ b/ndk-build2/src/dylibs.rs
@@ -30,7 +30,7 @@ pub fn get_libs_search_paths(
_ => unreachable!(),
};
match kind {
- // FIXME: which kinds of search path we interested in
+ // FIXME: 我们感兴趣的搜索路径类型
"dependency" | "native" | "all" => paths.push(path.into()),
_ => (),
};
diff --git a/ndk-build/src/error.rs b/ndk-build2/src/error.rs
similarity index 97%
rename from ndk-build/src/error.rs
rename to ndk-build2/src/error.rs
index 6f725d0..f69afc1 100644
--- a/ndk-build/src/error.rs
+++ b/ndk-build2/src/error.rs
@@ -47,7 +47,7 @@ pub enum NdkError {
#[error("Command `{}` had a non-zero exit code.", format!("{:?}", .0).replace('"', ""))]
CmdFailed(Command),
#[error(transparent)]
- Serialize(#[from] quick_xml::de::DeError),
+ Serialize(#[from] quick_xml::SeError),
#[error("String `{1}` is not a UID")]
NotAUid(#[source] ParseIntError, String),
#[error("Could not find `package:{package}` in output `{output}`")]
diff --git a/ndk-build/src/lib.rs b/ndk-build2/src/lib.rs
similarity index 100%
rename from ndk-build/src/lib.rs
rename to ndk-build2/src/lib.rs
diff --git a/ndk-build/src/manifest.rs b/ndk-build2/src/manifest.rs
similarity index 97%
rename from ndk-build/src/manifest.rs
rename to ndk-build2/src/manifest.rs
index 6e3696c..9ba28f9 100644
--- a/ndk-build/src/manifest.rs
+++ b/ndk-build2/src/manifest.rs
@@ -1,6 +1,6 @@
use crate::error::NdkError;
use serde::{Deserialize, Serialize, Serializer};
-use std::{fs::File, path::Path};
+use std::{fs::File, io::Write, path::Path};
/// Android [manifest element](https://developer.android.com/guide/topics/manifest/manifest-element), containing an [`Application`] element.
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -55,9 +55,10 @@ impl Default for AndroidManifest {
impl AndroidManifest {
pub fn write_to(&self, dir: &Path) -> Result<(), NdkError> {
- let file = File::create(dir.join("AndroidManifest.xml"))?;
- let w = std::io::BufWriter::new(file);
- quick_xml::se::to_writer(w, &self)?;
+ let mut buf = String::new();
+ quick_xml::se::to_writer(&mut buf, &self).map_err(|e| NdkError::Serialize(e))?;
+ let mut file = File::create(dir.join("AndroidManifest.xml"))?;
+ file.write_all(buf.as_bytes())?;
Ok(())
}
}
diff --git a/ndk-build/src/ndk.rs b/ndk-build2/src/ndk.rs
similarity index 93%
rename from ndk-build/src/ndk.rs
rename to ndk-build2/src/ndk.rs
index 744dac3..c861125 100644
--- a/ndk-build/src/ndk.rs
+++ b/ndk-build2/src/ndk.rs
@@ -1,8 +1,9 @@
-use crate::error::NdkError;
-use crate::target::Target;
-use std::collections::HashMap;
-use std::path::{Path, PathBuf};
-use std::process::Command;
+use crate::{error::NdkError, target::Target};
+use std::{
+ collections::HashMap,
+ path::{Path, PathBuf},
+ process::Command,
+};
/// The default password used when creating the default `debug.keystore` via
/// [`Ndk::debug_key`]
@@ -10,7 +11,6 @@ pub const DEFAULT_DEV_KEYSTORE_PASSWORD: &str = "android";
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Ndk {
- sdk_path: PathBuf,
user_home: PathBuf,
ndk_path: PathBuf,
build_tools_version: String,
@@ -20,23 +20,6 @@ pub struct Ndk {
impl Ndk {
pub fn from_env() -> Result {
- let sdk_path = {
- let sdk_path = std::env::var("ANDROID_SDK_ROOT").ok();
- if sdk_path.is_some() {
- eprintln!(
- "Warning: Environment variable ANDROID_SDK_ROOT is deprecated \
- (https://developer.android.com/studio/command-line/variables#envar). \
- It will be used until it is unset and replaced by ANDROID_HOME."
- );
- }
-
- PathBuf::from(
- sdk_path
- .or_else(|| std::env::var("ANDROID_HOME").ok())
- .ok_or(NdkError::SdkNotFound)?,
- )
- };
-
let user_home = {
let user_home = std::env::var("ANDROID_SDK_HOME")
.map(PathBuf::from)
@@ -59,6 +42,8 @@ impl Ndk {
.or_else(|| dirs::home_dir().map(|home| home.join(".android")))
.ok_or_else(|| NdkError::PathNotFound(PathBuf::from("$HOME")))?
};
+ let sdk_path =
+ android_build::android_sdk().map_or(Err(NdkError::SdkNotFound), |i| Ok(i))?;
let ndk_path = {
let ndk_path = std::env::var("ANDROID_NDK_ROOT")
@@ -141,7 +126,6 @@ impl Ndk {
}
Ok(Self {
- sdk_path,
user_home,
ndk_path,
build_tools_version,
@@ -150,10 +134,6 @@ impl Ndk {
})
}
- pub fn sdk(&self) -> &Path {
- &self.sdk_path
- }
-
pub fn ndk(&self) -> &Path {
&self.ndk_path
}
@@ -171,8 +151,11 @@ impl Ndk {
}
pub fn build_tool(&self, tool: &str) -> Result {
- let path = self
- .sdk_path
+ let Some(sdk_path) = android_build::android_sdk() else {
+ return Err(NdkError::SdkNotFound);
+ };
+
+ let path = sdk_path
.join("build-tools")
.join(&self.build_tools_version)
.join(tool);
@@ -183,7 +166,10 @@ impl Ndk {
}
pub fn platform_tool_path(&self, tool: &str) -> Result {
- let path = self.sdk_path.join("platform-tools").join(tool);
+ let Some(sdk_path) = android_build::android_sdk() else {
+ return Err(NdkError::SdkNotFound);
+ };
+ let path = sdk_path.join("platform-tools").join(tool);
if !path.exists() {
return Err(NdkError::CmdNotFound(tool.to_string()));
}
@@ -211,8 +197,10 @@ impl Ndk {
}
pub fn platform_dir(&self, platform: u32) -> Result {
- let dir = self
- .sdk_path
+ let Some(sdk_path) = android_build::android_sdk() else {
+ return Err(NdkError::SdkNotFound);
+ };
+ let dir = sdk_path
.join("platforms")
.join(format!("android-{}", platform));
if !dir.exists() {
diff --git a/ndk-build/src/readelf.rs b/ndk-build2/src/readelf.rs
similarity index 100%
rename from ndk-build/src/readelf.rs
rename to ndk-build2/src/readelf.rs
diff --git a/ndk-build/src/target.rs b/ndk-build2/src/target.rs
similarity index 100%
rename from ndk-build/src/target.rs
rename to ndk-build2/src/target.rs
diff --git a/ndk-examples/Cargo.toml b/ndk-examples/Cargo.toml
index ec422d8..d2ab15f 100644
--- a/ndk-examples/Cargo.toml
+++ b/ndk-examples/Cargo.toml
@@ -1,12 +1,15 @@
[package]
name = "ndk-examples"
version = "0.1.0"
-authors = ["David Craven "]
-edition = "2018"
+authors = [
+ "SmileSky ",
+ "David Craven "
+]
+edition = "2021"
publish = false
[target.'cfg(target_os = "android")'.dependencies]
-jni = "0.20"
+jni = "0.21.1"
libc = "0.2"
log = "0.4.14"
ndk = { version = "0.7", features = ["api-level-23"] }
@@ -27,5 +30,5 @@ name = "looper"
crate-type = ["cdylib"]
[package.metadata.android.sdk]
-min_sdk_version = 16
-target_sdk_version = 29
+min_sdk_version = 24
+target_sdk_version = 35