nambicompany / expandable-fab

A highly customizable 'speed dial' FloatingActionButton implementation.
https://nambicompany.github.io/expandable-fab/
MIT License
200 stars 21 forks source link

Caused by android.content.res.Resources$NotFoundException #33

Closed kartik0198 closed 3 years ago

kartik0198 commented 3 years ago

Getting this crash on several devices. Using the latest library version. Please let me know if any further detail is needed.

Caused by android.content.res.Resources$NotFoundException Resource ID #0x7f070113 android.content.res.ResourcesImpl.getValueForDensity (ResourcesImpl.java:225) androidx.core.content.ContextCompat$Api21Impl.getDrawable (ContextCompat.java:862) com.nambimobile.widgets.efab.ExpandableFab.setOptionalProperties (ExpandableFab.java:480) androidx.core.content.ContextCompat.getDrawable (ContextCompat.java:480) com.nambimobile.widgets.efab.ExpandableFab. (ExpandableFab.java:73) java.lang.reflect.Constructor.newInstance0 (Constructor.java) android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:790)

kabumere commented 3 years ago

Hey @kartik0198,

1) Is this the full stack trace? If not, can you post the full stack trace? 2) Are you supporting different pixel densities with your icons/drawables for the ExpandableFab (res/drawable, res/drawable-xhdpi, etc)? 3) Are you supporting different screen sizes or orientations with your layouts (i.e. res/layout-large, res/layout-land, res/layout-w600dp, etc)? 4) Can I see how you're initializing your ExpandableFabLayout and its children (through XML or code)? Please use markdown for code blocks when posting it, so your code looks like this and is easier to read.

kartik0198 commented 3 years ago
  1. Here's the complete stack trace.
    
    Fatal Exception: android.view.InflateException
    Binary XML file line #158: Binary XML file line #36: Error inflating class com.nambimobile.widgets.efab.ExpandableFab

Caused by android.view.InflateException Binary XML file line #36: Error inflating class com.nambimobile.widgets.efab.ExpandableFab

Caused by java.lang.reflect.InvocationTargetException java.lang.reflect.Constructor.newInstance0 (Constructor.java) androidx.databinding.DataBindingUtil.inflate (DataBindingUtil.java:95) com.niyotail.consumer.ui.base.BaseFragment.onCreateView (BaseFragment.java:48) androidx.fragment.app.Fragment.performCreateView (Fragment.java:2963) androidx.appcompat.app.AppCompatActivity.onStart (AppCompatActivity.java:246) com.niyotail.consumer.ui.main.MainActivity.onStart (MainActivity.java:331) android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1391) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)

Caused by android.content.res.Resources$NotFoundException: Resource ID #0x7f070113 at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:225) at android.content.res.Resources.getDrawableForDensity(Resources.java:887) at android.content.res.Resources.getDrawable(Resources.java:827) at android.content.Context.getDrawable(Context.java:635) at androidx.core.content.ContextCompat$Api21Impl.getDrawable(ContextCompat.java:862) at com.nambimobile.widgets.efab.ExpandableFab.setOptionalProperties(ExpandableFab.java:480) at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:480) at com.nambimobile.widgets.efab.ExpandableFab.(ExpandableFab.java:73) at java.lang.reflect.Constructor.newInstance0(Constructor.java) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 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.parseInclude(LayoutInflater.java:995) at android.view.LayoutInflater.rInflate(LayoutInflater.java:859) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126) at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95) at com.niyotail.consumer.ui.base.BaseFragment.onCreateView(BaseFragment.java:48) at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282) at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1647) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3128) at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:3065) at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:2988) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:546) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282) at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1647) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3128) at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072) at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251) at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502) at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246) at com.niyotail.consumer.ui.main.MainActivity.onStart(MainActivity.java:331) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391) at android.app.Activity.performStart(Activity.java:7165) at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2975) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180) at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6718) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

2. Are you supporting different pixel densities with your icons/drawables for the ExpandableFab (res/drawable, res/drawable-xhdpi, etc)? No, we are not as we are using svg (vectors) for all drawables. 
3. Are you supporting different screen sizes or orientations with your layouts (i.e. res/layout-large, res/layout-land, res/layout-w600dp, etc)? No, we are not. 
4. Here's my XML file.

