V
V
Volodymyr Palamar2019-07-03 16:07:19
linux
Volodymyr Palamar, 2019-07-03 16:07:19

What commands does ndk-build use to build programs?

Due to the fact that I do not have a computer with x86_64 architecture, I have to build programs manually. I was able to compile hello-jni from google examples but compile other examples not. It seems to me that the import of libandroid.so and liblog.so does not work. I tried writing logs but there was nothing in adb logcat.
I used the following commands
to get the headers file

javah -classpath $ANDROID_JAR/android.jar:obj/ -d jni com.example.demo.DemoActivity

and in order to build
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-arm64/
gcc -Wl,-rpath=$HOME/sdk/libs/arch-arm64/usr/lib/ -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/linux" -I"/root/sdk/android-ndk-r20/sysroot/usr/include/" -L$HOME/sdk/android-ndk-r20/platforms/android-28/arch-arm64/usr/lib/ -landroid -llog -fPIC hello-jni.c -shared -o libhello-jni.so -Wl,-soname -Wl,--no-whole-archive -Wl,--no-undefined -Wl,-z,noexecstack

if anyone needs hello-jni.c
#include <string.h>
#include <jni.h>
#include <android/log.h>
#include "com_example_demo_DemoActivity.h"

JNIEXPORT jstring JNICALL Java_com_example_demo_DemoActivity_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
{
#define LOG_TAG "mtjni"
#define DPRINTF(...)  __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,"ddddddddddddddddddddddddddd")
#define IPRINTF(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,"iiiiiiiiiiiiiiiiiiiiiiiiiiii")
#define EPRINTF(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,"eeeeeeeeeeeeeeeeeeeee")
    return (*env)->NewStringUTF(env, "Hello from JNI !  Compiled with ABI ");
}

the string it returns does not work logging
thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Skyrimus, 2019-08-18
@GORNOSTAY25

Use CMake, working with ndk is the last century, there are a lot of examples on how to set up a build for cmake on the github DSh

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question