Tencent / tinker

Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.
Other
17.18k stars 3.33k forks source link

dex2oat: Failed to open dex file for layout: Failure to verify dex file #1085

Open zysidea opened 5 years ago

zysidea commented 5 years ago
**补丁可以下载成功,但是无法load,已经打开MIUI的自启动**

异常类型:app运行时异常

手机型号:小米6x,华为荣耀8Lite,1加6T

手机系统版本:小米6x(9.0,8.1),华为荣耀8Lite(8.0),1加6T(9.0)

tinker版本:1.9.9 和 1.9.13

gradle版本:3.1.1

是否使用热更新SDK: Bugly SDK

系统:Mac

堆栈/日志:
2019-05-05 20:14:21.416 2352-2368/? D/Boost: hostingType=service, hostingName=com.yuncheapp.android.pearl/com.tencent.tinker.lib.service.TinkerPatchService, callerPackage=android, isSystem=true, isBoostNeeded=false.

2019-05-05 20:14:21.420 2352-2368/? I/ActivityManager: Start proc 6179:com.yuncheapp.android.pearl:patch/u0a528 for service com.yuncheapp.android.pearl/com.tencent.tinker.lib.service.TinkerPatchService caller=android

2019-05-05 20:14:22.212 6179-6240/? I/oid.pearl:patc: Speed up secondary dex load for /data/user/0/com.yuncheapp.android.pearl/tinker/patch-340281bf/dex/oat/arm/tinker_classN.odex

2019-05-05 20:14:22.387 6256-6256/? I/dex2oat: /system/bin/dex2oat -j6 --dex-file=/data/user/0/com.yuncheapp.android.pearl/tinker/patch-340281bf/dex/tinker_classN.apk --output-vdex-fd=69 --oat-fd=70 --oat-location=/data/user/0/com.yuncheapp.android.pearl/tinker/patch-340281bf/dex/oat/arm/tinker_classN.odex --compiler-filter=verify --class-loader-context=&

2019-05-05 20:14:24.796 6256-6256/? E/dex2oat: Failed to open dex file for layout: Failure to verify dex file '/data/user/0/com.yuncheapp.android.pearl/tinker/patch-340281bf/dex/tinker_classN.apk!classes2.dex': <clinit> must have descriptor ()V
2019-05-05 20:14:24.860 6179-6240/? W/oid.pearl:patc: Failed execv(/system/bin/dex2oat --instruction-set=arm --instruction-set-features=div,atomic_ldrd_strd,armv8a --runtime-arg -Xhidden-api-checks --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m -j6 --instruction-set-variant=cortex-a73 --instruction-set-features=default --dex-file=/data/user/0/com.yuncheapp.android.pearl/tinker/patch-340281bf/dex/tinker_classN.apk --output-vdex-fd=69 --oat-fd=70 --oat-location=/data/user/0/com.yuncheapp.android.pearl/tinker/patch-340281bf/dex/oat/arm/tinker_classN.odex --compiler-filter=verify --class-loader-context=&) because non-0 exit status

2019-05-05 20:14:25.473 6179-6240/? W/oid.pearl:patc: Zip open failed: Failure to verify dex file '/data/user/0/com.yuncheapp.android.pearl/tinker/patch-340281bf/dex/tinker_classN.apk!classes2.dex': <clinit> must have descriptor ()V

2019-05-05 20:19:13.366 2352-2366/? W/ActivityManager: Scheduling restart of crashed service com.yuncheapp.android.pearl/com.tencent.tinker.lib.service.TinkerPatchService in 30959ms

2019-05-05 20:19:13.376 2352-2366/? I/ActivityManager:   Force stopping service ServiceRecord{6f75e68 u0 com.yuncheapp.android.pearl/com.tencent.tinker.lib.service.TinkerPatchService}
zysidea commented 5 years ago
补充关于JobScheduler堆栈日志,没有打开MIUI的自启动

异常类型:app运行时异常

手机型号:小米6x

手机系统版本:9.0

tinker版本:1.9.9 和 1.9.13

gradle版本:3.1.1

