0

I am getting Resources$NotFoundException much like this and this question.

The error is this -

Caused by android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f080166
   at android.content.res.ResourcesImpl.getResourceName + 267(ResourcesImpl.java:267)
   at android.content.res.ResourcesImpl.loadDrawableForCookie + 831(ResourcesImpl.java:831)
   at android.content.res.ResourcesImpl.loadDrawable + 677(ResourcesImpl.java:677)
   at android.content.res.Resources.loadDrawable + 912(Resources.java:912)
   at android.content.res.TypedArray.getDrawableForDensity + 955(TypedArray.java:955)
   at android.content.res.TypedArray.getDrawable + 930(TypedArray.java:930)
   at android.widget.TextView.(TextView.java:1317)
   at android.widget.TextView.(TextView.java:1112)
   at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:87)
   at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:83)
   at com.myapp.myapp.widgetstore.CustomTextView.(CustomTextView.java:24)
   at com.myapp.myapp.widgetstore.roboto.RobotoTextView.(RobotoTextView.java:40)
   at java.lang.reflect.Constructor.newInstance0(Constructor.java)
   at java.lang.reflect.Constructor.newInstance + 343(Constructor.java:343)
   at android.view.LayoutInflater.createView + 686(LayoutInflater.java:686)
   at android.view.LayoutInflater.createViewFromTag + 829(LayoutInflater.java:829)
   at android.view.LayoutInflater.createViewFromTag + 769(LayoutInflater.java:769)
   at android.view.LayoutInflater.rInflate + 902(LayoutInflater.java:902)
   at android.view.LayoutInflater.rInflateChildren + 863(LayoutInflater.java:863)
   at android.view.LayoutInflater.parseInclude + 1034(LayoutInflater.java:1034)
   at android.view.LayoutInflater.rInflate + 898(LayoutInflater.java:898)
   at android.view.LayoutInflater.rInflateChildren + 863(LayoutInflater.java:863)
   at android.view.LayoutInflater.rInflate + 905(LayoutInflater.java:905)
   at android.view.LayoutInflater.rInflateChildren + 863(LayoutInflater.java:863)
   at android.view.LayoutInflater.inflate + 554(LayoutInflater.java:554)
   at android.view.LayoutInflater.inflate + 461(LayoutInflater.java:461)
   at android.view.LayoutInflater.inflate + 383(LayoutInflater.java:383)
   at android.support.v7.app.AppCompatDelegateImpl.setContentView + 469(AppCompatDelegateImpl.java:469)
   at android.support.v7.app.AppCompatActivity.setContentView + 140(AppCompatActivity.java:140)
   at com.myapp.myapp.core.bottomnavigation.BottomNavigationBaseActivity.onCreate + 163(BottomNavigationBaseActivity.java:163)
   at android.app.Activity.performCreate + 7327(Activity.java:7327)
   at android.app.Activity.performCreate + 7318(Activity.java:7318)
   at android.app.Instrumentation.callActivityOnCreate + 1275(Instrumentation.java:1275)
   at android.app.ActivityThread.performLaunchActivity + 3101(ActivityThread.java:3101)
   at android.app.ActivityThread.handleLaunchActivity + 3264(ActivityThread.java:3264)
   at android.app.servertransaction.LaunchActivityItem.execute + 78(LaunchActivityItem.java:78)
   at android.app.servertransaction.TransactionExecutor.executeCallbacks + 108(TransactionExecutor.java:108)
   at android.app.servertransaction.TransactionExecutor.execute + 68(TransactionExecutor.java:68)
   at android.app.ActivityThread$H.handleMessage + 1955(ActivityThread.java:1955)
   at android.os.Handler.dispatchMessage + 106(Handler.java:106)
   at android.os.Looper.loop + 214(Looper.java:214)
   at android.app.ActivityThread.main + 7078(ActivityThread.java:7078)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 493(RuntimeInit.java:493)
   at com.android.internal.os.ZygoteInit.main + 964(ZygoteInit.java:964)

After following the discussions, I implemented the side-loading check but for some reason it wasn't enough because the first activity cannot inflate and throws InflateException. I created a work around and added a manual check in the catch block. Like this -