<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

</data>

<com.nambimobile.widgets.efab.ExpandableFabLayout
    android:id="@+id/fab_layout_support"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.nambimobile.widgets.efab.Overlay
        android:id="@+id/fab_overlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:overlay_closingAnimationDurationMs="0"
        app:overlay_openingAnimationDurationMs="0" />

    <com.nambimobile.widgets.efab.ExpandableFab
        android:id="@+id/fab_support"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginEnd="@dimen/space_lg"
        android:layout_marginBottom="42dp"
        app:efab_closingAnimationDurationMs="0"
        app:efab_color="@color/color_primary"
        app:efab_icon="@drawable/ic_support_button"
        app:efab_iconAnimationRotationDeg="0"
        app:efab_openingAnimationDurationMs="0"
        app:fab_color="@color/color_primary"
        app:label_backgroundColor="@color/color_primary"
        app:label_hiddenToVisibleAnimationDurationMs="0"
        app:label_visibleToHiddenAnimationDurationMs="0" />

    <com.nambimobile.widgets.efab.FabOption
        android:id="@+id/action_call"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fab_closingAnimationDurationMs="100"
        app:fab_color="@color/color_primary"
        app:fab_icon="@drawable/ic_call"
        app:fab_openingAnimationDurationMs="100"
        app:label_backgroundColor="@color/color_primary"
        app:label_hiddenToVisibleAnimationDurationMs="100"
        app:label_text="@string/call_support"
        app:label_visibleToHiddenAnimationDurationMs="100" />

    <com.nambimobile.widgets.efab.FabOption
        android:id="@+id/action_feedback"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fab_closingAnimationDurationMs="100"
        app:fab_color="@color/color_primary"
        app:fab_icon="@drawable/ic_thumbsup"
        app:fab_openingAnimationDurationMs="100"
        app:label_backgroundColor="@color/color_primary"
        app:label_hiddenToVisibleAnimationDurationMs="100"
        app:label_text="@string/feedback"
        app:label_visibleToHiddenAnimationDurationMs="100" />

    <com.nambimobile.widgets.efab.FabOption
        android:id="@+id/action_help"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fab_closingAnimationDurationMs="100"
        app:fab_color="@color/color_primary"
        app:fab_icon="@drawable/ic_support_person"
        app:fab_openingAnimationDurationMs="100"
        app:label_backgroundColor="@color/color_primary"
        app:label_hiddenToVisibleAnimationDurationMs="100"
        app:label_text="Get help"
        app:label_visibleToHiddenAnimationDurationMs="100" />

</com.nambimobile.widgets.efab.ExpandableFabLayout>

kabumere commented 3 years ago

Hey @kartik0198.

From my review of the stack trace, it looks to me that a drawable being used for the ExpandableFab icon:

So my next questions to you are: 1) I know I asked this previously, but are you sure that the ic_support_button drawable that you're setting for app:efab_icon is actually in res/drawable and not in a density-specific folder (like res/drawable-xhdpi, res/drawable-xxxhdpi, etc)? Can you double check? 1.a) Is ic_support_button an icon you created and you're 100% sure it's not in a density-specific folder, or is it a drawable you're accessing from a 3rd party library or framework? 2) The library defaults to setting ExpandableFab's icon to a drawable called ic_plus_white_24dp (a white plus sign) before trying to apply the drawable a developer sets in their own project. Is it possible that you also have a drawable called ic_plus_white_24dp that is in a density-specific folder (and may be overriding the drawable in the library)? 3) Are you sure you're using the latest version of the library (v1.1.1)? 4) EDIT: Can you post the XML for that ic_support_button vector image? 5) EDIT: Is this error occurring on any devices running at or above Android Lollipop (aka SDK 21 or SDK 22 or Android 5.0 or Android 5.1)? If it's only failing on devices running less than Lollipop, it may actually be a different issue. I see the potential fix, but I can't recreate the issue in an Emulator to be sure unfortunately...

I also wonder if either the library's default icon (ic_plus_white_24dp), or your icon (ic_support_button), is somehow not being loaded in time, or is missing from the APK the user has installed. Are you publishing your app to Google Play using the new App Bundle format (.aab instead of .apk)? If so, I wonder if it's being smarter than it should be and is not installing all the resources the user's device needs at install time (though this would hopefully be unlikely).

