简体   繁体   English

Android NDK并加入新的共享库

[英]Android NDK and dropping in new shared libraries

I have a question regarding why I cannot simply drop in new shared libraries in Android without recompiling via NDK-build. 我有一个问题,为什么我不能不通过NDK-build重新编译而直接在Android中添加新的共享库。 Heres what i do: 这是我的工作:

Using Android Studio and the recent release of the Android NDK, I have been able to compile an app that uses a C code, which refers to a shared library. 使用Android Studio和最新发布的Android NDK,我已经能够编译使用C代码的应用程序,C代码指的是共享库。 I compile the shared library with: 我用以下方法编译共享库:

GCC := /xxx/AndroidStudioProjects/android-ndk-r10d/toolchains/x86-4.6/prebuilt/windows/bin/i686-linux-android-gcc.exe
GPP :=/xxx/AndroidStudioProjects/android-ndk-r10d/toolchains/x86-4.6/prebuilt/windows/bin/i686-linux-android-g++.exe
AR  := /xxx/AndroidStudioProjects/android-ndk-r10d/toolchains/x86-4.6/prebuilt/windows/bin/i686-linux-android-ar.exe

OPTIONS  :=\
 -ffunction-sections \
 -funwind-tables  \
 -DANDROID 

default: all
all: obj
    $(AR) r libmathadd.so mathadd.o

obj:
    $(GCC) $(OPTIONS) -c mathadd.c

This gives me my .so file. 这给了我我的.so文件。 I now run my ndk-build with the Android.mk makefile: 现在,我使用Android.mk makefile运行ndk-build:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE           := mathadd
LOCAL_SRC_FILES        :=./libmathadd.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE    := ndk1
 LOCAL_SRC_FILES := native.c
 LOCAL_SHARED_LIBRARIES := mathadd
 include $(BUILD_SHARED_LIBRARY)

Following this, I have my ndk1 .so file and my mathadd .so which i then place in a folder directory: 之后,我有我的ndk1 .so文件和mathadd .so,然后将它们放在文件夹目录中:

app -> src -> jniLibs -> x86 -> libmathadd.so 应用-> src-> jniLibs-> x86-> libmathadd.so

and

app -> src -> jniLibs -> x86 -> libndk1.so 应用-> src-> jniLibs-> x86-> libndk1.so

I compile and run on my emulator, and boom everything works! 我在模拟器上编译并运行,并且一切正常!

Now heres my problem. 现在这是我的问题。 I slightly modify my shared library source (mathadd.c). 我稍微修改了共享库源代码(mathadd.c)。 I recompile it using the first make file and drop it straight into the app tree (without rebuilding the native c code) . 我使用第一个make文件对其进行重新编译,然后将其直接放入应用程序树中(无需重建本机c代码)。 I rebuild the app in Studio, and run on my emulator, and notice that my modifications did not occur. 我在Studio中重建该应用程序,并在模拟器上运行,请注意未发生我的修改。

I am not changing my native source, nor the api between native and my shared library. 我不会更改本机源,也不会更改本机库和共享库之间的api。

If I rebuild the native with the ndk-build script, and drag the new native ndk1 in, everything works again, including the new modifcations. 如果我使用ndk-build脚本重建本机,然后将新的本机ndk1拖入其中,那么一切都会再次起作用,包括新的修改。 It seems I need to rebuild source via ndk everytime I tweak a shared library...?? 似乎每次调整共享库时,都需要通过ndk重建源代码……?

Any ideas? 有任何想法吗?

UPDATE : I opened up my libndk .so library with a RE tool. 更新 :我使用RE工具打开了libndk .so库。 Turns out the ndk compiler is statically adding the libmathadd code into the libndk, despite it being listed as a local shared library. 事实证明,ndk编译器将libmathadd代码静态添加到libndk中,尽管它被列为本地共享库。 Im curious if this is because the optimization is by default set for fastest speed, and the libmathadd code is simplistic math. 我是否很好奇,是因为默认情况下优化设置为最快速度,而libmathadd代码是简单的数学运算。

So libndk1.so has a dependency on libmath.so ? 那么libndk1.so对libmath.so有依赖性吗? That would then be logical to rebuild it when you touch to libmath source. 然后,当您接触libmath源时,将其重建是合乎逻辑的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android NDK共享库 - Android NDK shared libraries 如何在android ndk中添加多个共享库? - How to add multi shared libraries in android ndk? Android NDK / JNI:构建依赖于其他共享库的共享库 - Android NDK/JNI: Building a shared library that depends on other shared libraries 使用Android NDK将共享库和静态库编译为共享库 - Compiling shared and static libraries into a shared library using the Android NDK Android NDK:两个预构建的共享库,但其中一个依赖于另一个 - Android NDK: Two prebuilt shared libraries, but one of them depends on the other NDK和Android Studio,由于共享库而导致编译崩溃 - NDK & Android Studio, compiling it crashes because of shared libraries 将预构建的静态和共享库与Android NDK链接时的问题 - Linking issue when prebuilt static and shared libraries with the Android NDK Android NDK构建 - 包括LOCAL_SHARED_LIBRARIES? - Android NDK building - Include LOCAL_SHARED_LIBRARIES? Android Studio,gradle,ndk,aar以及几个本地共享库 - Android Studio, gradle, ndk, aar and the inclusion of several native shared libraries Android - NDK共享库使用nm / objdump提取相关的JNI挂钩 - Android - NDK Shared libraries extracting relevant JNI hooks with nm / objdump
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM