Instant App module searches for resources in anoth

2019-02-18 16:26发布

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

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 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

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;

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.

I should also note that this issue is observed only for Instant app. Installed app works fine.

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?

1条回答
对你真心纯属浪费
2楼-- · 2019-02-18 16:32

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.2 And ensure you are on Android Studio 3.0.1 or newer.

If any issue persists, please report at Google issue tracker they will re-open to examine. Thanks!

查看更多
登录 后发表回答