美文网首页Android开发Android技术9.0
通告!Android P新增检测项 应用热修复受重大影响

通告!Android P新增检测项 应用热修复受重大影响

作者: SYfarming | 来源:发表于2018-10-23 10:39 被阅读14次

    Google在Android P中添加了新的检测项,对国内大多数应用造成了严重影响:在调用resolve inline method时,如果检测到caller与callee处于不同的dex file,会主动发起abort(inline不允许跨dex文件),导致应用出现闪退等异常问题。

    问题原因:

    源码文件: art/runtime/entrypoints/entrypoint_utils-inl.h
    源码关于art的下载地址: https://android.googlesource.com/platform/art/
    commit 7c947996ca9426a8ae3abf9feb110f166d8f11da

    commit 7c947996ca9426a8ae3abf9feb110f166d8f11da
    Author: Vladimir Marko <vmarko@google.com>
    Date:   Thu Apr 26 09:18:10 2018 +0100
    
        AOT inlined method lookup should stay within dex file.
        
        Rewrite the AOT inlined method lookup and guard against
        crossing dex file boundary. The compiler does not currently
        support inlining across dex files, so this is an indication
        of multiple dex files defining the same class and the AOT
        code having used a definition which is not used at runtime.
        
        Test: m test-art-host-gtest
        Test: testrunner.py --host --optimizing --jit
        Test: Pixel 2 XL boots.
        Test: testrunner.py --target --optimizing --jit
        Bug: 74410240
        
        (cherry picked from commit 63a9f3e9e1b9fb8d98d8ca9abe626f3aa11e5692)
        
        Change-Id: Ibe9792f952d0c963b8560f10d57a951e227b24aa
    

    从提交的日志可以看出,内敛inline应该存放在一个dex文件中,不允许跨dex文件

    关于art/runtime/entrypoints/entrypoint_utils-inl.h的日志:


    1、问题场景

    由于国内大多数应用基本上都集成了热修复功能,所以 Android P的这个特性对国内应用影响较大。(不太理解热修复的童鞋可以参考:阿里的Android热修复技术原理.pdf)

    目前发现主要有两种情况:

    • 场景一

    应用原始apk中的dex A和从应用服务端下载的热修复dex B存在重复类,触发热修复且系统后台优化inline编译后,便会出现此问题。

    • 场景二

    由 classloader A 加载的 class1 调用一个由 classloader B 加载的 class2里的某个 inline 方法,将导致应用闪退。

    2、应用如何自检?

    • 1.首先建议应用在Android P中测试验证是否有该问题:

    adb shell cmd package compile –m speed –f 应用包名 (inline编译)。
    启动应用,构造热修复场景,在应用侧触发热修复。
    热修复完成之后,重启应用,检测有无闪退和无响应问题。

    • 2.通过关键日志分析确认问题:

    如果问题日志中有这个关键日志:This must be due to duplicate classes or playing wrongly with class loaders,可以确定就是该问题。

    如下图:

    06-20 19:07:24.597 30376 30376 F m.taobao.taoba:entrypoint_utils-inl.h:94]
    Inlined method resolution crossed dex file boundary: 
    from void com.ali.mobisecenhance.Init.doInstallCodeCoverage
    (android.app.Application, android.content.Context) in
    /data/app/com.taobao.taobao-YPDeV7WbuyZckOfy-5AuKw==/base.apk!classes3.dex/0xece238f0
    to void com.ali.mobisecenhance.code.CodeCoverageEntry.CoverageInit
    (android.app.Application, android.content.Context) in
    /data/user/0/com.taobao.taobao/files/storage/com.taobao.maindex
    /dexpatch/1111/com_taobao_maindex.zip!classes4.dex/0xebda4320. 
    This must be due to duplicate classes or playing wrongly with class loaders
    
    • 3、修复建议
      • 1.不要将ROM中预置的jar包打包至apk。

      • 2.不要使用相同的class loader加载重复类。

      • 3.如果必须要有重复类的话,避免内联现象(比如,在不期望被inline的函数里面加try catch,这样compiler就不会将此函数inline)。

    相关文章

      网友评论

        本文标题:通告!Android P新增检测项 应用热修复受重大影响

        本文链接:https://www.haomeiwen.com/subject/qedozftx.html