xxxx.so : text relocations 问题解决方法 (最新)

2018-09-09 00:25:51

以下是对别人答案的引用:

//////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


问题表现形式

错误或警告日志


当targetSdkVersion>=23且使用debug签名时,在6.0+的Android设备上运行App会输出以下错误Log:

E/linker: /data/app/packagename/lib/arm/libxxx.so: has text relocations 
W/System.err: java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/packagename/lib/arm/libxxx.so: has text relocations

注意:当targetSdkVersion>=23,在低于6.0的设备上运行是正常的,至于原因,本文最后会谈到。

当targetSdkVersion<23且使用debug签名时,在6.0+的Android设备上虽然运行正常,但会输出以下警告Log:

W/linker: “/data/app/packagename/lib/arm/libxxx.so”: has W+E (writable and executable) load segments. This is a security risk shared libraries with W+E load segments will not be supported in a future Android release. Please fix the library.

W/linker: /data/app/packagename/lib/arm/libxxx.so has text relocations. This is wasting memory and prevents security hardening. Please fix.

App启动时弹出提醒对话框

当targetSdkVersion<23且使用debug签名的APK运行在高版本系统上(此处使用原生7.0测试),每次启动时会弹出一个对话框,其内容如下:

Detected problems with app native libraries (please consult log for detail) : libxxx.so: text relocations

上述各种表象可以发现是同一个问题所致,即libxxx.so: text relocations。

问题原因

“libxxx.so: text relocations”这个问题在Android 6.0官方的更新说明中有提及:

On previous versions of Android, if your app requested the system to load a shared library with text relocations, the system displayed a warning but still allowed the library to be loaded. Beginning in this release, the system rejects this library if your app’s target SDK version is 23 or higher. To help you detect if a library failed to load, your app should log the dlopen(3) failure, and include the problem description text that the dlerror(3) call returns. To learn more about handling text relocations, see this guide.

这个问题在6.0之前只会产生一个警告,系统还是可以正常加载包含text relocations的共享库的,但从6.0起,即SDK Version>=23时,系统将会拒绝加载包含text relocations的共享库,同时输出错误Log,也就是上文中看到的错误日志。

其实引起该问题的最根本原因,是so动态链接库的代码并非PIC(Position independent code),关于PIC的概念可以参考维基百科的介绍。在Android 6.0更新说明中,也只是简单提了一句处理方案:

To learn more about handling text relocations, see this guide.

该链接是一个解决text relocations (TEXTRELs)的指南。

\\\\\\\\\\\\\\\\\\\\\\\\\\///////////////////////////////////引用结束

  上面的引用内容中大部分的内容都是正确的,其中 红色加粗部分描述的不正确让我浪费了好长时间:

  按照上文红色加粗部分满足两个条件就不会显示错误提示

  1.targetSdkVersion < 23

  2.不使用debug 签名文件


  因为在我自己的项目里面debug 和release 都使用的同一个key 签名,所以我想当然的认为 在我自己的项目中不会出现这个错误弹窗。但是现实还是赤裸裸的打脸。

   最开始为了解决这个问题查了不少的资料,答案基本都一样。没有什么能解决我问题的。 后来自己就不断的尝试,修改targetSdkVersion 版本拉、更改so 引入方式、不直接run 而是打包;结果我发现 打release 包 没有问题 其他的包beta 、dev、pre、都不行 。最后我比对其他环境和release 环境的不同点 发现了原因。debuggable  

这个才是是否出现弹框的关键, 即使你使用debug 签名,只要关闭了debuggable 模式 都不会出现弹框;


      下面来说一下设置debuggable 开启 关闭的方法:

1. 在AndroidMainfest.xml 中设置


<applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme"android:debuggable="false">



2. 在build.gradle 中设置

buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'}debug {debuggable false}}



debuggable false 就是关闭调试模式,在IDEA中不会显示该进程名字也不能调试;

在build.gradle 中默认release 中debuggable 是false 的 ,debug 中 debuggable 是true 的,如果要不用默认设置需要自己写一下。这样给测试打的包就没有弹窗了,我们发布项目时候 debuggable 一定要关闭 不管什么项目。

       以上是我的解决方案,tagerversion 如果>= 23如何解决,大家可以一起讨论下


  • 2020-04-03 16:56:59

    Inkscape教程

    本教程演示了Inkscape基础使用。这是常规Inkscape文档,你可以预览、编辑、复制、保存。 本教程包括画布导航、管理文档、形状工具基础、选择技术、使用选择转换对象、分组、设置填充和画笔、对齐和Z顺序。有关更高级的主题请查看帮助菜单中的其它教程。

  • 2020-04-03 17:04:35

    Inkscape/SVG附中文教程PDF

    Inkscape中的终极工具是XML编辑器(Shift+Ctrl+X),可以实时显示整个文档的XML树形图。修改绘图时,你可以注意一下XML树形图中的变化。也可以在XML编辑器中修改文本、元素或者节点属性,然后在画图上查看效果。这是一个非常形象化的学习SVG格式的交互式工具。并且可以实现一些通常的编辑工具无法完成的功能。

  • 2020-04-03 19:09:31

    CryptoJS.enc.UTF8 中文乱码

    ret = CryptoJS.AES.encrypt(data,'secret key 123') content = ret.toString() result = CryptoJS.AES.decrypt(content,'secret key 123') print(result.toString(CryptoJS.enc.Utf8))

  • 2020-04-03 19:10:56

    nodejs与javascript中的aes加密

    aes加密简单来说,在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。高级加密标准已然成为对称密钥加密中最流行的算法之一。

  • 2020-04-03 19:13:05

    Express-session的使用

    当浏览器访问服务器并发送第一次请求时,服务器端会创建一个 session 对象,生成一个类似于 key,value 的键值对,然后将 key(cookie)返回到浏览器(客户)端,浏览器下次再访问时,携带 key(cookie), 找到对应的 session(value)。 客户的信息都保存在 session 中

  • 2020-04-08 22:46:28

    Element的操作方法

    Element 是一个通用性非常强的基类,所有 Document 对象下的对象都继承自它。这个接口描述了所有相同种类的元素所普遍具有的方法和属性。一些接口继承自 Element 并且增加了一些额外功能的接口描述了具体的行为。例如, HTMLElement 接口是所有 HTML 元素的基本接口,而 SVGElement 接口是所有 SVG 元素的基础。大多数功能是在这个类的更深层级(hierarchy)的接口中被进一步制定的。