kabumere commented 3 years ago

Hey @kartik0198,

Any update?

kartik0198 commented 3 years ago
  1. Yes the drawable for app:efab_icon is in the drawable folder, not in density specific folder
  2. No I don’t have ic_plus_white_24dp file in my project
  3. Yes I am using latest 1.1.1 version
  4. 
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="23dp"
    android:height="24dp"
    android:viewportWidth="23"
    android:viewportHeight="24">
    <path
        android:fillColor="@color/white"
        android:pathData="M11.5 23.206c1.583 0 2.903-0.867 3.19-2.01h2.895c1.735 0 3.146-1.412 3.146-3.147v-0.253C22.017 17.574 23 16.458 23 15.11v-2.269c0-1.348-0.983-2.465-2.269-2.687V9.231C20.731 4.14 16.59 0 11.5 0S2.269 4.14 2.269 9.23v0.924C0.983 10.376 0 11.492 0 12.841v2.269c0 1.507 1.226 2.733 2.733 2.733 1.507 0 2.733-1.226 2.733-2.733v-2.269c0-1.348-0.983-2.465-2.269-2.687V9.231c0-4.578 3.725-8.303 8.303-8.303 4.578 0 8.303 3.725 8.303 8.303v0.923c-1.286 0.222-2.27 1.338-2.27 2.687v2.269c0 1.348 0.984 2.464 2.27 2.686v0.253c0 1.223-0.995 2.218-2.218 2.218H14.69c-0.286-1.144-1.606-2.011-3.19-2.011-1.79 0-3.248 1.11-3.248 2.475s1.457 2.475 3.249 2.475zM4.538 12.841v2.269c0 0.995-0.81 1.805-1.805 1.805-0.995 0-1.805-0.81-1.805-1.805v-2.269c0-0.995 0.81-1.805 1.805-1.805 0.995 0 1.805 0.81 1.805 1.805zm13.924 2.269v-2.269c0-0.995 0.81-1.805 1.805-1.805 0.995 0 1.805 0.81 1.805 1.805v2.269c0 0.995-0.81 1.805-1.805 1.805-0.995 0-1.805-0.81-1.805-1.805zM11.5 19.184c1.21 0 2.23 0.658 2.306 1.455-0.006 0.03-0.018 0.06-0.018 0.092 0 0.033 0.012 0.062 0.018 0.092-0.075 0.797-1.095 1.455-2.306 1.455-1.258 0-2.32-0.708-2.32-1.547s1.062-1.547 2.32-1.547z" />
    <path
        android:fillColor="@color/white"
        android:pathData="M6.637 9.504c-0.12 0.028-0.224 0.103-0.29 0.208-0.064 0.105-0.085 0.231-0.056 0.351 0.131 0.551 0.35 1.075 0.646 1.558 0.065 0.105 0.169 0.18 0.289 0.209 0.12 0.027 0.246 0.007 0.351-0.058C7.7 11.697 8.02 11.74 8.298 12.02c0.28 0.28 0.324 0.598 0.248 0.721-0.065 0.105-0.086 0.231-0.057 0.351 0.028 0.12 0.103 0.224 0.208 0.289 0.484 0.297 1.008 0.515 1.558 0.646 0.036 0.009 0.072 0.013 0.108 0.013 0.085 0 0.17-0.024 0.244-0.07 0.105-0.064 0.18-0.169 0.208-0.289 0.033-0.14 0.289-0.335 0.685-0.335 0.396 0 0.652 0.195 0.685 0.335 0.028 0.12 0.103 0.225 0.208 0.29 0.105 0.065 0.231 0.086 0.351 0.056 0.55-0.13 1.075-0.348 1.559-0.646 0.105-0.065 0.18-0.169 0.208-0.289 0.028-0.12 0.008-0.246-0.057-0.35-0.076-0.124-0.032-0.442 0.248-0.722 0.28-0.28 0.599-0.322 0.72-0.248 0.105 0.065 0.232 0.085 0.352 0.058 0.12-0.029 0.224-0.104 0.289-0.209 0.297-0.484 0.515-1.008 0.646-1.558 0.028-0.12 0.008-0.247-0.057-0.351-0.065-0.105-0.169-0.18-0.289-0.208-0.14-0.034-0.335-0.29-0.335-0.686 0-0.396 0.195-0.652 0.335-0.685 0.12-0.028 0.224-0.103 0.289-0.208 0.065-0.105 0.085-0.231 0.057-0.351-0.131-0.55-0.349-1.074-0.646-1.559-0.065-0.104-0.169-0.18-0.289-0.208-0.12-0.028-0.246-0.008-0.351 0.057C15.3 5.94 14.98 5.896 14.702 5.617c-0.28-0.28-0.324-0.599-0.248-0.721 0.065-0.105 0.085-0.232 0.057-0.352-0.028-0.12-0.103-0.223-0.208-0.288-0.484-0.298-1.009-0.516-1.559-0.646-0.12-0.029-0.246-0.009-0.351 0.056-0.105 0.065-0.18 0.17-0.208 0.29-0.033 0.14-0.29 0.334-0.685 0.334-0.396 0-0.652-0.194-0.685-0.335-0.028-0.12-0.103-0.224-0.208-0.289-0.105-0.065-0.233-0.085-0.352-0.056-0.55 0.13-1.074 0.348-1.558 0.646-0.105 0.065-0.18 0.168-0.208 0.288C8.46 4.664 8.48 4.791 8.546 4.896c0.076 0.122 0.032 0.44-0.248 0.72-0.28 0.28-0.598 0.324-0.72 0.248C7.471 5.8 7.345 5.778 7.225 5.807 7.106 5.835 7.002 5.91 6.937 6.015 6.64 6.5 6.423 7.023 6.291 7.573 6.262 7.693 6.283 7.82 6.348 7.925c0.064 0.105 0.168 0.18 0.289 0.208 0.14 0.033 0.335 0.29 0.335 0.685 0 0.396-0.195 0.652-0.335 0.686zM7.292 7.44c0.07-0.215 0.157-0.423 0.26-0.624 0.463 0.063 0.99-0.132 1.403-0.544C9.367 5.86 9.56 5.334 9.498 4.87c0.202-0.103 0.41-0.19 0.625-0.26 0.285 0.373 0.793 0.609 1.377 0.609s1.092-0.236 1.377-0.608c0.214 0.07 0.423 0.156 0.624 0.259-0.061 0.464 0.132 0.99 0.544 1.403 0.413 0.412 0.939 0.607 1.403 0.544 0.103 0.202 0.19 0.41 0.26 0.624C15.335 7.726 15.1 8.235 15.1 8.818c0 0.584 0.235 1.093 0.608 1.378-0.07 0.214-0.157 0.422-0.26 0.624-0.464-0.063-0.99 0.131-1.403 0.544-0.412 0.412-0.605 0.938-0.544 1.403-0.201 0.103-0.41 0.19-0.624 0.259-0.285-0.372-0.793-0.608-1.377-0.608s-1.092 0.236-1.377 0.608c-0.214-0.07-0.423-0.156-0.625-0.259 0.062-0.464-0.13-0.99-0.543-1.403-0.413-0.413-0.94-0.606-1.404-0.544-0.102-0.201-0.189-0.41-0.259-0.624C7.665 9.91 7.9 9.402 7.9 8.818c0-0.583-0.235-1.092-0.608-1.377z" />
    <path
        android:fillColor="@color/white"
        android:pathData="M11.5 11.504c1.481 0 2.686-1.204 2.686-2.686 0-1.48-1.205-2.685-2.686-2.685-1.481 0-2.686 1.204-2.686 2.685 0 1.482 1.205 2.686 2.686 2.686zm0-4.443c0.97 0 1.758 0.788 1.758 1.757 0 0.97-0.789 1.758-1.758 1.758-0.97 0-1.758-0.789-1.758-1.758S10.53 7.061 11.5 7.061z" />
    </vector>

