android内联优化导致Inlined method resolution crossed dex file boundary

最近App在android11上出现了一个诡异的native 崩溃,很不容易出现,但都是有个特点就是安装App后过一段时间才会出现,杀进程没用,覆盖安装同一个apk,崩溃立刻消失,日志为如下:

1243 08-02 15:44:16.921 18134 18134 F pace.android:p: entrypoint_utils-inl.h:101] Inlined method resolution crossed dex file boundary: from void com.xxx.l1ll1lIIl1I. Il1llll111.Il1IIl1lllII1.IIIIIlI1IIIl1$lIIIl11ll11.<init>() in /data/app/~~dZ1qJ5hUv_FgD08Tr9d4pg==/com.xxx.android-x7T-p_8Jw69_1QmnZXhP6g==/base.apk/0x77fd7cf1d0 to void android.net.wifi.IWifiScanner$Stub.<init>() in /apex/com.android.wifi/javalib/framework-wifi.jar/0xb4000077ed7ca590. This must be due to duplicate classes or playing wrongly with class loaders. The  runtime is in an unsafe state.

搜索系统art源码中抛出异常的地方:

 50 inline ArtMethod* GetResolvedMethod(ArtMethod* outer_method,
 51                                     const CodeInfo& code_info,
 52                                     const BitTableRange<InlineInfo>& inline_infos)
 53     REQUIRES_SHARED(Locks::mutator_lock_) {
           ...
 94     if (UNLIKELY(inlined_method->GetDexFile() != method->GetDexFile())) {
 95       // TODO: We could permit inlining within a multi-dex oat file and the boot image,
 96       // even going back from boot image methods to the same oat file. However, this is
 97       // not currently implemented in the compiler. Therefore crossing dex file boundary
 98       // indicates that the inlined definition is not the same as the one used at runtime.
 99       bool target_sdk_at_least_p =
100           IsSdkVersionSetAndAtLeast(Runtime::Current()->GetTargetSdkVersion(), SdkVersion::kP);
101       LOG(target_sdk_at_least_p ? FATAL : WARNING)
102           << "Inlined method resolution crossed dex file boundary: from "
103           << method->PrettyMethod()
104           << " in " << method->GetDexFile()->GetLocation() << "/"
105           << static_cast<const void*>(method->GetDexFile())
106           << " to " << inlined_method->PrettyMethod()
107           << " in " << inlined_method->GetDexFile()->GetLocation() << "/"
108           << static_cast<const void*>(inlined_method->GetDexFile()) << ". "
109           << "This must be due to duplicate classes or playing wrongly with class loaders. "
110           << "The runtime is in an unsafe state.";
111     }
112     method = inlined_method;
113   }
115   return method;
116 }

发现大致意思就是,我们App中集成了framwwork的android.net.wifi.IWifiScanner这个类,在系统dexopt之后发生了内联优化,导致这个系统的类被内敛到odex中了,然后被系统检测到caller与callee处于不同的dex file,也就是在App的odex中有一份,在系统framework-wifi.jar中也有一份,所以主动发起abort(inline不允许跨dex文件),导致应用出现闪退等异常问题,但是sdk小于P的话,只会报WARNING而不是FATAL。
于是在安装了App之后手动对apk进行dexopt

adb shell cmd package compile -m speed -f  packageName

这个崩溃就必现了,这样就比较好分析了,只需要防止这个类被dex优化内敛就行了,加个try-catch就可以。
参考:
Android疑难杂症——因内联优化导致9.0机型Native Crash
Android P新增检测项 应用热修复受重大影响

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值