是否使用热更新SDK: Bugly SDK

系统:Mac

堆栈/日志:
2019-05-05 20:30:22.713 2352-4794/? I/AutoStartManagerService: MIUILOG- Reject service :Intent { cmp=com.yuncheapp.android.pearl/com.tencent.tinker.lib.service.TinkerPatchService } userId : 0 uid : 10529
2019-05-05 20:30:22.714 2352-4794/? D/JobScheduler: Error executing JobStatus{542d1b3 #u0a529/-642605764 com.yuncheapp.android.pearl/com.tencent.tinker.lib.service.TinkerPatchService u=0 s=10529 TIME=none:-2ms READY}
tys282000 commented 5 years ago

补丁对应的完整包在运行的时候会报这个错误吗? 可以试试直接安装完整新包看看log里有没有类似的输出。

zysidea commented 5 years ago
小米6x android9.0  安装上述生成的完成的包

直接运行完整包,堆栈错误如下:

 java.lang.RuntimeException: Unable to instantiate application com.kuaishou.athena.tinker.KwaiApplication: com.tencent.tinker.loader.TinkerRuntimeException: Tinker Exception:fail to invoke onBaseContextAttached of appLike.
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1073)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5920)
        at android.app.ActivityThread.access$1200(ActivityThread.java:200)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6810)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
     Caused by: com.tencent.tinker.loader.TinkerRuntimeException: Tinker Exception:fail to invoke onBaseContextAttached of appLike.
        at com.tencent.tinker.loader.app.TinkerApplication.invokeAppLikeOnBaseContextAttached(TinkerApplication.java:133)
        at com.tencent.tinker.loader.app.TinkerApplication.onBaseContextAttached(TinkerApplication.java:148)
        at com.tencent.tinker.loader.app.TinkerApplication.attachBaseContext(TinkerApplication.java:164)
        at android.app.Application.attach(Application.java:215)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1122)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1065)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5920) 
        at android.app.ActivityThread.access$1200(ActivityThread.java:200) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:201) 
        at android.app.ActivityThread.main(ActivityThread.java:6810) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
zysidea commented 5 years ago

但是在android 7.1(包含)以下,补丁可以应用成功,而且直接安装完整包也没有报错 @tomystang ps: 上述完整的包是执行bugly的buildTinkerPatchRelease生成的包

tys282000 commented 5 years ago

这个堆栈前后还有其他信息吗?尤其是后面应该还有几个cause by才对的

