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-12-18 17:15:29

    coTurn stun服务器搭建,禁用turn

    https://github.com/coturn/coturn 在这里git clone 下来然后编译安装,一切默认即可。编译后,也可以不用安装。在编译目录下bin文件夹下有turnserver turnutils_stunclient turnutils_uclient 这三个等一下会用到的软件。

  • 2020-12-18 17:26:25

    coturn配置文件详细解释

    Coturn 是webrtc,p2p视频通话必不少的,主要包含2个主要功能stun服务, turn服务 Coturn 的githup地址为 https://github.com/coturn/coturn/

  • 2020-12-21 06:26:16

    为UIView添加点击事件

    最近经常碰到要将UIImageView和UILabel看成整体的情况,我于是就将他俩用UIView包起来,那么怎么给一个UIView添加点击事件,可以这么实现:

  • 2020-12-21 09:00:20

    Window.matchMedia() 方法详解

    matchMedia() 返回一个新的 MediaQueryList 对象,表示指定的媒体查询字符串解析后的结果。 matchMedia() 方法的值可以是任何一个 CSS @media 规则 的特性, 如 min-height, min-width, orientation 等。 MediaQueryList 对象有以下两个属性:

  • 2020-12-21 09:42:42

    iframe.contentWindow 操作iframe

    注:iframe.contentWindow这里,返回的是iframe的window对象,所以后面可以接着调用document方法,再接着调用getElementByTagName。那么就可以对iframe里面的元素进行操作了。

  • 2020-12-21 14:00:19

    iframe + postMessage跨域通信

    在实际项目开发中可能会碰到在 a.com 页面中嵌套 b.com 页面,这时第一反应是使用 iframe,但是产品又提出在 a.com 中操作,b.com 中进行显示,或者相反。

  • 2020-12-22 12:02:41

    ios开发优秀的开源框架,demo集合

    期待大家和我们一起共同维护,同时也期望大家随时能提出宝贵的意见(直接提交issues即可)。请广大网友只按照目录结构(即使目录结构有问题)添加三方库,并提交pull request。目录问题大家提出issues后楼主会及时更改的。