You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support for latest Android NDK and SDK,
ABI rework, additional manifest configuration, and multiple cargo targets.
Updated dependencies.
Formatted using rustfmt.
Removed gradle dependency.
Do not mount a volume on `/root` or you will erase the local installation of Cargo.
24
24
25
-
After the build is finished, you should get an Android package in `target/android-artifacts/app/build/outputs/apk`.
25
+
After the build is finished, you should get an Android package in `target/android-artifacts/debug/apk`.
26
26
27
27
## Manual usage
28
28
@@ -32,12 +32,10 @@ Before you can compile for Android, you need to setup your environment. This nee
32
32
33
33
- Install [`rustup`](https://rustup.rs/).
34
34
- Run `rustup target add arm-linux-androideabi`, or any other target that you want to compile to.
35
-
- Install the Java JDK (on Ubuntu, `sudo apt-get install openjdk-8-jdk`).
36
-
- Install CMake (on Ubuntu, `sudo apt-get install cmake`).
37
-
-[Install Gradle](https://gradle.org/install/).
35
+
- Install the Java JRE or JDK (on Ubuntu, `sudo apt-get install openjdk-8-jdk`).
38
36
- Download and unzip [the Android NDK](https://developer.android.com/ndk).
39
37
- Download and unzip [the Android SDK](https://developer.android.com/studio).
40
-
- Install some components in the SDK: `./android-sdk/tools/bin/sdkmanager "platform-tools" "platforms;android-18" "build-tools;26.0.1"`.
38
+
- Install some components in the SDK: `./android-sdk/tools/bin/sdkmanager "platform-tools" "platforms;android-29" "build-tools;29.0.0"`.
41
39
- Install `cargo-apk` with `cargo install cargo-apk`.
42
40
- Set the environment variables `NDK_HOME` to the path of the NDK and `ANDROID_HOME` to the path of the SDK.
43
41
@@ -46,7 +44,7 @@ Before you can compile for Android, you need to setup your environment. This nee
46
44
In the project root for your Android crate, run `cargo apk build`. You can use the same options as
47
45
with the regular `cargo build`.
48
46
49
-
This will build an Android package in `target/android-artifacts/app/build/outputs/apk`.
47
+
This will build an Android package in `target/android-artifacts/<debug|release>/apk`.
50
48
51
49
### Testing on an Android emulator
52
50
@@ -72,62 +70,63 @@ the stdlib.
72
70
73
71
## The build process
74
72
75
-
The build process works by invoking `cargo rustc` and:
73
+
The build process works by running rustc and:
76
74
77
-
- Always compiles your crate as a shared library.
78
-
-Injects the `android_native_app_glue` file provided by the Android NDK.
79
-
-Injects some glue libraries in Rust, which ties the link between `android_native_app_glue` and
80
-
the `main` function of your crate.
75
+
- Always compiles your crate as a static library.
76
+
-Uses `ndk-build`provided by the NDK to to build a shared library.
77
+
-Links to the `android_native_app_glue` library provided by the Android NDK.
78
+
- Injects some glue libraries in Rust, which ties the link between `android_native_app_glue` and the `main` function of your crate.
81
79
82
80
This first step outputs a shared library, and is run once per target architecture.
83
81
84
-
The command then sets up an Android build environment, which includes some Java code, in
85
-
`target/android-artifacts` and puts the shared libraries in it. Then it runs `gradle`.
82
+
The command then builds the APK using the shared library, generated manifest, and tools from the Android SDK.
83
+
It signs the APK with the default debug keystore used by Android development tools. If the keystore doesn't exist, it creates it using the keytool from the JRE or JDK.
86
84
87
85
# Supported `[package.metadata.android]` entries
88
86
89
87
```toml
90
-
[package.metadata.android]
88
+
# The target Android API level.
89
+
# "android_version" is the compile SDK version. It defaults to 29.
90
+
# (target_sdk_version defaults to the value of "android_version")
91
+
# (min_sdk_version defaults to 18) It defaults to 18 because this is the minimum supported by rustc.
92
+
android_version = 29
93
+
target_sdk_version = 29
94
+
min_sdk_version = 26
95
+
96
+
# Specifies the array of targets to build for.
97
+
# Defaults to "armv7-linux-androideabi", "aarch64-linux-android", "i686-linux-android".
0 commit comments