Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drawable files are not accessible in Android 11. adding support for android 11? #12

Open
chlegou opened this issue Jun 13, 2020 · 8 comments
Assignees

Comments

@chlegou
Copy link

chlegou commented Jun 13, 2020

Hi there, when deploying my app to production, i have seen this error in crashlytics happening to a user having an Android 11 Pixel 4 XL device. here is the error exception:

Caused by android.content.res.Resources$NotFoundException: File res/drawable/dark_theme_google_icon_selector.xml from drawable resource ID #0x7f080082
   at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:876)
   at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:659)
   at android.content.res.Resources.getDrawableForDensity(Resources.java:906)
   at android.content.res.Resources.getDrawable(Resources.java:845)
   at android.content.Context.getDrawable(Context.java:687)
   at android.view.View.setBackgroundResource(View.java:22717)
   at androidx.appcompat.widget.AppCompatButton.setBackgroundResource(AppCompatButton.java:84)
   at com.shobhitpuri.custombuttons.GoogleSignInButton.setButtonBackground(GoogleSignInButton.java:160)
   at com.shobhitpuri.custombuttons.GoogleSignInButton.setButtonParams(GoogleSignInButton.java:143)
   at com.shobhitpuri.custombuttons.GoogleSignInButton.init(GoogleSignInButton.java:100)
   at com.shobhitpuri.custombuttons.GoogleSignInButton.<init>(GoogleSignInButton.java:77)
   at java.lang.reflect.Constructor.newInstance0(Constructor.java)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
   at android.view.LayoutInflater.createView(LayoutInflater.java:854)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
   at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
   at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
   at com.chlegou.bitbot.activity.MainActivity.onCreate(MainActivity.java:92)
   at android.app.Activity.performCreate(Activity.java:7802)
   at android.app.Activity.performCreate(Activity.java:7791)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
   at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
   at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
   at android.os.Handler.dispatchMessage(Handler.java:107)
   at android.os.Looper.loop(Looper.java:214)
   at android.app.ActivityThread.main(ActivityThread.java:7356)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Please add support for Android 11 devices.

Thanks.

@shobhitpuri shobhitpuri self-assigned this Jun 13, 2020
@shobhitpuri
Copy link
Owner

shobhitpuri commented Jun 13, 2020

@chlegou Thanks for opening the issue. I tried to reproduce it using Android R simulator, Android Studio 4.0, latest Build Tools etc but couldn't reproduce it. Here was my configuration for the sample app code that is included in the master branch:

Project Level build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

App level build.gradle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"
    defaultConfig {
        applicationId "com.shobhitpuri.googlecustomsigninbutton"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    // Uncomment this if you want to use the released sign-in library.
    implementation 'com.shobhitpuri.custombuttons:google-signin:1.1.0'

    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
}

1- Can you include the top level build file and the app level build file for your project?
2- Please add the XML of your GoogleSignInButton.
3- Also can you try running the sample project with your build file configuration on Android 11 and see if it crashes? Use bugs/android-11-drawable-crash branch. https://github.com/shobhitpuri/custom-google-signin-button/tree/bugs/android-11-drawable-crash

@chlegou
Copy link
Author

chlegou commented Jun 14, 2020

for me, it's working fine, it didn't happened for me (having android 7).
Following the issue with the user getting the error, reinstalling the app solved the issue for him.
so i believe it's a bug in installing the app.

@shobhitpuri
Copy link
Owner

Thanks for the update @chlegou. Glad it worked out fine. Let me know if you see any other issue around it or the frequency of the error changes. For the time being I'm closing the issue. Feel free to reopen if it persists

@chlegou
Copy link
Author

chlegou commented Jun 19, 2020

following this issue further, i have noticed other crashes:

This issue has 8 crashes affecting 5 users
devices: android 9, 8.1.0, 5.1

I'm now 100% sure that it's not related to Android 11 (being in Beta currently, made me think it's related to it when noticing the first crash report).

After peeking your source code, it's related to this:

i recommend using:

// needs a check that the drawable isn't null, otherwise having the image as default in xml
this.setBackgroundDrawable(ContextCompat.getDrawable(getContext(), googleIconImageSelector));

this is part of the the crash report, hopefully might helps you to improve it better:

........

Caused by java.lang.reflect.InvocationTargetException
	   at java.lang.reflect.Constructor.newInstance0(Constructor.java)
	   at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
	   at android.view.LayoutInflater.createView(LayoutInflater.java:647)
	   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
	   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
	   at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
	   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
	   at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)

........

Caused by android.content.res.Resources$NotFoundException: File res/drawable/dark_theme_google_icon_selector.xml from drawable resource ID #0x7f080082
	   at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:820)
	   at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:630)
	   at android.content.res.Resources.getDrawableForDensity(Resources.java:877)
	   at android.content.res.XResources.getDrawableForDensity(XResources.java:868)
	   at android.content.res.Resources.getDrawable(Resources.java:819)
	   at android.content.res.XResources.getDrawable(XResources.java:790)
	   at android.content.Context.getDrawable(Context.java:605)
	   at android.view.View.setBackgroundResource(View.java:20376)
	   at androidx.appcompat.widget.AppCompatButton.setBackgroundResource(AppCompatButton.java:84)
	   at com.shobhitpuri.custombuttons.GoogleSignInButton.setButtonBackground(GoogleSignInButton.java:160)
	   at com.shobhitpuri.custombuttons.GoogleSignInButton.setButtonParams(GoogleSignInButton.java:143)
	   at com.shobhitpuri.custombuttons.GoogleSignInButton.init(GoogleSignInButton.java:100)
	   at com.shobhitpuri.custombuttons.GoogleSignInButton.<init>(GoogleSignInButton.java:77)
	   at java.lang.reflect.Constructor.newInstance0(Constructor.java)
	   at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
	   at android.view.LayoutInflater.createView(LayoutInflater.java:647)
	   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
	   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
	   at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)


