问题描述
我正在开发一个Instant App,它具有base
模块和2个功能模块:feature1
和feature2
.尝试启动feature2
活动时,我遇到了奇怪的崩溃:
I'm developing an Instant App, that has base
module and 2 feature modules: feature1
and feature2
. I'm getting strange crash when I'm trying to launch feature2
activity:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.myapp.qa/com.test.myapp.feature2.ui.activity.Feature2Activity}: android.view.InflateException: Binary XML file line #76: Binary XML file line #76: Error inflating class android.widget.ProgressBar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #76: Binary XML file line #76: Error inflating class android.widget.ProgressBar
Caused by: android.view.InflateException: Binary XML file line #76: Error inflating class android.widget.ProgressBar
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:650)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:723)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:791)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at com.test.myapp.ui.activity.base.BaseActivity.setContentView(BaseActivity.java:237)
at com.test.myapp.feature2.ui.activity.Feature2Activity.onCreate(Feature2Activity.java:123)
at android.app.Activity.performCreate(Activity.java:6980)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.content.res.Resources$NotFoundException: Drawable com.test.myapp.qa:layout/random_feature1_layout with resource ID #0x82030011
E/AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: File res/layout/random_feature1_layout_fns.xml from drawable resource ID #0x82030011
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:754)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:598)
at android.content.res.Resources.loadDrawable(Resources.java:885)
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
at android.widget.ProgressBar.<init>(ProgressBar.java:281)
at android.widget.ProgressBar.<init>(ProgressBar.java:230)
at android.widget.ProgressBar.<init>(ProgressBar.java:226)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:650)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:723)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:791)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at com.test.myapp.ui.activity.base.BaseActivity.setContentView(BaseActivity.java:237)
at com.test.myapp.feature2.ui.activity.Feature2Activity.onCreate(Feature2Activity.java:123)
at android.app.Activity.performCreate(Activity.java:6980)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Class not found LinearLayout
at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:220)
at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:139)
at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1254)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:744)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:598)
at android.content.res.Resources.loadDrawable(Resources.java:885)
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
at android.widget.ProgressBar.<init>(ProgressBar.java:281)
at android.widget.ProgressBar.<init>(ProgressBar.java:230)
at android.widget.ProgressBar.<init>(ProgressBar.java:226)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:650)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:723)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:791)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at com.test.myapp.ui.activity.base.BaseActivity.setContentView(BaseActivity.java:237)
at com.test.myapp.feature2.ui.activity.Feature2Activity.onCreate(Feature2Activity.java:123)
at android.app.Activity.performCreate(Activity.java:6980)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
06-18 10:42:37.616 11607-11607/com.test.myapp.qa E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "LinearLayout" on path: DexPathList[[zip file "/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/base.apk", zip file "/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/split_feature2.apk", zip file "/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/split_feature1.apk"],nativeLibraryDirectories=[/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/lib/x86, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:201)
... 47
如果我们查看Feature2Activity
布局文件,则在第76行中将看到:
If we look at Feature2Activity
layout file, line 76 we'll see:
<ProgressBar
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="right"
android:indeterminateDrawable="@drawable/progress" />
Drawable progress.xml
位于feature2
资源中.如果我们将其删除,或将其更改为base
资源中的某些可绘制对象,则一切正常.
Drawable progress.xml
is located in feature2
resources. If we remove it, or change it to some drawable from base
resources, everything works fine.
这行是另一个奇怪的事情:
Another strange thing is this line:
Caused by: android.content.res.Resources$NotFoundException: Drawable com.test.myapp.qa:layout/random_feature1_layout with resource ID #0x82030011
布局random_feature1_layout
位于feature1
资源处,完全不应被引用.但是,如果我们转到feature2\R.java
文件,并查找progress.xml
drawable,则会发现:
Layout random_feature1_layout
is located at feature1
resources, and shouldn't be referenced at all. But if we go to feature2\R.java
file, and look for progress.xml
drawable we'll find:
public static final int progress=0x80030011;
如果仔细看,您会发现progress
和random_feature1_layout
的ID相差一个数字:0x80030011
和0x82030011
.因此,我做出了一个假设,即feature2
由于未知原因而在feature1
资源中寻找progress
可绘制对象.我试图删除feature1
依赖关系,然后崩溃消失了,这证实了我的假设.
And if you look closer you'll notice that progress
's and random_feature1_layout
's ids are differ by one digit: 0x80030011
and 0x82030011
. So I made an assumption, that feature2
for unknown reasons looks for progress
drawable in feature1
resources. I tried to remove feature1
dependency and crash disappeared, that confirms my assumption.
我还应该注意,仅Instant应用程序会出现此问题.已安装的应用程序运行正常.
I should also note that this issue is observed only for Instant app. Installed app works fine.
我的问题是feature2
如何在feature1
apk中搜索资源?您是否知道导致此行为的原因,或者暗示如何调试此问题?
My question is how is it possible that feature2
searches for resources in feature1
apk? Do you have any ideas what caused this behaviour or maybe hints how to debug this issue?
推荐答案
参考 Google问题跟踪器,已使用Android SDK内置工具修复为27.0.2
请将您的 Android SDK内置工具更新为27.0.2 并确保您使用的是 Android Studio 3.0.1或更高版本.
With reference to Google issue tracker, it has been fixed with Android SDK Built-Tools to 27.0.2
Please update your Android SDK Built-Tools to 27.0.2And ensure you are on Android Studio 3.0.1 or newer.
如果任何问题仍然存在,请在Google问题跟踪器中报告 ,他们将重新打开检查.谢谢!
If any issue persists, please report at Google issue tracker they will re-open to examine. Thanks!
这篇关于Instant App模块在另一个非基本模块中搜索资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!