|
| 1 | +# Description |
| 2 | + |
| 3 | +This is a guide on how to build the rust SDK for AppFlowy on android. |
| 4 | +Compiling the sdk is easy it just needs a few tweaks. |
| 5 | +When compiling for android we need the following pre-requisites: |
| 6 | + |
| 7 | +- Android NDK Tools. (v24 has been tested). |
| 8 | +- Cargo NDK. (@latest version). |
| 9 | + |
| 10 | +**Getting the tools** |
| 11 | +- Install cargo-ndk ```bash cargo install cargo-ndk```. |
| 12 | +- [Download](https://developer.android.com/ndk/downloads/) Android NDK version 24. |
| 13 | +- When downloading Android NDK you can get the compressed version as a standalone from the site. |
| 14 | + Or you can download it through [Android Studio](https://developer.android.com/studio). |
| 15 | +- After downloading the two you need to set the environment variables. For Windows that's a seperate process. |
| 16 | + On MacOs and Linux the process is similar. |
| 17 | +- The variables needed are '$ANDROID_NDK_HOME', this will point to where the NDK is located. |
| 18 | +--- |
| 19 | + |
| 20 | +**Cargo Config File** |
| 21 | +This code needs to be written in ~/.cargo/config, this helps cargo know where to locate the android tools(linker and archiver). |
| 22 | +**NB** Keep in mind just replace 'user' with your own user name. Or just point it to the location of where you put the NDK. |
| 23 | + |
| 24 | +```toml |
| 25 | +[target.aarch64-linux-android] |
| 26 | +ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" |
| 27 | +linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang" |
| 28 | + |
| 29 | +[target.armv7-linux-androideabi] |
| 30 | +ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" |
| 31 | +linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang" |
| 32 | + |
| 33 | +[target.i686-linux-android] |
| 34 | +ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" |
| 35 | +linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android29-clang" |
| 36 | + |
| 37 | +[target.x86_64-linux-android] |
| 38 | +ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" |
| 39 | +linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android29-clang" |
| 40 | +``` |
| 41 | + |
| 42 | +**Clang Fix** |
| 43 | + In order to get clang to work properly with version 24 you need to create this file. |
| 44 | + libgcc.a, then add this one line. |
| 45 | + ``` |
| 46 | + INPUT(-lunwind) |
| 47 | + ``` |
| 48 | + |
| 49 | +**Folder path: 'Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux'.** |
| 50 | +After that you have to copy this file into three different folders namely aarch64, arm, i386 and x86_64. |
| 51 | +We have to do this so we Android NDK can find clang on our system, if we used NDK 22 we wouldnt have to do this process. |
| 52 | +Though using NDK v22 will not give us alot of features to work with. |
| 53 | +This github [issue](https://github.com/fzyzcjy/flutter_rust_bridge/issues/419) explains the reason why we are doing this. |
| 54 | + |
| 55 | + --- |
| 56 | + |
| 57 | + **Android NDK** |
| 58 | + |
| 59 | + After installing the NDK tools for android you should export the PATH to your config file |
| 60 | + (.vimrc, .zshrc, .profile, .bashrc file), That way it can be found. |
| 61 | + |
| 62 | + ```vim |
| 63 | + export PATH=/home/sean/Android/Sdk/ndk/24.0.8215888 |
| 64 | + ``` |
0 commit comments