Class 未找到异常:xamarin android

Class Not Found Exception: xamarin android

我正在尝试调试我的 android 应用程序,但不幸的是它给出了异常: Java.Lang.RuntimeException: 'Unable to get provider android.support.v4.content.fileprovider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.fileprovider" on path: DexPathList[[zip file "/data/app/com.companyname.finalproject_pu-1/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.finalproject_pu-1/lib/arm64, /data/app/com.companyname.finalproject_pu-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]' 我试过了:

  1. 垃圾箱/对象删除
  2. 重建重建
  3. 我在清单文件中添加了代码:
    <provider
   android:name="android.support.v4.content.fileprovider"
   android:authorities="com.companyname.finalproject_pu.fileprovider"
   android:grantUriPermissions="true"
   android:exported="false">

   <meta-data
      android:name="android.support.FILE_PROVIDER_PATHS"
      android:resource="@xml/file_paths" />
</provider>

我原来的供应商代码是:

<provider android:name="xamarin.essentials.fileProvider" android:authorities="com.companyname.finalproject_pu.fileprovider" 
android:exported="false" 
android:grantUriPermissions="true">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
      
      <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    </provider> 

首先,确保您的 <provider> 内容在 <Appliacation> 标签内。

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

其次,如果还是报错,可能你还在用旧的包,尝试把android.support.v4.FileProvider改成androidx.core.content.FileProvider

您可以在此处找到完整的 androidx 迁移列表:https://developer.android.com/jetpack/androidx/migrate/class-mappings