zysidea commented 5 years ago
   java.lang.RuntimeException: Unable to instantiate application com.kuaishou.athena.tinker.KwaiApplication: com.tencent.tinker.loader.TinkerRuntimeException: Tinker Exception:fail to invoke onBaseContextAttached of appLike.
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1073)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5920)
        at android.app.ActivityThread.access$1200(ActivityThread.java:200)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6810)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
     Caused by: com.tencent.tinker.loader.TinkerRuntimeException: Tinker Exception:fail to invoke onBaseContextAttached of appLike.
        at com.tencent.tinker.loader.app.TinkerApplication.invokeAppLikeOnBaseContextAttached(TinkerApplication.java:133)
        at com.tencent.tinker.loader.app.TinkerApplication.onBaseContextAttached(TinkerApplication.java:148)
        at com.tencent.tinker.loader.app.TinkerApplication.attachBaseContext(TinkerApplication.java:164)
        at android.app.Application.attach(Application.java:215)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1122)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1065)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5920) 
        at android.app.ActivityThread.access$1200(ActivityThread.java:200) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:201) 
        at android.app.ActivityThread.main(ActivityThread.java:6810) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.tencent.tinker.loader.app.TinkerApplication.invokeAppLikeOnBaseContextAttached(TinkerApplication.java:131)
        at com.tencent.tinker.loader.app.TinkerApplication.onBaseContextAttached(TinkerApplication.java:148) 
        at com.tencent.tinker.loader.app.TinkerApplication.attachBaseContext(TinkerApplication.java:164) 
        at android.app.Application.attach(Application.java:215) 
        at android.app.Instrumentation.newApplication(Instrumentation.java:1122) 
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1065) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5920) 
        at android.app.ActivityThread.access$1200(ActivityThread.java:200) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:201) 
        at android.app.ActivityThread.main(ActivityThread.java:6810) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lio/reactivex/internal/schedulers/j;
        at io.reactivex.f.a$g.<clinit>(Schedulers.java:58)
        at io.reactivex.f.a$h.call(Schedulers.java:1387)
        at io.reactivex.e.a.a(RxJavaPlugins.java:1306)
        at io.reactivex.f.a.<clinit>(Schedulers.java:2319)
        at io.reactivex.f.a.a(Schedulers.java:341)
        at com.kwai.a.a.<init>(Async.java:53)
        at com.kwai.a.a.<init>(Async.java:21)
        at com.kwai.a.a$a.<clinit>(Async.java:38)
        at com.kwai.a.a.a(Async.java:1042)
        at com.kuaishou.athena.storage.preference.a.<init>(BaseSharedPreferences.java:2039)
        at com.kuaishou.athena.storage.preference.i.<init>(ProviderPreferences.java:25)
        at com.kuaishou.athena.storage.preference.f.a(MultiProcessSharedPreferences.java:152)
        at com.kuaishou.athena.storage.preference.f.<init>(MultiProcessSharedPreferences.java:29)
        at com.kuaishou.athena.account.Account.e(Account.java:282)
        at com.kuaishou.athena.account.CurrentUser.<init>(CurrentUser.java:32)
        at com.kuaishou.athena.init.module.PreferenceInitModule.a(PreferenceInitModule.java:74)
        at com.kuaishou.athena.KwaiAppLike.onBaseContextAttached(KwaiAppLike.java:2122)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.tencent.tinker.loader.app.TinkerApplication.invokeAppLikeOnBaseContextAttached(TinkerApplication.java:131) 
        at com.tencent.tinker.loader.app.TinkerApplication.onBaseContextAttached(TinkerApplication.java:148) 
        at com.tencent.tinker.loader.app.TinkerApplication.attachBaseContext(TinkerApplication.java:164) 
        at android.app.Application.attach(Application.java:215) 
        at android.app.Instrumentation.newApplication(Instrumentation.java:1122) 
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1065) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5920) 
        at android.app.ActivityThread.access$1200(ActivityThread.java:200) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:201) 
        at android.app.ActivityThread.main(ActivityThread.java:6810) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "io.reactivex.internal.schedulers.j" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.yuncheapp.android.pearl--QuKZdBF2skjYCOqZmrQUg==/base.apk"],nativeLibraryDirectories=[/data/app/com.yuncheapp.android.pearl--QuKZdBF2skjYCOqZmrQUg==/lib/arm, /system/fake-libs, /data/app/com.yuncheapp.android.pearl--QuKZdBF2skjYCOqZmrQUg==/base.apk!/lib/armeabi-v7a, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at io.reactivex.f.a$g.<clinit>(Schedulers.java:58) 
        at io.reactivex.f.a$h.call(Schedulers.java:1387) 
        at io.reactivex.e.a.a(RxJavaPlugins.java:1306) 
        at io.reactivex.f.a.<clinit>(Schedulers.java:2319) 
        at io.reactivex.f.a.a(Schedulers.java:341) 
        at com.kwai.a.a.<init>(Async.java:53) 
        at com.kwai.a.a.<init>(Async.java:21) 
        at com.kwai.a.a$a.<clinit>(Async.java:38) 
        at com.kwai.a.a.a(Async.java:1042) 
        at com.kuaishou.athena.storage.preference.a.<init>(BaseSharedPreferences.java:2039) 
        at com.kuaishou.athena.storage.preference.i.<init>(ProviderPreferences.java:25) 
        at com.kuaishou.athena.storage.preference.f.a(MultiProcessSharedPreferences.java:152) 
        at com.kuaishou.athena.storage.preference.f.<init>(MultiProcessSharedPreferences.java:29) 
        at com.kuaishou.athena.account.Account.e(Account.java:282) 
        at com.kuaishou.athena.account.CurrentUser.<init>(CurrentUser.java:32) 
        at com.kuaishou.athena.init.module.PreferenceInitModule.a(PreferenceInitModule.java:74) 
        at com.kuaishou.athena.KwaiAppLike.onBaseContextAttached(KwaiAppLike.java:2122) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.tencent.tinker.loader.app.TinkerApplication.invokeAppLikeOnBaseContextAttached(TinkerApplication.java:131) 
        at com.tencent.tinker.loader.app.TinkerApplication.onBaseContextAttached(TinkerApplication.java:148) 
        at com.tencent.tinker.loader.app.TinkerApplication.attachBaseContext(TinkerApplication.java:164) 
        at android.app.Application.attach(Application.java:215) 
        at android.app.Instrumentation.newApplication(Instrumentation.java:1122) 
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1065) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5920) 
        at android.app.ActivityThread.access$1200(ActivityThread.java:200) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:201) 