5. It is crashing on Android version 8 and 9 as of now. Potentially nexus 5, Pixel 3 XL, Pixel 3a. nexus 5x
Yes we are using .aab format in google play store 
kabumere commented 3 years ago

EDIT:

TLDR: I have pushed a fix to master branch that will soon go into the next stable release on Maven Central. However, this fix is for a related issue on devices running Android SDK 20 and lower. I haven't been able to reproduce any such error on Android Oreo, Pie or above, so I'm not sure if it'll fix the similar issue that you're seeing on those user devices. If you know how to reproduce this on Oreo and above, please let me know.


So your vector drawable helped me reproduce a similar error which I fixed. This error should only occur on devices running SDK 20 or lower though, so I'm not sure if it'll fix the issue you're seeing occur on Android Oreo and Pie.

So my steps to reproduce:

  1. Create a drawable file using your ic_support_button vector paths.
  2. Set an ExpandableFab (or FabOption) icon to that ic_support_button vector drawable.
  3. Attempt to build.
  4. At this point, the build process will fail with an error similar to this:
    
    Caused by: java.lang.RuntimeException: Error while processing [redacted]\ExpandableFab\examples\src\main\res\drawable\test_resource.xml : Can't process attribute android:fillColor="@color/white": references to other resources are not supported by build-time PNG generation.
    File was preprocessed as vector drawable support was added in Android 5.0 (API level 21)
    See http://developer.android.com/tools/help/vector-asset-studio.html for details.
    ...

