Exception is thrown when calling await MediaPicker.CapturePhotoAsync();
This exception is thrown just after permission checks and requests
The code works in debug mode, but not in release mode
Perhaps it's related to the necessary configuration detailed in MediaPlugin from James Montemagno:
https://github.com/jamesmontemagno/MediaPlugin#android-required-setup
But no reference is made to this kind of configuration in Xamarin.Essentials.MediaPicker's documentation
Exception is not thrown in Release mode
The following exception is thrown:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.XXX.XXXX/crc64a0e0a82d0db9a07d.IntermediateActivity}: java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.XXX.XXXX.fileProvider
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3326)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3465)
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:2069)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
E/AndroidRuntime(28427): Caused by: java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.XXX.XXXX.fileProvider
at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:606)
at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:579)
at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:417)
at crc64a0e0a82d0db9a07d.IntermediateActivity.n_onCreate(Native Method)
at crc64a0e0a82d0db9a07d.IntermediateActivity.onCreate(IntermediateActivity.java:31)
at android.app.Activity.performCreate(Activity.java:7817)
at android.app.Activity.performCreate(Activity.java:7806)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3301)
I had this just now as well.
When i went into the manifest and changed
android:authorities="${applicationId}.fileprovider"
into
android:authorities="${applicationId}.fileProvider"
it worked
edit
Going to sign a build and install an archived/signed on a test device to see if its really the fix (i didnt change anything else)
Edit 2
Installed a signed apk with the above described fix on a Oneplus 5T running oxygenOS 10.0.1 and i can now open the camera again
Edit 3
So it seems there is a difference between how essentials names the fileprovider and how james names it in his own plugin.
I am having the same issue. It works in debug mode but not in release mode
I am having the same issue. It works in debug mode but not in release mode
Have you tried renaming the authority in AndroidManifest to my suggested fix?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="xxx">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="xxx" android:theme="@style/MainTheme" android:allowBackup="false"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
That is my manifest.. where do I rename it?
Oh you dont even have a fileprovider in your manifest.....
Read this
and then rename android:authorities="${applicationId}.fileprovider" to android:authorities="${applicationId}.fileProvider"
@Gekidoku your suggested fix doesn't work for me. same issue here
@Gekidoku I have already tried the solution you suggest, but I couldn't get the software to work. Which puzzles me, that's why it works in "Debug" mode?
@cbs-cbt debugging a bit shows that the generated debug apk contains the following
<provider android:name="xamarin.essentials.fileProvider" android:authorities="com.companyname.mioid.fileProvider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/xamarin_essentials_fileprovider_file_paths" />
</provider>
but it's not part of release apk
Still not working for me. I am using Azure DevOps pipeline to generate an apk
There should be no need for the file provider element in the manifest, Xamarin.Essentials adds it automatically.
Could it be the linker is removing it? Can you do a release build but disable the linker and test again?
@mattleibow yes. confirmed. Linker is removing the provider element. disabling the linker removes the issue.
quick fix would be to ignore the Xamarin.Essentials library from linker
<AndroidLinkSkip>Xamarin.Essentials</AndroidLinkSkip>
Just writing this to provide further context that may help clarify why me just adding the fileprovider manually fixed it for me.
Xamarin Forms version: 4.8.0.156
Xamarin Essentials version: 1.6.0-pre3
My Manifest Here
If i remove my fileprovider it only works in debug.
Edit
Linker is set to Sdk Assemblies Only
@asadcr I tried your fix and it still does not work. I am using a Xiamo Mi Mix 2.
It only works in debug mode.
I am using azure devops pipeline to create an apk
@ekjuanrejon if you open the apk in Android Studio and browse to the AndroidManifest.xml, can you see the provider entry?
I have this for example.
<provider
android:name="xamarin.essentials.fileProvider"
android:exported="false"
android:authorities="com.xamarin.essentials.fileProvider"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@ref/0x7f110005" />
</provider>
That's what's on the manifest.
That's after adding <AndroidLinkSkip>Xamarin.Essentials</AndroidLinkSkip>
``<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" android:compileSdkVersion="28" android:compileSdkVersionCodename="9" package="com.companyname.connect365" platformBuildVersionCode="28" platformBuildVersionName="9">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-feature android:name="android.hardware.camera" android:required="true"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="true"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application android:theme="@style/MainTheme" android:label="Connect365.Android" android:icon="@mipmap/icon" android:name="android.app.Application" android:allowBackup="false" android:extractNativeLibs="true">
<activity android:theme="@style/MainTheme" android:label="Connect365" android:icon="@mipmap/icon" android:name="crc6411fd9ebf0bc2a66c.MainActivity" android:screenOrientation="portrait" android:configChanges="orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="crc64a0e0a82d0db9a07d.IntermediateActivity" android:configChanges="orientation|screenSize"/>
<receiver android:name="crc643f46942d9dd1fff9.PowerSaveModeBroadcastReceiver" android:enabled="true" android:exported="false"/>
<activity android:label="Scanner" android:name="crc6480997b3ef81bf9b2.ZxingActivity" android:configChanges="keyboardHidden|orientation|screenLayout"/>
<provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:authorities="com.companyname.connect365.mono.MonoRuntimeProvider.__mono_init__" android:initOrder="1999999999"/>
</application>
</manifest>
@jonathanpeppers or @dellis1972 , did we change anything with the linker that might result in things being removed in Release?
I think I found the issue. In the IntermediateActivity, we are referencing the FileProvider, but it appears to not be _our_ file provider, thus getting linked out, thus the metadata is missing from the manifest.
Until this is fixed, you can force the type to exist by referencing it in the Android project head somewhere:
Xamarin.Essentials.FileProvider.TemporaryLocation = Xamarin.Essentials.FileProvider.TemporaryLocation;
I just added the line somewhere in the OnCreate. It should do nothing, but keep the type available.
@mattleibow that seems to have worked. I have created a signed apk with azure devops and the camera is now working
upgrade to rc1... having the issues with azure devops
@mattleibow
at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
--- End of inner exception stack trace ---
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
at Xamarin.Android.Tasks.AndroidTask.Execute()
Most helpful comment
@mattleibow that seems to have worked. I have created a signed apk with azure devops and the camera is now working