看样子是主dex没有这个io.reactivex.internal.schedulers.j类,但是打release包的时候有配置主dex的列表,其中有io/reactivex/internal/**/class,查看apk的classes.dex,也是存在的 @tomystang

tys282000 commented 5 years ago

io.reactivex.f.a$g. 看下这个方法里对io.reactivex.internal.schedulers.j是不是作为数组类型或者注解类型来引用的?看现象很像是之前查过的proguard的坑。

方便的话把有问题的新apk也发到yinshengtang92@gmail.com吧。

zysidea commented 5 years ago

是直接new的io.reactivex.internal.schedulers.j,非数组类型或者注解类型。基准包,新包,补丁都邮件发给你了,谢谢帮助@tomystang

zysidea commented 5 years ago

@tomystang 想咨询个问题,直接用assembleRelease的包可以安装,用Tinker的tinkerPatchRelease的包就不能安装,Tinker对assembleRelease做了什么修改么?

tys282000 commented 5 years ago

发下安装失败的提示?

tys282000 commented 5 years ago

运行之后crash的问题找到了,原因跟 #711 一样,都是某个dex中的clinit方法因为proguard的原因缺少V()这个proto定义导致的,dex2oat的log里能看到这句:

dex2oat : Failed to open dex file from oat file. File: base.apk!classes2.dex Error: Failure to verify dex file 'base.apk!classes2.dex': must have descriptor ()V

参考那个issue里的解法就可以了。

zysidea commented 5 years ago

@tomystang 按照711的方式已经可以,但是又出现了新的问题,跟 #638的一样,奇怪的时候补丁竟然可以应用成功。

Failed to add image file Failed to flatten class loader hierarchy 'Unknown class loader type com.tencent.tinker.loader.AndroidNClassLoader'
2019-05-07 15:56:21.040 23348-23348/? I/earl:messagesd: Failed to add image file Failed to flatten class loader hierarchy 'Unknown class loader type com.tencent.tinker.loader.AndroidNClassLoader'
2019-05-07 15:56:21.344 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:194)
2019-05-07 15:56:21.344 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:200)
2019-05-07 15:56:21.344 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:194)
2019-05-07 15:56:21.345 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:194)
2019-05-07 15:56:21.345 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:200)
2019-05-07 15:56:21.345 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:194)
2019-05-07 15:56:21.346 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:194)
2019-05-07 15:56:21.346 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:200)
2019-05-07 15:56:21.346 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:194)
2019-05-07 15:56:21.346 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:194)
2019-05-07 15:56:21.346 23262-23470/? I/p.android.pear:     at java.lang.Class com.tencent.tinker.loader.AndroidNClassLoader.findClass(java.lang.String) (AndroidNClassLoader.java:200)
tys282000 commented 5 years ago

这个问题跟 #638 还不太一样,那边是因为ApplicationLike没做隔离导致的,1.9.9和1.9.13已经把ApplicationLike和TinkerApplication用反射隔离了,所以补丁加载应该是没问题的,但是Android 9.0不认识Tinker自定义的ClassLoader,所以就无法对补丁dex产生art缓存文件,并且会打log。