Skip to content

Instantly share code, notes, and snippets.

@slavc
Last active June 21, 2024 15:29
Show Gist options
  • Save slavc/34d4acd506ea4a7b58079cb0772870d0 to your computer and use it in GitHub Desktop.
Save slavc/34d4acd506ea4a7b58079cb0772870d0 to your computer and use it in GitHub Desktop.
How to install an Android toolchain
These instructions describe how to install an Android toolchain capable of compiling standalone C/C++ programs for an Android device.
1. Download Android NDK from https://developer.android.com/ndk/downloads/index.html and unpack it somewhere.
2. Run the included script to install a standalone toolchain:
mkdir $HOME/opt
$NDK/build/tools/make-standalone-toolchain.sh --arch=arm --install-dir=$HOME/opt/android_toolchain
3. Create a test program and compile it:
cat > hello.c << EOF
#include <stdio.h>
int main(int argc, char **argv) {
printf("Hello, world!\n");
return 0;
}
EOF
$HOME/opt/android_toolchain/bin/arm-linux-androideabi-gcc -fPIC -pic -o hello hello.c
4. Upload the compiled program to the device and see if it works:
adb push hello /cache/hello
adb shell
root@GT-I9100:/ # /cache/hello
WARNING: linker: /cache/hello: unused DT entry: type 0x6ffffffe arg 0x2e0
WARNING: linker: /cache/hello: unused DT entry: type 0x6fffffff arg 0x1
Hello, world!
root@GT-I9100:/ #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment