Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symbols are stripped when building native code using Gradle

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?

like image 495
Erik Hellman Avatar asked Jul 21 '14 18:07

Erik Hellman


People also ask

Why does Gradle build fail?

When Gradle is unable to communicate with the Gradle daemon process, the build will immediately fail with a message similar to this: $ gradle help Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details FAILURE: Build failed with an exception.

What does build Gradle contains?

“build. gradle” are scripts where one can automate the tasks. For example, the simple task to copy some files from one directory to another can be performed by the Gradle build script before the actual build process happens.

What is a build type Gradle?

Build types define certain properties that Gradle uses when building and packaging your app, and are typically configured for different stages of your development lifecycle. There are two build types defined by default, debug and release , and you can customize them and create additional build types.


1 Answers

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.

like image 89
VitalyD Avatar answered Oct 03 '22 22:10

VitalyD