JNI共享库似乎在发布版本中包含符号



我是android原生开发的新手。目前正在将一个库移植到android平台,并将其与app集成。

我通过ndk-build命令行工具构建库。在发布配置中,我指定了NDK_DEBUG=0选项,实际上我可以在源C/c++文件中看到它们确实在发布配置中编译(定义了NDEBUG)。

但是生成的。so文件似乎包含调试符号。用编辑器打开文件,我可以看到所有内部符号(变量和函数名),这些符号不是由库导出的,因此它们显然不应该出现在发布构建中。我的意思是,这个库文件。so将包含在应用程序apk文件中并分发到客户端,用户没有理由得到这个带有。

符号的文件。

那么,我如何摆脱它们呢?我应该在ndk-build命令行或Android.mk文件中指定一个选项吗?

您应该在Application.mk文件中使用APP_OPTIM := release,在AndroidManifest.xml文件中使用android:debuggable="false"

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...

顺便说一下,如果你仔细看看ndk-build实际上在做什么,你应该看到一个strip命令,我认为它负责删除这些符号。

最新更新