Xamarin.Forms Android application crash on release with linking

Created on 7 Feb 2019  路  13Comments  路  Source: xamarin/Xamarin.Forms

Description

Android Application crash on release mode when using linking or Use shared runtime is unchecked if Xamarin.Forms version is greater than 3.1.0.583944

Edit: I've enable ProGuard, unchecked shared runtime and set Linking to "Sdk Assemblies Only" on Debug configuration now app crashed on base.OnCreate(savedInstanceState); where savedInstanceState is null with error message Unhandled Exception: Java.Lang.RuntimeException: Binary XML file line #20: Binary XML file line #20: Error inflating class android.support.v7.widget.FitWindowsFrameLayout

Steps to Reproduce

  1. Create New Xamarin Forms MasterView project
  2. Set it to Release mode
  3. Uncheck "Use shared monoruntime"
  4. Check "Enable ProGuard"
  5. Set Linking to "Sdk Assemblies Only"

Expected Behavior

Application should not crash

Actual Behavior

Application crash on Splash screen on release mode with these warning
Severity Code Description Project File Line Suppression State Warning Failed to read 'C:\Users\defaultuser\source\repos\Temp\Temp\Temp.Android\obj\Release\90\linksrc\FormsViewGroup.dll' with debugging symbols. Retrying to load it without it. Error details are logged below. 0

Severity Code Description Project File Line Suppression State Warning Failed to read 'C:\Users\defaultuser\source\repos\Temp\Temp\Temp.Android\obj\Release\90\android\assets\FormsViewGroup.dll' with debugging symbols. Retrying to load it without it. Error details are logged below. 0

Severity Code Description Project File Line Suppression State Warning Failed to read 'C:\Users\defaultuser\source\repos\Temp\Temp\Temp.Android\obj\Release\90\android\assets\Xamarin.Forms.Platform.Android.dll' with debugging symbols. Retrying to load it without it. Error details are logged below. 0

Severity Code Description Project File Line Suppression State Warning Mono.Cecil.Cil.SymbolsNotMatchingException: Symbols were found but are not matching the assembly at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader, Boolean throwIfSymbolsAreNotMaching) at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters) at Mono.Cecil.ModuleReader.CreateModule(Image image, ReaderParameters parameters) at Mono.Cecil.ModuleDefinition.ReadModule(Disposable1 stream, String fileName, ReaderParameters parameters) at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName, ReaderParameters parameters) at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.ReadAssembly(String file) 0

Severity Code Description Project File Line Suppression State Warning Failed to read 'C:\Users\defaultuser\source\repos\Temp\Temp\Temp.Android\obj\Release\90\linksrc\Xamarin.Forms.Platform.Android.dll' with debugging symbols. Retrying to load it without it. Error details are logged below. 0

Basic Information

  • Version with issue: > 3.1.0.583944
  • Last known good version: 3.1.0.583944
  • IDE: Visual Studio 15.9.6
  • Platform Target Frameworks:

    • iOS: Project not included

    • Android: Tried 8.1 and 9.0

    • UWP: Project not included

  • Android Support Library Version: 28.0.0.1
  • Nuget Packages:

    • Xamarin.Android.Support.CustomTabs (28.0.0.1)
    • Xamarin.Android.Support.v7.AppCompat (28.0.0.1)
    • Xamarin.Android.Support.v7.CardView (28.0.0.1)
    • Xamarin.Android.Support.v4 (28.0.0.1)
    • Xamarin.Android.Support.Design (28.0.0.1)
    • Xamarin.Android.Support.v7.MediaRouter (28.0.0.1)
    • Xaramin.Forms (3.5.0.129452)
    • NETStandard.Library (2.0.3)
  • Affected Devices: All

4 help wanted high inactive Android bug up-for-grabs

Most helpful comment

@iswahyudhie Yes, just follow one of these Method

Method 1

  1. Download proguard configuration file form this link
  2. Include this file in Android Project (Simply drag and drop on android project)
  3. Select ProGuard.cfg file and change its Build Action to ProguardConfiguration
  4. Clean your solution (important) then build it.

