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
{{ message }}
This repository was archived by the owner on Jul 3, 2020. It is now read-only.
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
@@ -31,13 +31,15 @@ After the build is finished, you should get an Android package in `target/androi
31
31
Before you can compile for Android, you need to setup your environment. This needs to be done only once per system.
32
32
33
33
- Install [`rustup`](https://rustup.rs/).
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/).
34
+
- Run `rustup target add <target>` for all supported targets to which you want to compile. Building will attempt to build for all supported targets unless the build targets are adjusted via `Cargo.toml`.
35
+
-`rustup target add armv7-linux-androideabi`
36
+
-`rustup target add aarch64-linux-android`
37
+
-`rustup target add i686-linux-android`
38
+
-`rustup target add x86_64-linux-android`
39
+
- Install the Java JRE or JDK (on Ubuntu, `sudo apt-get install openjdk-8-jdk`).
38
40
- Download and unzip [the Android NDK](https://developer.android.com/ndk).
39
41
- 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"`.
42
+
- Install some components in the SDK: `./android-sdk/tools/bin/sdkmanager "platform-tools" "platforms;android-29" "build-tools;29.0.0"`.
41
43
- Install `cargo-apk` with `cargo install cargo-apk`.
42
44
- Set the environment variables `NDK_HOME` to the path of the NDK and `ANDROID_HOME` to the path of the SDK.
43
45
@@ -46,7 +48,15 @@ Before you can compile for Android, you need to setup your environment. This nee
46
48
In the project root for your Android crate, run `cargo apk build`. You can use the same options as
47
49
with the regular `cargo build`.
48
50
49
-
This will build an Android package in `target/android-artifacts/app/build/outputs/apk`.
51
+
This will build an Android package in `target/android-artifacts/<debug|release>/apk`.
52
+
53
+
### Compiling Multiple Binaries
54
+
55
+
`cargo apk build` supports building multiple binaries and examples using the same arguments as `cargo build`. It will produce an APK for each binary.
56
+
57
+
Android packages for bin targets are placed in `target/android-artifacts/<debug|release>/apk`.
58
+
59
+
Android packages for example targets are placed in `target/android-artifacts/<debug|release>/apk/examples`.
50
60
51
61
### Testing on an Android emulator
52
62
@@ -72,62 +82,75 @@ the stdlib.
72
82
73
83
## The build process
74
84
75
-
The build process works by invoking `cargo rustc` and:
85
+
The build process works by running rustc and:
76
86
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.
87
+
- Always compiles your crate as a static library.
88
+
-Uses `ndk-build`provided by the NDK to to build a shared library.
89
+
-Links to the `android_native_app_glue` library provided by the Android NDK.
90
+
- Injects some glue libraries in Rust, which ties the link between `android_native_app_glue` and the `main` function of your crate.
81
91
82
92
This first step outputs a shared library, and is run once per target architecture.
83
93
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`.
94
+
The command then builds the APK using the shared library, generated manifest, and tools from the Android SDK.
95
+
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
96
87
97
# Supported `[package.metadata.android]` entries
88
98
89
99
```toml
90
-
[package.metadata.android]
100
+
# The target Android API level.
101
+
# "android_version" is the compile SDK version. It defaults to 29.
102
+
# (target_sdk_version defaults to the value of "android_version")
103
+
# (min_sdk_version defaults to 18) It defaults to 18 because this is the minimum supported by rustc.
104
+
android_version = 29
105
+
target_sdk_version = 29
106
+
min_sdk_version = 26
107
+
108
+
# Specifies the array of targets to build for.
109
+
# Defaults to "armv7-linux-androideabi", "aarch64-linux-android", "i686-linux-android".
0 commit comments