@Override
public void onCreate(Bundle savedInstanceState) {
    try{
        // the regular stuff
    } catch (Exception e){
        if(!isValidInstallation()){
            startInstallFromPlaystoreActivity();
        } else {
            throw e;
        }
    }
}

private boolean isValidInstallation(){
    boolean isValid = true;
    try {
        String installer = this.getPackageManager()
                .getInstallerPackageName(this.getPackageName());
        isValid = !TextUtils.isEmpty(installer);
    } catch (Throwable e) {
        isValid = false;
    }
    return isValid;
}

private void startInstallFromPlaystoreActivity(){
    startActivity(new Intent(this, InstallFromPlaystore.class));
}

This is what works right now but I am looking for something much cleaner. Why does Google's recommended way not solve my problem?

To test this out, I created a bundle and built apks with this spec -

{
   "supportedAbis": ["x86"],
   "supportedLocales": ["en-US"],
   "screenDensity": 50,
   "sdkVersion": 24
}

This is definitely causing my app to crash with the same error. Updating the screenDensity to the correct value according to the device no longer causes a crash.

If I play around with supportedLocales, I am able to trigger the Missing Split APK functionality that Google provides.

I also doubt that for lower screenDensity, the custom RobotoTextView that I have cannot access the correct resources for the ripple effect in the support library. Could that be the case?

Thanks

Aakash Choubey
  • 426
  • 3
  • 19
  • Are you using a vector drawable in a textview? – sanjeev Aug 01 '19 at 08:10
  • Nope. I don't think so. – Aakash Choubey Aug 01 '19 at 08:11
  • or any kind of drawables? cuz I had a similar issue when I used a drawable in a textview and got crash reports only in certain devices.. – sanjeev Aug 01 '19 at 08:12
  • I know for sure that the RobotoTextView using ripple from support library is where it breaks. Probably because of sideloading. – Aakash Choubey Aug 01 '19 at 08:16
  • Crashes are not specific to certain devices in my case – Aakash Choubey Aug 01 '19 at 08:17
  • So i assume it works properly during debugging? Anyway why are you using robototextview(library I assume?) when you can use fonts directly in AS? – sanjeev Aug 01 '19 at 08:22
  • The fact that providing a different screenDensity causes a crash is suspicious. You should file a bug, with reproducible steps, ideally a small project and app bundle that can reproduce the error would be very helpful. – Pierre Aug 01 '19 at 08:55
  • @Pierre I will try to. I was testing on pixel2 emulator and it works perfectly fine with screenDensities like 560, 620.. I intentionally set it to 50, and it wasn't caught by MissingSplitsManager. – Aakash Choubey Aug 01 '19 at 09:27
  • @AakashChoubey Yeah I can bet on that too.. seeing the number of active users I would suggest to go for an alternate solution for the feature that you may be using for that textview.. And yeah I am one among those 70k users :D – sanjeev Aug 01 '19 at 09:28
  • Even when setting density to 50, bundletool should select the split with the closest density split, which is why I'm surprised it crashes. – Pierre Aug 01 '19 at 15:32
  • @Pierre I unzipped the apks and there was a "base-ldpi.apk" there. That's probably why MissingSplitsManager couldn't catch the crash. – Aakash Choubey Aug 02 '19 at 05:33
  • Did you define this resource in the unqualified "drawable" directory by any chance? If so, could you try removing it and only declare it in the qualified directories, e.g. drawable-ldpi, drawable-mdpi, etc.? – Pierre Aug 02 '19 at 17:35

1 Answers1

0

After changing upload format. Did you set below values, specially density = true. We usually put every resources in all drawable-hdpi/xhdpi/xxhdpi variations. But if say there is one resource in only hdpi folder and you create an APK using App bundle. App bundle creates separate APKs for hdpi, xhdpi... which means in a xhdpi device it'll only use drawable-xhdpi folder's resources. So if you have a resource only in drawable-hdpi will not be available on xhdpi devices hence the crash.

bundle {
   language {
       enableSplit = true
   }
   density {
       enableSplit = true
   }
   abi {
       enableSplit = true
   }
}

Solution We have two solutions here One: Disable density split by setting it to false or ensure every resource is available in every drawable folders and also test on devices with different density. Same goes for ABI as well.

Bali
  • 749
  • 6
  • 19