Caused by: org.gradle.api.GradleException: Can't process attribute android:fillColor="@color/white": references to other resources are not supported by build-time PNG generation. File was preprocessed as vector drawable support was added in Android 5.0 (API level 21) See http://developer.android.com/tools/help/vector-asset-studio.html for details. ...

The issue stems from attempting to reference one resource (`@color/white`) from inside another (`ic_support_button`). This [Stack Overflow answer](https://stackoverflow.com/a/53846109/14032472) says to add `vectorDrawables.useSupportLibrary = true` to your `defaultConfig` block in your build.gradle. I'm assuming you followed a similar solution and that's why you were able to build.

5. Now the app can build, even though we still reference a color resource from our vector drawable. However, setting `vectorDrawables.useSupportLibrary = true` now introduces a new bug on devices running Android Lollipop or lower:

android.content.res.Resources$NotFoundException: File res/drawable/ic_walk_white_24dp.xml from drawable resource ID #0x7f070080 ...

Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector ...


This error is directly caused by setting `vectorDrawables.useSupportLibrary = true` and only occurs on versions of Android that didn't have direct vector drawable support. To fix this, I updated the library to use `AppCompatResources.getDrawable` when attempting to load a vector drawable from resources, instead of the `ContextCompat.getDrawable` call I was using. This fixes this chain of errors.

Again though, this fix works for devices running SDK 20 and below. I haven't been able to reproduce this on Oreo (SDK 26 and 27) and above, but I will keep researching. If you know how to reproduce on those devices, please let me know. In the meantime you can update your version of the ExpandableFab library when I release it and see if it helps.
kabumere commented 3 years ago

Hey @kartik0198,

v1.2.0 of the library was just published. The bug I described above is fixed in this version. If you choose to use it, let me know if it solves the issue some of your users were experiencing. If it doesn't, I'd be glad to do further research into the problem.

kartik0198 commented 3 years ago

Thanks, I am releasing a new build with the updated library. Will let you know if there is a regression.

kartik0198 commented 3 years ago

Hi @kabumere , i am still getting this crash on the latest version i.e v1.2.1.

Caused by android.content.res.Resources$NotFoundException
Resource ID #0x7f07011a
android.content.res.ResourcesImpl.getValue (ResourcesImpl.java:190)
androidx.appcompat.content.res.AppCompatResources.getDrawable (AppCompatResources.java:104)
com.nambimobile.widgets.efab.ExpandableFab.<init> (ExpandableFab.java:76)
java.lang.reflect.Constructor.newInstance0 (Constructor.java)
androidx.databinding.DataBindingUtil.inflate (DataBindingUtil.java:95)
com.niyotail.consumer.ui.base.BaseFragment.onCreateView (BaseFragment.java:48)
androidx.fragment.app.Fragment.performCreateView (Fragment.java:2963)
androidx.appcompat.app.AppCompatActivity.onStart (AppCompatActivity.java:246)
com.niyotail.consumer.ui.main.MainActivity.onStart (MainActivity.java:331)
android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1248)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:780)

