exception when configuring a FileProvider

MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

I'm trying to configure a FileProvider in my Xamarin.Forms app. There are numerous examples (some blog, Google, SO, Xamarin samples) where people did that without a problem.

Unfortunately when I do the same, I get an exception.

I added this to my AndroidManifest.xml (within <application...> together with two activity's):

<provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="com.royalapplications.royaltsd.fileprovider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
    android:name="android.support.FILE_PROVIDER_PATHS"
    android:resource="@xml/providerpaths" />
</provider>

The Resources/xml/providerpaths.xml is very simple:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
  <files-path name="connections" path="."/>
</paths>

But as soon as I include providerpaths.xml in my project and I want to run it, then I get an exception in MainActivity.OnCreate when I call base.OnCreate.

04-25 15:18:59.757 I/MonoDroid(23333): UNHANDLED EXCEPTION:
04-25 15:18:59.764 I/MonoDroid(23333): Java.Lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.ContentFrameLayout.setId(int)' on a null object reference
04-25 15:18:59.764 I/MonoDroid(23333):   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
04-25 15:18:59.764 I/MonoDroid(23333):   at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x000a7] in /Users/builder/data/lanes/4468/b16fb820/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12083 
04-25 15:18:59.764 I/MonoDroid(23333):   at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (System.IntPtr jobject, System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x00000] in /Users/builder/data/lanes/4468/b16fb820/source/monodroid/src/Mono.Android/JNIEnv.g.cs:444 
04-25 15:18:59.764 I/MonoDroid(23333):   at Android.Support.V7.App.AppCompatActivity.SetSupportActionBar (Android.Support.V7.Widget.Toolbar toolbar) [0x00091] in <c690702816034f28aca512af1f0abd66>:0 
04-25 15:18:59.764 I/MonoDroid(23333):   at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00050] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:171 
04-25 15:18:59.764 I/MonoDroid(23333):   at RoyalMobileApps.XF.Android.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0000d] in D:\RoyalFamily\RoyalMobileApps.XF\Android\RoyalTSD\MainActivity.cs:34 
04-25 15:18:59.764 I/MonoDroid(23333):   at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <27c17fe440cf491ba8255bcefade6e02>:0 
04-25 15:18:59.764 I/MonoDroid(23333):   at (wrapper dynamic-method) System.Object:fa6cc14f-843c-4f05-b6cf-c90ed14f8c0b (intptr,intptr,intptr)

I can exclude the file from the Android project, then it builds and starts, but of course I cannot share my file.

Answers

  • ItayShreItayShre USMember

    I have same problem when i use my MainActivity inherit from "FormsAppCompatActivity".
    Did you found a solution not including inheritance from "FormsApplicationActivity"?

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    Once again it was a bug which vanished over night without changing anything.

    It is so frustrating when this happens. And it only occurs when working with Xamarin.

Sign In or Register to comment.