so文件相关

时间:2022-11-20 16:52:48

2018-08-31

今天尝试了一下编译so文件。

最开始是按照这个博主来操作的https://blog.csdn.net/tianshuai4317618/article/details/79073836

后来我的Android Studio (v3.1.3)说这种方式不再支持了,叫我换CMake。

然后我就换CMake了,可是一直报这个错

Build command failed.
Error while executing process D:\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {-HG:\AndroidStudioProjects\SoTest\app -BG:\AndroidStudioProjects\SoTest\app\.externalNativeBuild\cmake\debug\armeabi-v7a -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-14 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=G:\AndroidStudioProjects\SoTest\app\build\intermediates\cmake\debug\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Debug -DANDROID_NDK=D:\sdk\ndk-bundle -DCMAKE_CXX_FLAGS= -DCMAKE_TOOLCHAIN_FILE=D:\sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=D:\sdk\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja}
CMake Error in CMakeLists.txt:
The CMAKE_C_COMPILER:
D:/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
The CMAKE_CXX_COMPILER:
D:/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "G:/AndroidStudioProjects/SoTest/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log".
Build command failed.
Error while executing process D:\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {-HG:\AndroidStudioProjects\SoTest\app -BG:\AndroidStudioProjects\SoTest\app\.externalNativeBuild\cmake\release\armeabi-v7a -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-14 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=G:\AndroidStudioProjects\SoTest\app\build\intermediates\cmake\release\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DANDROID_NDK=D:\sdk\ndk-bundle -DCMAKE_CXX_FLAGS= -DCMAKE_TOOLCHAIN_FILE=D:\sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=D:\sdk\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja}
CMake Error in CMakeLists.txt:
The CMAKE_C_COMPILER:
D:/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
The CMAKE_CXX_COMPILER:
D:/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "G:/AndroidStudioProjects/SoTest/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeOutput.log".

一直以为要配置什么变量,就去学CMakeLists.txt的语法,也没找到那个变量,不了了之了。

天无绝人之路,后来我碰运气,打到了解决办法

感谢博主https://blog.csdn.net/qq_36630050/article/details/80708685

我以前的ndk是17的,我按他说的改为ndk 16的就好了。

2018-09-19

今天打aar模块包的时候,不知道为什么,so文件没有打包进去,我是手动加进去的。好奇怪,导出aar没有包括so文件。

2019-04-22

04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk I/art: Rejecting re-init on previously-failed class java.lang.Class<cn.angelshelter.app.apicloud.ffmpeg.link.FFmpegLink>
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: java.lang.reflect.InvocationTargetException
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at java.lang.reflect.Method.invoke(Native Method)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at com.uzmap.pkg.uzcore.uzmodule.a$a.a(Unknown Source)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at com.uzmap.pkg.uzcore.uzmodule.a$1.run(Unknown Source)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at android.os.Looper.loop(Looper.java:135)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5569)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at java.lang.reflect.Method.invoke(Native Method)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:931)
04-22 22:49:57.069 31357-31357/com.apicloud.pkg.sdk W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:726)
04-22 22:49:57.079 31357-31357/com.apicloud.pkg.sdk W/System.err: Caused by: java.lang.UnsatisfiedLinkError: cn.angelshelter.app.apicloud.ffmpeg.link.FFmpegLink
04-22 22:49:57.079 31357-31357/com.apicloud.pkg.sdk W/System.err: at cn.angelshelter.app.apicloud.ffmpeg.link.FFmpegLink.getInt(Native Method)
04-22 22:49:57.079 31357-31357/com.apicloud.pkg.sdk W/System.err: at cn.angelshelter.app.apicloud.ffmpeg.FFmpegModule.jsmethod_test(FFmpegModule.java:19)
04-22 22:49:57.079 31357-31357/com.apicloud.pkg.sdk W/System.err: ... 12 more

原因是我依赖了一个其它的第三方动态库so,但是我把那个so加进apk直接闪退,晕,如果把那个依赖库去掉就ok了。

2018-05-05

W/System.err: java.lang.reflect.InvocationTargetException
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
at com.uzmap.pkg.uzcore.uzmodule.a$a.a(Unknown Source)
at com.uzmap.pkg.uzcore.uzmodule.a$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6268)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:916)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:806)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: library "libavutil-55.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:989)
at java.lang.System.loadLibrary(System.java:1530)
at cn.angelshelter.app.apicloud.ffmpeg.link.FFmpegLink.<clinit>(FFmpegLink.java:23)
at cn.angelshelter.app.apicloud.ffmpeg.link.FFmpegLink.getInt(Native Method)
at cn.angelshelter.app.apicloud.ffmpeg.FFmpegModule.jsmethod_test(FFmpegModule.java:19)
... 10 more

用别人打好的so包。如果是

System.loadLibrary("swresample");//导入生成的链接库文件
System.loadLibrary("avcodec");//导入生成的链接库文件
System.loadLibrary("avutil");//导入生成的链接库文件

这样的顺序,就会报上面的错误 :

正确的写法是

System.loadLibrary("avutil");//导入生成的链接库文件
System.loadLibrary("swresample");//导入生成的链接库文件
System.loadLibrary("avcodec");//导入生成的链接库文件

。不过后来我自己打的包,却没这个限制。

2019-05-12

-- ::30.922 -/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.apicloud.pkg.sdk, PID:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.apicloud.pkg.sdk-1/base.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.apicloud.pkg.sdk-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.apicloud.pkg.sdk-/lib/arm64, /system/fake-libs64, /data/app/com.apicloud.pkg.sdk-/base.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_dependencies_apk.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_slice_0_apk.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_slice_2_apk.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_slice_3_apk.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_slice_4_apk.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_slice_5_apk.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_slice_6_apk.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_slice_7_apk.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_slice_8_apk.apk!/lib/arm64-v8a, /data/app/com.apicloud.pkg.sdk-/split_lib_slice_9_apk.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libsec.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:)
at java.lang.System.loadLibrary(System.java:)
at com.uzmap.pkg.uzcore.external.Enslecb.<clinit>(Unknown Source)
at com.uzmap.pkg.uzcore.external.Enslecb.xsm(Unknown Source)
at com.uzmap.pkg.uzcore.external.g.b(Unknown Source)
at com.uzmap.pkg.uzcore.t.a(Unknown Source)
at com.uzmap.pkg.uzapp.UZApplication.onCreate(Unknown Source)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:)
at android.os.Handler.dispatchMessage(Handler.java:)
at android.os.Looper.loop(Looper.java:)
at android.app.ActivityThread.main(ActivityThread.java:)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:)

这个是我启用了ndk编译后,没有找到对应的架包造成的,就是ndk打出来的是全平台的,而第三方SDK只是指定平台的。所以要在build.gradle加上

android{
defaultConfig {
ndk{
abiFilters "armeabi"
}
}
}

指定只打包armeabi平台的。

如果加了还是会有,“就清缓存” 。build\intermediates\cmake,这里面的删除了。我的就是多了一个arm64-v8a平台。