Method 2

  1. Create new file Proguard.cfg with notepad or any text editor just don't create it with Visual Studio, make sure its encoding is just UTF-8 not anything else. (Important)
  2. paste this in Proguard.cfg
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**

-keep class android.support.v7.widget.** { *; }
-dontwarn android.support.v7.widget.**
-keep class android.support.v4.widget.Space { *; }
-dontwarn android.support.v4.widget.Space
  1. Include this file in Android Project (Simply drag and drop on android project)
  2. Select ProGuard.cfg file and change its Build Action to ProguardConfiguration
  3. Clean your solution (important) then build it.

Note: If you get java.exe exited with code 1 then your ProGuard.cfg file is not UTF-8 or your forget to change its Build Action to ProguardConfiguration

All 13 comments

I face this issue, any workaround yet?

@iswahyudhie Yes, just follow one of these Method

Method 1

  1. Download proguard configuration file form this link
  2. Include this file in Android Project (Simply drag and drop on android project)
  3. Select ProGuard.cfg file and change its Build Action to ProguardConfiguration
  4. Clean your solution (important) then build it.

Method 2

  1. Create new file Proguard.cfg with notepad or any text editor just don't create it with Visual Studio, make sure its encoding is just UTF-8 not anything else. (Important)
  2. paste this in Proguard.cfg
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**

-keep class android.support.v7.widget.** { *; }
-dontwarn android.support.v7.widget.**
-keep class android.support.v4.widget.Space { *; }
-dontwarn android.support.v4.widget.Space
  1. Include this file in Android Project (Simply drag and drop on android project)
  2. Select ProGuard.cfg file and change its Build Action to ProguardConfiguration
  3. Clean your solution (important) then build it.

Note: If you get java.exe exited with code 1 then your ProGuard.cfg file is not UTF-8 or your forget to change its Build Action to ProguardConfiguration

hi Uzairali,
thanks for your reply,
unfortunately, your workaround does not work in my project, I realize even without pro guard checked this issue still occurs. only work if I set the linking to none but the warning still appears. at least the app can run normally. maybe in my case, it's not related with proguard enable.

@iswahyudhie As far as I know this issue is related to Linking. Proguard is just a configuration file for linking, it tells linker what not to skip so in your case you must be using some plugins which linker is striping. Try this maybe it might solve your problem

  1. Go to Tools > Options, select Xamarin from left panel and set Xamarin Diagnostics output verbosity to Detailed
  2. Switch to Debug mode, Open Android project's property
  3. Goto Android Options and make sure Debug configuration is selected, then disable Use Shared Runtime, enable Enable ProGuard and set linking to SKDs assemblies Only.
  4. Clean and Build solution (Still in Debug mode).
  5. Deploy to android project (Still in Debug mode).
  6. Now when android application crashes check output windows you will see the cause of crashing.

If its something like missing dll then add that in proguard configuration file

