In particular I am trying to compile chainDD's su binary. I tried to use ndk-build
but it seems I need to set NDK_PROJECT_PATH
but what this should be set to is not described in the documentation.
Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE's integrated build system. Your Java code can then call functions in your native library through the Java Native Interface (JNI) framework.
Android native code is C/C++. Here is a bit of info about SDK(NDK). And here you can find general overview of NDK(native development kit).
The syntax of the Android.mk allows you to group your sources into modules. A module is either a static library, a shared library, or a standalone executable. You can define one or more modules in each Android.mk file, and you can use the same source file in multiple modules.
Android provides Native Development Kit (NDK) to support native development in C/C++, besides the Android Software Development Kit (Android SDK) which supports Java. [TODO] more. NDK is a complex and advanced topics.
First, make sure you have the NDK:
http://developer.android.com/tools/sdk/ndk/index.html
Here is the easiest way to compile a C binary for your phone:
http://developer.android.com/tools/sdk/ndk/index.html
http://www.kandroid.org/ndk/docs/STANDALONE-TOOLCHAIN.html
Usually $NDK(may be different) =
Linux:
/home/<user>
/android-ndk
Mac OS X:
/Users/<user>
/android-ndk
Both: $HOME/android-ndk
In Terminal:
# create tool-chain - one line $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.o -c foo.c # push binary to phone adb push foo.o /data/local/tmp # execute binary adb /data/local/tmp/foo.o
Please let me know if I can help!
Regards,
You need establish your project folder like this:
project_root
|__ jni/ (include Android.mk and your C/C++ code)
|__ other_directory
The jni directory can't change name. and run ndk-build in project_root directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With