Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CypherpunkSamurai/1b5adf7759aac0612fd1c9e49ece5419 to your computer and use it in GitHub Desktop.
Save CypherpunkSamurai/1b5adf7759aac0612fd1c9e49ece5419 to your computer and use it in GitHub Desktop.
// from https://stackoverflow.com/questions/10798357/want-to-compile-native-android-binary-i-can-run-in-terminal-on-the-phone
/*
# create tool-chain - one line
# New method in ndk 12.
$NDK/build/tools/make_standalone_toolchain.py --arch arm --install-dir=/tmp/my-android-toolchain
# Old method.
#$NDK/build/tools/make-standalone-toolchain.sh --platform=android-3 --install-dir=/tmp/my-android-toolchain
# add to terminal PATH variable
export PATH=/tmp/my-android-toolchain/bin:$PATH
# make alias CC be the new gcc binary
export CC=arm-linux-androideabi-gcc
# compile your C code(I tried hello world)
$CC -o foo test-ndk.c
# push binary to phone
adb push test-ndk /data/local/tmp
# execute binary
adb shell
$ /data/local/tmp/test-ndk
*/
#include <stdio.h>
int
main(void)
{
printf("test-ndk works\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment