9

In my Android project, using the latest Gradle build tools, I have a single file with native C code and a few simple function. The only thing included in the C file is string.h and jni.h and the functions simply return String and primitives. The file is placed in the jni directory besides the other source folders (java, res etc.).

When I build the application, it compile the C code, generates the .so file and includes it in my APK. The problem is that the .so file has ALL symbols stripped.

When inspecting the intermediate .so file placed in build/intermediate/ndk/obj, all the symbols are still there. So somewhere after the first .so file is generated and when it gets packaged, everything is stripped.

When building the .so file using the command line ndk-build, everything works fine and the symbols are included.

Is it a bug in the Android Gradle plugin (I'm using the latest!) or am I missing something?

Erik Hellman
  • 529
  • 4
  • 11

2 Answers2

2

The symbols 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 Symbol directories: app/build/intermediates/jniLibs

after that I was able to debug my native code.

VitalyD
  • 289
  • 1
  • 15
1

make sure to use JNIEXPORT and JNICALL macros in your methods. Also make sure that proguard does not first strip away a class that only calls jni stuff - and later on the jni code itself, because no class is using 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;
}
Martin Gerhardy
  • 1,860
  • 22
  • 13