xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

[Bug] Android issue java.lang.NoClassDefFoundError #8301

Open wojciech-kulik opened 4 years ago

wojciech-kulik commented 4 years ago

Description

Hi, my Xamarin.Forms application is crashing on some Android devices. I have found some posts about similar issue in native development. The solution is to change in gradle ResolutionStrategy, however I don't know how to apply this fix to Xamarin development.

Here is possible fix: https://stackoverflow.com/questions/53161063/viewcompatonunhandledkeyeventlistener-on-setcontentview

Steps to Reproduce

Just run the application and on some devices it crashes with the following logs:

10-29 18:31:03.794: I/zygote64(15441): Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
10-29 18:31:03.794: I/zygote64(15441):   at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (:-1)
10-29 18:31:03.794: I/zygote64(15441):   at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (:-1)
10-29 18:31:03.794: I/zygote64(15441):   at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (:-1)
10-29 18:31:03.794: I/zygote64(15441):   at void android.support.v7.app.AppCompatDelegateImpl.initWindowDecorActionBar() (:-1)
10-29 18:31:03.794: I/zygote64(15441):   at android.support.v7.app.ActionBar android.support.v7.app.AppCompatDelegateImpl.getSupportActionBar() (:-1)
10-29 18:31:03.794: I/zygote64(15441):   at void android.support.v7.app.AppCompatDelegateImpl.setSupportActionBar(android.support.v7.widget.Toolbar) (:-1)
10-29 18:31:03.794: I/zygote64(15441):   at void android.support.v7.app.AppCompatActivity.setSupportActionBar(android.support.v7.widget.Toolbar) (:-1)
10-29 18:31:03.794: I/zygote64(15441):   at void md536637be26cc67c3c700931937b0a7da2.MainActivity.n_onCreate(android.os.Bundle) (:-2)
10-29 18:31:03.794: I/zygote64(15441):   at void md536637be26cc67c3c700931937b0a7da2.MainActivity.onCreate(android.os.Bundle) (:-1)
10-29 18:31:03.794: I/zygote64(15441):   at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6975)
10-29 18:31:03.794: I/zygote64(15441):   at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1213)
10-29 18:31:03.794: I/zygote64(15441):   at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2779)
10-29 18:31:03.794: I/zygote64(15441):   at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2904)
10-29 18:31:03.794: I/zygote64(15441):   at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
10-29 18:31:03.794: I/zygote64(15441):   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1596)
10-29 18:31:03.794: I/zygote64(15441):   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105)
10-29 18:31:03.794: I/zygote64(15441):   at void android.os.Looper.loop() (Looper.java:164)
10-29 18:31:03.794: I/zygote64(15441):   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6600)
10-29 18:31:03.794: I/zygote64(15441):   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
10-29 18:31:03.794: I/zygote64(15441):   at void com.android.internal.os.Zygote$MethodAndArgsCaller.run() (Zygote.java:240)
10-29 18:31:03.794: I/zygote64(15441):   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:772)

Packages that I use:

<ItemGroup>
    <Reference Include="Mono.Android" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="PropertyChanged.Fody" Version="3.1.3" PrivateAssets="all" />
    <PackageReference Include="Prism.DryIoc.Forms" Version="7.0.0.396" />
    <PackageReference Include="Crashlytics">
      <Version>1.5.0</Version>
    </PackageReference>
    <PackageReference Include="Fabric">
      <Version>1.5.0</Version>
    </PackageReference>
    <PackageReference Include="Plugin.StoreReview">
      <Version>2.0.0.5</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Analytics">
      <Version>71.1630.0</Version>
    </PackageReference>
    <PackageReference Include="Xam.Plugin.Geolocator">
      <Version>4.5.0.6</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Messaging">
      <Version>71.1740.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms">
      <Version>4.2.0.848062</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms.Maps">
      <Version>4.2.0.848062</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Analytics">
      <Version>71.1608.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Basement">
      <Version>71.1620.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Maps">
      <Version>71.1610.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Tasks">
      <Version>71.1601.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Common">
      <Version>71.1610.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Base">
      <Version>71.1610.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Iid">
      <Version>71.1710.0</Version>
    </PackageReference>
  </ItemGroup>

Expected Behavior

Application should work properly on all supported Android devices.

Actual Behavior

It causes crash on some Android devices.

Basic Information

hartez commented 4 years ago

It causes crash on some Android devices.

Do you know the device models/APIs it's crashing on?

hartez commented 4 years ago

Possibly related: https://issuetracker.google.com/issues/120750246 and https://issuetracker.google.com/issues/142771874

wojciech-kulik commented 4 years ago

I observed it on Pixel 2 (API 26) when running robo test using Firebase Test Lab + it happens on my friend's phone Galaxy S8 (API 28).

In the meantime, I've also tried all combinations of build settings like linking, dex, shrinker etc.

I'm not sure if it's relevant, but the stack trace I attached refers to android.support.v4.view.ViewCompat, however when I unzip apk in assemblies directory there is no v4 assembly, only v7.

I also tried to disable linker and code shrinking and added android.support.v4 as nuget package it appeared in assemblies directory, however it did not help either.

I've just created on my machine emulator Pixel 2 (API 26) and it prints out the same stack trace, however, the application starts properly.

hartez commented 4 years ago

Nuget Packages: 4.2.0.848062

@wojciech-kulik Do you still see this error if you update to Forms 4.3.0? 4.3.0 uses a slightly later version of the support packages.

wojciech-kulik commented 4 years ago

@hartez I tried 4.3.0.991211 but the issue still occurs.

PureWeen commented 4 years ago

@wojciech-kulik do you have multi dex enabled for release builds?

What is your setup for release builds? MultiDex? ProGuard? D8? R8?

If you're using MultiDexing can you try to just use ProGuard and see if that fixes?

image

wojciech-kulik commented 4 years ago
Screenshot 2019-12-11 at 22 15 56
rmarinho commented 4 years ago

Follow up on #8382

wojciech-kulik commented 4 years ago

@rmarinho why it's closed? This issue still occurs, it doesn't cause crash, but it still occurs.

ivmirx commented 4 years ago

It still happens but I don't use Forms, so it's probably a general Xamarin issue on top of this Android issue.

Seems pretty harmless and should be fixed in the latest AndroidX versions.