Android的NDK:使用静态库比指定precompiled库不同 [英] Android NDK: Static library used is different than precompiled library specified

查看:214
本文介绍了Android的NDK:使用静态库比指定precompiled库不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立++库手动使用Android SDK编译的C值。其结果是libMyUtils.a。

I build a C++ library manually using the Android SDK compiler. The result is libMyUtils.a.

我用我的Java / JNI测试应用程序如下:

I'm using the following in my Java/JNI test application:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := MyUtils
LOCAL_SRC_FILES := ../../../../libs/libMyUtils.a

include $(PREBUILT_STATIC_LIBRARY)

LOCAL_MODULE    := AndroidTests
LOCAL_STATIC_LIBRARIES    := MyUtils

include $(BUILD_SHARED_LIBRARY)

当我建立控制台显示以下内容:

When I build the console shows the following:

[armeabi] Install        : libMyUtils.so => libs/armeabi/libMyUtils.so

现在的一些奇怪的原因,库../../../../libs/libMyUtils.a是一对夫妇兆,但库库/ armeabi / libMyUtils.so只有5KB。是不是应该是相同的库?

Now for some bizarre reason the library ../../../../libs/libMyUtils.a is a couple megabytes, but the library libs/armeabi/libMyUtils.so is only 5KB. Isn't it supposed to be the same library?

当我运行我的测试应用程序,我得到的UnsatisfiedLinkError。很显然,我调用本地函数不位于库中。我在做什么错了?

When I run my test application I get UnsatisfiedLinkError. Obviously the native function I'm calling isn't located in the library. What am I doing wrong?

推荐答案

在最终解决方案是建立在MyUtils库作为 prebuilt共享库。这样,链接器不会删除任何东西。然后我修改我的makefile如下:

In the end the solution was to build the MyUtils library as a prebuilt shared library. This way the linker doesn't strip anything. Then I modified my makefile as follows:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := MyUtils
LOCAL_SRC_FILES := ../../../../libs/libMyUtils.so

include $(PREBUILT_SHARED_LIBRARY)

LOCAL_MODULE    := AndroidTests
LOCAL_SHARED_LIBRARIES    := MyUtils

include $(BUILD_SHARED_LIBRARY)

注意的.so 延伸和preBUILT_的共享 _LIBRARY和BUILD_的共享 _LIBRARY脚本。

Notice the .so extention and the PREBUILT_SHARED_LIBRARY and BUILD_SHARED_LIBRARY scripts.

这篇关于Android的NDK:使用静态库比指定precompiled库不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