Issue
I have a third party .so
library which I need to use at compile time only in my application. The provider of the library says:-
NOTE: DO NOT include thelibrary.so as part of agent APK. Use for compilation purpose only.
I have this in my build.gradle
:-
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = project.android.ndkDirectory.absolutePath
project.logger.debug('my debug message')
if (ndkDir == null) {
ndkDir = "/usr/local/bin"
}
commandLine "$ndkDir/ndk-build",
'-C', file('src/main').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
and the Android.mk
file looks like this:-
LOCAL_PATH:= $(call my-dir)
LOCAL_C_INCLUDES:= $(LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= $(LOCAL_PATH)
LOCAL_MODULE:= mymodulename
LOCAL_STL := c++_static
LOCAL_CPPFLAGS := -std=c++11
LOCAL_LDLIBS := -ldl -llog
LOCAL_LDLIBS += -fuse-ld=bfd
LOCAL_LDLIBS += -lz
LOCAL_LDLIBS += -ljnigraphics
LOCAL_LDLIBS += -landroid
LOCAL_LDLIBS +:= -Lmylibrary.so <-------THIS IS THE THIRD PARTY LIB
LOCAL_LDFLAGS:= -Wl,--unresolved-symbols=ignore-all
LOCAL_SRC_FILES:= mylocalfile_using_thecode_from_so_file.cpp
include $(BUILD_SHARED_LIBRARY)
I know I can add the myLibrary.so
as a separate module and package it as a PREBUILT_SHARED_LIBRARY
, but the provider of the library has said that it should not be packaged along with the apk, and should be used at compilation only.
How do I add this library for compilation only?
I am not using cmake. This is a legacy project and there is no goal to upgrade it for some reason.
UPDATE #1
We were using another version of this library in the project. Let us call it Version 1 and were including Version 1 as a PREBUILT_SHARED_LIBRARY
. However when I use the newer Version 2 of the same library as a PREBUILT_SHARED_LIBRARY
, it complains
cannot locate symbol "_ZNK7android8String164sizeEv" referenced by thefinalbuiltlibrary.so .
Regarding the ignore all symbols LDFLAG
:- It is one of the many things I am just trying to make this work.
Solution
How do I add this library for compilation only?
Probably you are trying to exclude that shared library when do apk packaging. Putting below snippet into your app/build.gradle
can achieve this:
android {
...
packagingOptions {
exclude 'lib/x86/thefinalbuiltlibrary.so'
exclude 'lib/x86_64/thefinalbuiltlibrary.so'
exclude 'lib/armeabi-v7a/thefinalbuiltlibrary.so'
exclude 'lib/arm64-v8a/thefinalbuiltlibrary.so'
}
...
}
See: libsupportjni.so files added in the project
Answered By - shizhen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.