Skip to content

Commit 91331b6

Browse files
committed
Reflect changes made to gdnative-sys NDK version handling (godot-rust/gdnative#754)
1 parent 1d6efbe commit 91331b6

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/exporting/android.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,56 +51,67 @@ apt-get install g++-multilib gcc-multilib libc6-dev-i386 -y
5151

5252
## Setting up Cargo
5353

54-
To make Cargo aware of the proper platform-specific linkers that it needs to use for Android targets, we need to put the paths to the binaries in the Cargo configuration file, which can be found (or created) at `$HOME/.cargo/config` on UNIX-like systems, or `%USERPROFILE%\.cargo\config` on Windows), using [`[target]` tables](https://doc.rust-lang.org/cargo/reference/config.html#target):
54+
To make Cargo aware of the proper platform-specific linkers that it needs to use for Android targets, we need to put the paths to the binaries in the Cargo configuration file, which can be found (or created) at `$HOME/.cargo/config` on UNIX-like systems, or `%USERPROFILE%\.cargo\config` on Windows), using [`[target]` tables](https://doc.rust-lang.org/cargo/reference/config.html#targettriplelinker):
5555

5656
```toml
5757
[target.armv7-linux-androideabi]
58-
linker = "/usr/local/lib/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"
58+
linker = "/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"
5959
```
6060

61-
... where the value of `linker` is an **absolute path** to the Android SDK linker for the target triple. Assuming `$ANDROID_SDK_ROOT` is the Android SDK path, these binaries can be found at:
61+
... where the value of `linker` is an **absolute path** to the Android SDK linker for the target triple. Assuming `$ANDROID_SDK_ROOT` is the Android SDK path and `$ANDROID_NDK_VERSION` is the installed NDK instance version, these binaries can be found at:
6262

63-
- Windows: `$ANDROID_SDK_ROOT\ndk\<NDK-VERSION>\toolchains\llvm\prebuilt\windows-x86_64\bin\`, where `<NDK-VERSION>` is the installed NDK instance version
64-
- UNIX-like systems: `$ANDROID_SDK_ROOT/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/`
63+
- Windows: `$ANDROID_SDK_ROOT\ndk\$ANDROID_NDK_VERSION\toolchains\llvm\prebuilt\windows-x86_64\bin\`
64+
- UNIX-like systems: `$ANDROID_SDK_ROOT/ndk/$ANDROID_NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/bin/`
65+
66+
> Alternatively, the NDK can be located under `$ANDROID_SDK_ROOT/ndk-bundle` instead of `$ANDROID_SDK_ROOT/ndk/$ANDROID_NDK_VERSION`, but this folder is deprecated because it doesn't allow for parallel versions installation.
6567
6668
Repeat for all targets installed in the previous step, until we get something that looks like:
6769

6870
```toml
6971
# Example configuration on an UNIX-like system. `29` is the Android API version.
7072

7173
[target.armv7-linux-androideabi]
72-
linker = "/usr/local/lib/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"
74+
linker = "/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"
7375

7476
[target.aarch64-linux-android]
75-
linker = "/usr/local/lib/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang"
77+
linker = "/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang"
7678

7779
[target.i686-linux-android]
78-
linker = "/usr/local/lib/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android29-clang"
80+
linker = "/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android29-clang"
7981

8082
[target.x86_64-linux-android]
81-
linker = "/usr/local/lib/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android29-clang"
83+
linker = "/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android29-clang"
84+
```
85+
86+
Alternatively, you can use cargo config environment variables:
87+
88+
```bash
89+
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"
90+
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang"
91+
export CARGO_TARGET_I686_LINUX_ANDROID_LINKER="/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android29-clang"
92+
export CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android29-clang"
8293
```
8394

8495

8596
## Setting up environment variables for `gdnative-sys`
8697

8798
The `gdnative-sys` crate can infer include paths for Android targets, but it requires the following environment variables:
8899

89-
- `$JAVA_HOME`, which should point to the installed JDK instance.
90-
- `$ANDROID_SDK_ROOT`, which should point to the Android SDK root (which contains the `ndk-bundle` directory).
100+
- `$ANDROID_SDK_ROOT`, which should point to the Android SDK root (which contains the `ndk` or `ndk-bundle` directory).
101+
- `$ANDROID_NDK_VERSION`, which should contain the selected ndk version (if omitted, the latest version available is used and a warning is issued).
91102

92103
Depending on your installation, these environment variables might have already been set. Otherwise, the variables may be set in bash:
93104

94105
```bash
95-
export JAVA_HOME=/path/to/jdk
96106
export ANDROID_SDK_ROOT=/path/to/android/sdk
107+
export ANDROID_NDK_VERSION=21.4.7075529
97108
```
98109

99110
... or in PowerShell on Windows:
100111

101112
```powershell
102-
$env:JAVA_HOME = "C:\path\to\jdk"
103113
$env:ANDROID_SDK_ROOT = "C:\path\to\android\sdk"
114+
$env:ANDROID_NDK_VERSION = "21.4.7075529"
104115
```
105116

106117

0 commit comments

Comments
 (0)