Hi Uzairali,
Apologies for the delay and thanks for your detail step. after doing that, it leads me to another error that reported in this link https://github.com/xamarin/xamarin-android/issues/2620
I do some extra step explained in that GitHub and my project can build and run in my android device.
but it leaves 8 warning message
Severity Code Description Project File Line Suppression State Warning Mono.Cecil.Cil.SymbolsNotMatchingException: Symbols were found but are not matching the assembly at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader, Boolean throwIfSymbolsAreNotMaching) at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters) at Mono.Cecil.ModuleReader.CreateModule(Image image, ReaderParameters parameters) at Mono.Cecil.ModuleDefinition.ReadModule(Disposable1 stream, String fileName, ReaderParameters parameters)
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName, ReaderParameters parameters)
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.ReadAssembly(String file) QrCodeManagement.Android
Warning Failed to read 'E:\File_Yudi\AndroidProject\QRCodeManagement\QrCodeManagement\QrCodeManagement.Android\obj\Release\90\linksrc\Xamarin.Forms.Platform.Android.dll' with debugging symbols. Retrying to load it without it. Error details are logged below. QrCodeManagement.Android
Warning Mono.Cecil.Cil.SymbolsNotMatchingException: Symbols were found but are not matching the assembly
at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader, Boolean throwIfSymbolsAreNotMaching)
at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
at Mono.Cecil.ModuleReader.CreateModule(Image image, ReaderParameters parameters)
at Mono.Cecil.ModuleDefinition.ReadModule(Disposable1 stream, String fileName, ReaderParameters parameters) at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName, ReaderParameters parameters) at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.ReadAssembly(String file) QrCodeManagement.Android Warning Failed to read 'E:\File_Yudi\AndroidProject\QRCodeManagement\QrCodeManagement\QrCodeManagement.Android\obj\Release\90\android\assets\Xamarin.Forms.Platform.Android.dll' with debugging symbols. Retrying to load it without it. Error details are logged below. QrCodeManagement.Android Warning Failed to read 'E:\File_Yudi\AndroidProject\QRCodeManagement\QrCodeManagement\QrCodeManagement.Android\obj\Release\90\linksrc\FormsViewGroup.dll' with debugging symbols. Retrying to load it without it. Error details are logged below. QrCodeManagement.Android Warning Mono.Cecil.Cil.SymbolsNotMatchingException: Symbols were found but are not matching the assembly at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader, Boolean throwIfSymbolsAreNotMaching) at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters) at Mono.Cecil.ModuleReader.CreateModule(Image image, ReaderParameters parameters) at Mono.Cecil.ModuleDefinition.ReadModule(Disposable1 stream, String fileName, ReaderParameters parameters)
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName, ReaderParameters parameters)
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.ReadAssembly(String file) QrCodeManagement.Android
Warning Mono.Cecil.Cil.SymbolsNotMatchingException: Symbols were found but are not matching the assembly
at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader, Boolean throwIfSymbolsAreNotMaching)
at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
at Mono.Cecil.ModuleReader.CreateModule(Image image, ReaderParameters parameters)
at Mono.Cecil.ModuleDefinition.ReadModule(Disposable1 stream, String fileName, ReaderParameters parameters) at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName, ReaderParameters parameters) at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.ReadAssembly(String file) QrCodeManagement.Android Warning Failed to read 'E:\File_Yudi\AndroidProject\QRCodeManagement\QrCodeManagement\QrCodeManagement.Android\obj\Release\90\android\assets\FormsViewGroup.dll' with debugging symbols. Retrying to load it without it. Error details are logged below. QrCodeManagement.Android
Is it okay to ignore this warning message?

Crash reproducible with a standard MDP template, deployed to an S8 device.

(Whether this is specifically a Forms issue, I'm uncertain)

@iswahyudhie I am also getting these warnings but they are not causing any problem so far, so yeah ignore them.

@uzairali001 Thanks for your confirmation

I was able to get around it adding a custom proguard.cfg like described above. Works both with Proguard and r8. Tested against 4.2.0.673161-pre3 (as 4.2 GA breaks to many things for me, need to stay at this level for the moment).

While changing the ProGuard configuration didn't work for me, following https://github.com/xamarin/Xamarin.Forms/issues/5157#issuecomment-463554304 revealed the real error:

java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.FitWindowsFrameLayout" on path: DexPathList [...]

The solution was to include the following code in one of the Activity classes of the Android project, e.g. MainActivity.cs:

static bool falseflag = false;
static MainActivity()
{
    if (falseflag)
    {
        var ignore = new FitWindowsFrameLayout(Application.Context);
    }
}

Upon archiving I still get the original warning message but the generated package runs fine.

falseflag is mentioned here: https://docs.microsoft.com/en-us/xamarin/android/deploy-test/linker

@Mimisss what version of XF are you using? If it's a newer version can you attach a repro? Your exception should happen on any XF version 4.0+

I tested the original issue with the latest version of forms and I'm not see the error anymore.

Please log a new issue with a repro using the latest version of Forms if this exception still comes up for you

@PureWeen I am using Xamarin.Forms 3.4.0.1008975.

Was this page helpful?
0 / 5 - 0 ratings