Crash stats: 75% crashes on - Android 9 13%- Android 7 12%- Android 8

kabumere commented 3 years ago

Hey @kartik0198,

Are you able to reproduce the crash on your end? If so, can you post the steps to reproduce? I can't reproduce that bug.

kartik0198 commented 3 years ago

Nope, i am not able to reproduce this crash but its crashing heavily, most frequent crash now in the latest version. :( also most of the crashes are in android 7

kabumere commented 3 years ago

From all your stack traces, the issue is occurring when trying to set an icon on the main ExpandableFab button (here specifically). We use to use ContextCompat instead of AppCompatResources, but even the old way still caused issues to some of your users.

I can't reproduce the crash, and it sounds like you can't reproduce the crash either. So without steps on how to reproduce it so I can solve it, we're kind of flying in the dark here at this point. I'm surprised you're getting the crash so frequently, as this seems like an edge case (since I haven't been hearing anyone else encounter this issue).

Is the crash happening frequently to the same users? Or is it happening frequently to unique users every time?

You could try giving me more data so I can try to more accurately mimic the environment your users are installing from, but I can't guarantee that it'll help without definitive steps to reproduce.

  1. What Android versions is this affecting (is only only Android 7, or is Android 7 the biggest share, but it's still happening to 8, 9, 10, etc)?
  2. What device models is this affecting (Samsung S series? Google Pixels? Huawei?)?
  3. What are the top user regions that are getting affected (US? India? South Korea?)?
  4. Do you know if your app is being sideloaded, instead of being installed directly from the Google Play Store?
    • this could create issues with resources, especially with the new app bundle format that Google uses to generate APKs specific to a user's device configuration
  5. Do you have something like vectorDrawables.useSupportLibrary = true defined in your build.gradle? Are there any other related properties you've added to your build.gradle?
kartik0198 commented 3 years ago

What Android versions is this affecting (is only only Android 7, or is Android 7 the biggest share, but it's still happening to 8, 9, 10, etc)? - Android 7 17% Android 9 3% Android 8

What device models is this affecting (Samsung S series? Google Pixels? Huawei?)? - 47% OnePlus 32% samsung 17% Google

What are the top user regions that are getting affected (US? India? South Korea?)? - users are from india only as the app is used in india only. Do you know if your app is being sideloaded, instead of being installed directly from the Google Play Store? - can't say, although i also think that this issue is being caused only when the app is sideloaded (its e-com app so people may/do sideload for referral benefits) this could create issues with resources, especially with the new app bundle format that Google uses to generate APKs specific to a user's device configuration Do you have something like vectorDrawables.useSupportLibrary = true defined in your build.gradle? Are there any other related properties you've added to your build.gradle? - no i dont have this property defined in my gradle

kabumere commented 3 years ago

@kartik0198,

That's surprising. When I try to use your ic_support_button drawable from above, I get the following error when building:

Caused by: org.gradle.api.GradleException: Can't process attribute android:fillColor="@color/white": references to other resources are not supported by build-time PNG generation.
File was preprocessed as vector drawable support was added in Android 5.0 (API level 21)
See http://developer.android.com/tools/help/vector-asset-studio.html for details.
    at com.android.build.gradle.tasks.MergeResources$MergeResourcesVectorDrawableRenderer.generateFile(MergeResources.java:440)
    at com.android.ide.common.resources.MergedResourceWriter$FileGenerationWorkAction.run(MergedResourceWriter.java:412)
    ... 31 more

It's because your vector drawable references other resources inside of it (e.g.: you use android:fillColor="@color/white" which references a color resource, instead of just using android:fillColor="#FFFFFF".

I have been following this Stack Overflow answer and including vectorDrawables.useSupportLibrary = true in my build.gradle in order to get the error to go away and build.

If you're not setting vectorDrawables.useSupportLibrary = true in your build.gradle though, how did you avoid that error? Or is your minSDK >= 24?

If your minSDK is less than 24, you should be getting this error too. Maybe the solution you used is leading to the issue and that's why I haven't been able to replicate it? Do you mind posting your build.gradle?

kartik0198 commented 3 years ago

That's strange, my minsdk is set at 21 but still i am not getting any gradle errors. In any case, i have changed the fill color to absolute value instead of referencing to a color resource (android:fillColor="#FFFFFF"). Here's my gradle file -

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'com.google.firebase.firebase-perf'

apply from: '../ktlint.gradle'

android {

    def versionMajor = 2
    def versionMinor = 5
    def versionPatch = 2
    def releaseNumber = 98
    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        applicationId "(hidden)"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 30000 + releaseNumber
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
        buildConfigField "int", "RELEASE_NUMBER", "$releaseNumber"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        debug {
            storeFile file('../keystore/debug.keystore')
            storePassword "(hidden)"
            keyAlias "(hidden)"
            keyPassword "(hidden)"
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
            debuggable true
            minifyEnabled false
            firebaseCrashlytics { mappingFileUploadEnabled false }
            buildConfigField "String", "API_ENDPOINT", "(hidden)"
            applicationIdSuffix ".d"
            versionNameSuffix "-d"
            resValue "string", "app_name", "(hidden)"
        }
        release {
            debuggable false
            minifyEnabled true
            firebaseCrashlytics { mappingFileUploadEnabled true }
            shrinkResources true
            buildConfigField "String", "API_ENDPOINT", "(hidden)"
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            resValue "string", "app_name", "(hidden)"
        }
    }

    android.applicationVariants.all { variant ->
        variant.outputs.all { output ->
            outputFileName = "(hidden)-v${variant.versionName}(${variant.versionCode})-${variant.buildType.name}.apk"
        }
    }

    buildTypes.each {
        it.buildConfigField "String", "MIXPANEL_API_KEY", mixpanelApiKey
    }

    compileOptions {
        sourceCompatibility rootProject.ext.javaVersion
        targetCompatibility rootProject.ext.javaVersion
    }

    kotlinOptions {
        jvmTarget = rootProject.ext.javaVersion.toString()
    }

    buildFeatures {
        dataBinding true
    }

    bundle {
        language {
            /* Specifies that the app bundle should not support configuration APKs for language resources. These
               resources are instead packaged with each base and dynamic feature APK. */
            enableSplit = false
        }
    }
}

dependencies {
    //implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    /* PLEASE KEEP THE DEPENDENCIES BLOCK CLEAN BY ADDING NEW LIBRARIES AS PER THE CATEGORY ONLY !! */

    def retrofit_version = '2.9.0'
    def room_version = "2.3.0"

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    //Modules
    implementation project(path: ':analytics')
    implementation project(path: ':barcode')
    implementation project(path: ':core')
    implementation project(path: ':commons:utils')
    implementation project(path: ':commons:ui')
    implementation project(path: ':commons:views')

    //Kotlin
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.5.2-native-mt'

    //AndroidX
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'androidx.activity:activity-ktx:1.4.0'
    implementation "androidx.fragment:fragment-ktx:1.3.6"
    implementation "androidx.recyclerview:recyclerview:1.2.1"

    //Jetpack Components
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.0"
    implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
    implementation "androidx.navigation:navigation-ui-ktx:2.3.5"
    implementation "androidx.paging:paging-runtime-ktx:3.0.1"
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"
    implementation "androidx.room:room-ktx:$room_version"

    //Firebase
    implementation platform('com.google.firebase:firebase-bom:28.4.2')
    implementation 'com.google.firebase:firebase-config-ktx'
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    implementation 'com.google.firebase:firebase-messaging-ktx'
    implementation 'com.google.firebase:firebase-appindexing'
    implementation 'com.google.firebase:firebase-inappmessaging-display-ktx'
    implementation 'com.google.firebase:firebase-firestore-ktx'
    implementation 'com.google.firebase:firebase-perf-ktx'
    implementation 'com.google.firebase:firebase-storage-ktx'
    implementation("com.google.firebase:firebase-iid") { because("github.com/mixpanel/mixpanel-android/issues/744") }

    //Google play services
    implementation 'com.google.android.play:core-ktx:1.8.1'
    implementation "com.google.android.gms:play-services-maps:18.0.0"
    implementation "com.google.android.gms:play-services-location:18.0.0"
    implementation 'com.google.android.gms:play-services-auth:19.2.0'
    implementation 'com.google.android.gms:play-services-auth-api-phone:17.5.1'
    implementation 'com.google.android.gms:play-services-ads-identifier:17.1.0'
    implementation 'com.android.installreferrer:installreferrer:2.2'

    //Testing
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    //Networking
    implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.1"))
    implementation("com.squareup.okhttp3:okhttp")
    implementation("com.squareup.okhttp3:logging-interceptor")
    implementation "com.squareup.retrofit2:retrofit:${retrofit_version}"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

    //Debugging
    implementation 'com.facebook.stetho:stetho:1.6.0'
    implementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
    implementation 'com.jakewharton.timber:timber:5.0.1'
    // debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
    debugImplementation 'com.mocklets:pluto:1.1.1'
    releaseImplementation 'com.mocklets:pluto-no-op:1.1.1'

    //Payments
    implementation 'com.razorpay:checkout:1.6.12'

    //UI
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'com.facebook.shimmer:shimmer:0.5.0'
    implementation 'com.airbnb.android:lottie:4.2.0'
    implementation 'com.github.GrenderG:Toasty:1.5.0'
    implementation 'com.github.cachapa:ExpandableLayout:2.9.2'
    implementation 'com.robinhood.ticker:ticker:2.0.3'
    implementation 'com.nambimobile.widgets:expandable-fab:1.2.1'
    implementation 'com.github.Jamshid-M:IGRefreshLayout:1.0.3'

    //Custom
    implementation 'com.github.skydoves:preferenceroom:1.2.2'
    kapt 'com.github.skydoves:preferenceroom-processor:1.2.2'
    implementation 'io.branch.sdk.android:library:5.0.14'
    implementation 'io.coil-kt:coil:1.3.2'
    implementation("io.coil-kt:coil-gif:1.3.2")
    implementation "com.truecaller.android.sdk:truecaller-sdk:2.6.0"
    implementation 'com.webengage:android-sdk:3.18.7'

    //Dagger-Hilt
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-compiler:$hilt_version"

}
apply plugin: 'com.google.gms.google-services'

check.dependsOn ktlint
kabumere commented 3 years ago

@kartik0198,

There's nothing in your build.gradle that jumps out at me as being suspect. At this point, I'm not sure there's anything else I can do. You can't reproduce the issue, and neither can I.

I just built signed release versions of a proguarded test app that included the library, and tested on Android 19 and 21 (emulator), and Androids 28, 29 and 30 (physical devices), and it worked without issue every time.

My final suspicions on this are:

  1. Some of your users are sideloading your app, and the particular APK configuration they're downloading is not meant for their specific device and it's causing issues. I believe this is especially an issue when publishing using App Bundles, since Google uses that bundle info to provide users with an APK specific to their general device configuration.
    • Example: if User 'A' downloads a specific APK configuration for their device from the Play Store, then that APK ends up on a sideloading website, User 'B' might encounter issues when installing it since their device may not fully support that APK configuration.
  2. If you're using Android Studio 3.0 or higher, Android Gradle plugin 3.0 or higher, and have a minSDK of less than 24, you should have had to include vectorDrawables.useSupportLibrary = true when using drawables that referenced other resources like colors. Some how you got around that without seeing an error when you were testing, but perhaps that led to a deeper problem with your vector drawables? You can try removing all references to resources from all your drawables and see if that helps.

Other than that, I'm out of ideas. Sorry this issue couldn't be resolved :slightly_frowning_face:

EDIT: Some Stack Overflow posts that support my suspicion with number 1 above: https://stackoverflow.com/q/52469914/14032472 https://stackoverflow.com/a/52474885/14032472 https://stackoverflow.com/a/59514472/14032472 https://stackoverflow.com/q/65167556/14032472

kartik0198 commented 3 years ago

Yes, I have worked on point 2. Hoping that it fixes the issue although I also think some users who have side-loaded the apk are affected and they might be trying again and again to open the app. Anyway, thanks a lot for your help!

kabumere commented 3 years ago

No problem @kartik0198! Keep me posted if you find out any more information about those crashes or you become able to reproduce them, and we can revisit and reopen this ticket for further testing.