简体   繁体   中英

JNI shared library seem to contain symbols in release build

I'm new to android native development. Currently working on porting a library to android platform and integrating it with app.

I build the library via ndk-build command line tool. In release configuration I specify NDK_DEBUG=0 option, and I actually can see in the source C/C++ files that they're indeed compiled in release configuration ( NDEBUG is defined).

However the resulting .so file seem to contains debug symbols. Opening the file with an editor I can see all the internal symbols (variable and function names), which are not exported by the library, hence they clearly should not be be present in release build. I mean, this library file .so is going to be included in the application apk file and distributed to the client, there's no reason in the world the user should get this file with the symbols.

So, how do I get rid of them? Is there an option I should specify in ndk-build command line or Android.mk file?

You should use the APP_OPTIM := release in your Application.mk file as well as android:debuggable="false" in AndroidManifest.xml .

APP_OPTIM
    This optional variable can be defined to either 'release' or
    'debug'. This is used to alter the optimization level when
    building your application's modules.

    A 'release' mode is the default, and will generate highly
    optimized binaries. The 'debug' mode will generate un-optimized
    binaries which are much easier to debug.

    Note that if your application is debuggable (i.e. if your manifest
    sets the android:debuggable attribute to "true" in its <application>
    tag), the default will be 'debug' instead of 'release'. This can
    be overridden by setting APP_OPTIM to 'release'.
Note that it is possible to debug both 'release' and 'debug'
binaries, but the 'release' builds tend to provide less information
during debugging sessions: some variables are optimized out and
can't be inspected, code re-ordering can make stepping through
the code difficult, stack traces may not be reliable, etc...

By the way, if you take a closer look at what ndk-build is actually doing, you should see a strip command, with is I think responsible for removing such symbols.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM