AndroidX: AndroidX.Core.Content.FileProvider Fails to Instantiate with Multi-Dex On
Xamarin.Android Version (eg: 6.0):
Microsoft Visual Studio Enterprise 2019 Version 16.7.2 VisualStudio.16.Release/16.7.2+30413.136 Xamarin 16.7.000.440 (d16-7@358f3c6) Xamarin.Android SDK 11.0.2.0 (d16-7/025fde9)
Operating System & Version (eg: Mac OSX 10.11):
Windows 10 1909 18363.778
Support Libraries Version (eg: 23.3.0):
Xamarin.AndroidX.Core 1.3.0.1
Describe your Issue:
When the Multi-Dex option is turned on and a file provider is defined in the manifest file, the app crashes upon startup.
Steps to Reproduce (with link to sample solution if possible):
Run the AndroidX app provided in the attached package.
Include any relevant Exception Stack traces, build logs, adb logs:
Java.Lang.RuntimeException:
'Unable to get provider androidx.core.content.FileProvider:
java.lang.InstantiationException: java.lang.Class<androidx.core.content.FileProvider> cannot be instantiated'
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (8 by maintainers)
I had the same initialization error. I changed the Code Shrinker property in Android Project Property from ProGuard and R8 to EMPTY. This solved the issue. Just remove the ProGuard property and it works. I will try to find another workaround later but for now, this is fine with me.
Because issue is not caused by bindings itself.
I have proven that with proguard rules there is completely different error (No Activity) and I did not dive in deeper.
The class was bound (surfaced) and now additional tools come into play:
I would suggest to open new issue in xamarin-android repo, with repro sample that uses my proguard rule and explanation, so the team can test with and without proguard/R8 rules.
I hope this reduces confusion a bit. It is not simple problem.
Repro succeded:
multidex -on => crash
multidex off => OK