Characters are removed when creating custom code using Gradle

In my Android project, using the latest Gradle build tools, I have one file with my own C code and a few simple features. The only things that are included in the C file are string.h and jni.h, and the functions just return String and primitives. The file is placed in the jni directory, except for other source folders (java, res, etc.).

When I create the application, it compiles the C code, generates a .so file and includes it in my APK. The problem is that the .so file has ALL characters.

When checking the intermediate .so file placed in build / intermediate / ndk / obj, all characters still exist. So, somewhere after creating the first .so file and when it is packed, everything is devoid.

When creating the .so file using the ndk-build command line, everything works fine and the characters are on.

Is this a bug in the Android Gradle plugin (I'm using the latest version!), Or am I missing something?

+8
android android-studio android-gradle android-ndk jni
source share
2 answers

The characters are in: src / main / obj / local so add to build.grade:

android.sources { main { jni { source { srcDir 'src/main/none' } } jniLibs { source { srcDir 'src/main/obj/local' } } } } 

then go to Debug Configuration-> Debugger and add to the Symbol directories: application / build / intermediate / jniLibs

after that I was able to debug my own code.

+1
source share

Be sure to use the JNIEXPORT and JNICALL macros in your methods. Also, make sure that proguard does not first separate the class that calls only the jni material, and later the jni code itself, because the class does not use it.

https://developer.android.com/tools/help/proguard.html#configuring

Example for JNIEXPORT AND JNICALL

 JNIEXPORT jint JNICALL foobar(JNIEnv* env, jclass cls) { return 0; } 
0
source share

All Articles