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