........

Caused by android.content.res.Resources$NotFoundException: Drawable (missing name) with resource ID #0x7f080063

........

Caused by android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f080063
	   at android.content.res.ResourcesImpl.getResourceName(ResourcesImpl.java:253)
	   at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:760)
	   at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:630)
	   at android.content.res.Resources.loadDrawable(Resources.java:886)
	   at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
	   at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
	   at android.content.res.XResources$XTypedArray.getDrawable(XResources.java:1363)
	   at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:177)
	   at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:122)
	   at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
	   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:807)
	   at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:630)
	   at android.content.res.Resources.getDrawableForDensity(Resources.java:877)
	   at android.content.res.XResources.getDrawableForDensity(XResources.java:868)
	   at android.content.res.Resources.getDrawable(Resources.java:819)
	   at android.content.res.XResources.getDrawable(XResources.java:790)
	   at android.content.Context.getDrawable(Context.java:605)
	   at android.view.View.setBackgroundResource(View.java:20376)
	   at androidx.appcompat.widget.AppCompatButton.setBackgroundResource(AppCompatButton.java:84)
	   at com.shobhitpuri.custombuttons.GoogleSignInButton.setButtonBackground(GoogleSignInButton.java:160)
	   at com.shobhitpuri.custombuttons.GoogleSignInButton.setButtonParams(GoogleSignInButton.java:143)
	   at com.shobhitpuri.custombuttons.GoogleSignInButton.init(GoogleSignInButton.java:100)
	   at com.shobhitpuri.custombuttons.GoogleSignInButton.<init>(GoogleSignInButton.java:77)
	   at java.lang.reflect.Constructor.newInstance0(Constructor.java)
	   at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
	   at android.view.LayoutInflater.createView(LayoutInflater.java:647)
	   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
	   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
	   at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
	   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)

...........

@shobhitpuri shobhitpuri reopened this Jun 20, 2020
@shobhitpuri
Copy link
Owner

Thanks @chlegou. I've reopened it for further investigation. Can you please add the XML where you are adding <com.shobhitpuri.custombuttons.GoogleSignInButton? And if you are manipulating it programmatically, please attach that code too. Thanks!

@chlegou
Copy link
Author

chlegou commented Jun 21, 2020

Well, i believe it has nothing to do with it. but here it is anyway:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:app="http://schemas.android.com/apk/res-auto"
	xmlns:tools="http://schemas.android.com/tools"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:background="@color/grey_50"
	tools:context=".activity.MainActivity">

	...........

	<androidx.coordinatorlayout.widget.CoordinatorLayout
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_above="@+id/footer"
		android:layout_below="@+id/header">

		<androidx.appcompat.widget.LinearLayoutCompat
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:layout_marginBottom="60dp"
			android:orientation="vertical"
			app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

			<androidx.core.widget.NestedScrollView
				android:layout_width="match_parent"
				android:layout_height="match_parent"
				android:clipToPadding="false"
				android:scrollbars="none"
				android:scrollingCache="true">

				<androidx.appcompat.widget.LinearLayoutCompat
					android:layout_width="match_parent"
					android:layout_height="match_parent"
					android:orientation="vertical"
					tools:context=".activity.MainActivity">

					................

					<androidx.appcompat.widget.LinearLayoutCompat
						android:id="@+id/layout_sign_in"
						android:layout_width="match_parent"
						android:layout_height="wrap_content"
						android:background="@color/blue_50"
						android:gravity="center"
						android:orientation="vertical"
						android:padding="@dimen/spacing_large">

						<androidx.appcompat.widget.AppCompatTextView
							android:layout_width="wrap_content"
							android:layout_height="wrap_content"
							android:text="@string/message_login"
							android:textAppearance="@style/TextAppearance.AppCompat.Title"
							android:textIsSelectable="true" />

						<com.shobhitpuri.custombuttons.GoogleSignInButton
							android:id="@+id/btn_sign_in"
							android:layout_width="wrap_content"
							android:layout_height="wrap_content"
							android:layout_centerInParent="true"
							android:layout_marginTop="12dp"
							android:text="@string/common_signin_button_text_long"
							app:isDarkTheme="true" />

					</androidx.appcompat.widget.LinearLayoutCompat>
					
					..........
					
				</androidx.appcompat.widget.LinearLayoutCompat>
			</androidx.core.widget.NestedScrollView>
		</androidx.appcompat.widget.LinearLayoutCompat>
	</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>

Also, following the vector drawables errors further, i finally get this solution that is working reliably good so far after 3 days of annoying drawables crashes: (instead of the above solution i have mentioned earlier)

setting an image resource in XML layout file as a placeholder. then fetching the vector drawable using this method:

/**
 * This is a support method for API < 21 vector drawables.
 */
@Nullable
public static Drawable getVectorDrawable(int resId) {
    Drawable drawable = null;
    try {
        drawable = AppCompatResources.getDrawable(MainApp.getInstance().getApplicationContext(), resId);
    } catch (Exception ignored) {
    }
    return drawable;
}

if the drawable fetched by this method isn't null, i apply it from java. otherwise, it's the default placeholder affected from the xml layout which is image drawable not vector drawable.

This workaround is preventing app crashes so far.

@shobhitpuri
Copy link
Owner

shobhitpuri commented Jun 22, 2020 via email

@indra452
Copy link

Hi im also facing this issue... Can someone help me ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants