java.lang.UnsatisfiedLinkError,couldn’t find “libc++_shared.so”问题解决

业精于勤荒于嬉,写文章练习表达能力,写代码练习基本工。

问题:

在测试验证Xlog的过程中,自己创建的项目引入xlog,运行报错:

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.demo.hellowcdb-1/base.apk”],nativeLibraryDirectories=[/data/app/com.demo.hellowcdb-1/lib/arm64, /data/app/com.demo.hellowcdb-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn’t find “libc++_shared.so”

查看下Xlog.java,是需要引入这两个库的:

	public static void open(boolean isLoadLib, int level, int mode, String cacheDir, String logDir, String nameprefix, String pubkey) {
		if (isLoadLib) {
			System.loadLibrary("c++_shared");
			System.loadLibrary("marsxlog");
		}

		appenderOpen(level, mode, cacheDir, logDir, nameprefix, 0, pubkey);
	}

而自己的项目,jniLibs下只有libmarsxlog.so

通过androidstudio -> build -> Analyze Apk,发现libc++_shared.so没有打包进去。


解决方法1

拷贝已有的libc++_shared.so到jniLibs下,要找到arm64-v8a和armeabi-v7a两个架构的so,我没有采用这个方式),毕竟让编译器自己干还是省时省力,不容易出错。


解决方法2:

把mouble修改成c++工程,添加一个CMakeLists.txt,添加一个空的cpp进行编译即可自动打包libc++_shared.so,无需手工拷贝。

1,新建cpp目录,新增一个hello.cpp文件,什么都不写。

2,同样在cpp目录下,新增一个CMakeLists.txt文件,添加hellp.cpp进行编译。

cmake_minimum_required(VERSION 3.4.1)

add_library(
        hello
        Hello.cpp
        )

3,build.gradle 添加 CMakeLists构建项目

    externalNativeBuild {
        cmake {
            path file('src/main/cpp/CMakeLists.txt')
        }
    }

4,添加-DANDROID_STL参数

        externalNativeBuild {
            cmake {
                abiFilters 'armeabi-v7a', 'arm64-v8a'
                arguments "-DANDROID_STL=c++_shared"
            }
        }

5,重新build,发现intermediates的cmake目录自动生成了 libc++_shared.so,app也正常运行了。

├── intermediates

│ ├── cmake
│ │ ├── debug
│ │ │ └── obj
│ │ │ ├── arm64-v8a
│ │ │ │ ├── libc++_shared.so
│ │ │ │ └── libhello.so
│ │ │ └── armeabi-v7a
│ │ │ ├── libc++_shared.so
│ │ │ └── libhello.so

6,最后回顾一下我的module源码结构

├── AndroidManifest.xml
├── cpp
│ ├── CMakeLists.txt
│ ├── Hello.cpp
│ └── Hello.h
├── java
│ └── com
│ ├── demo
│ └── tencent
├── jniLibs
│ ├── arm64-v8a
│ │ └── libmarsxlog.so
│ └── armeabi-v7a
│ └── libmarsxlog.so
└── …


呜谢

集成第三so之dlopen failed: library “libc++_shared.so” not found

NDK编译——C++ 库支持

官方指南 -> C++ 库支持

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值