首页 > 解决方案 > InAppWebView 插件中的问题

问题描述

我在使用 InAppWebView 插件时遇到了这个错误,请指导我在哪里出错。如何解决这个问题?

W/System.err(30308): java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.nine_am.app.flutter_inappwebview.fileprovider
W/System.err(30308):    at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:606)
W/System.err(30308):    at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:579)
W/System.err(30308):    at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:417)
W/System.err(30308):    at com.pichillilorenzo.flutter_inappwebview.InAppWebView.InAppWebViewChromeClient.getOutputUri(InAppWebViewChromeClient.java:1052)
W/System.err(30308):    at com.pichillilorenzo.flutter_inappwebview.InAppWebView.InAppWebViewChromeClient.getPhotoIntent(InAppWebViewChromeClient.java:938)
W/System.err(30308):    at com.pichillilorenzo.flutter_inappwebview.InAppWebView.InAppWebViewChromeClient.startPhotoPickerIntent(InAppWebViewChromeClient.java:895)
W/System.err(30308):    at com.pichillilorenzo.flutter_inappwebview.InAppWebView.InAppWebViewChromeClient.onShowFileChooser(InAppWebViewChromeClient.java:799)
W/System.err(30308):    at co.runFileChooser(PG:10)
W/System.err(30308):    at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err(30308):    at android.os.MessageQueue.next(MessageQueue.java:336)
W/System.err(30308):    at android.os.Looper.loop(Looper.java:181)
W/System.err(30308):    at android.app.ActivityThread.main(ActivityThread.java:7520)
W/System.err(30308):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err(30308):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
W/System.err(30308):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
F/chromium(30308): [FATAL:jni_android.cc(249)] Please include Java exception stack in crash report
F/libc    (30308): Fatal signal 5 (SIGTRAP), code -6 (SI_TKILL) in tid 30308 (com.nine_am.app), pid 30308 (com.nine_am.app)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

如果添加了提供者标签,它会显示这样的错误,请查看它,我在路径 res>xml>provider_paths.xml 中添加了 provider_paths.xml 文件

    E/AndroidRuntime(16711): java.lang.RuntimeException: Unable to get provider com.nine_am.app.flutter_inappwebview.InAppWebViewFileProvider: java.lang.ClassNotFoundException: Didn't find class "com.nine_am.app.flutter_inappwebview.InAppWebViewFileProvider" on path: DexPathList[[zip file "/data/app/com.nine_am.app-ytDaqFCP0M6-QPYD_HI-wQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.nine_am.app-ytDaqFCP0M6-QPYD_HI-wQ==/lib/arm64, /data/app/com.nine_am.app-ytDaqFCP0M6-QPYD_HI-wQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
E/AndroidRuntime(16711):    at android.app.ActivityThread.installProvider(ActivityThread.java:7152)
E/AndroidRuntime(16711):    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6630)
E/AndroidRuntime(16711):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6525)
E/AndroidRuntime(16711):    at android.app.ActivityThread.access$1400(ActivityThread.java:220)
E/AndroidRuntime(16711):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1883)
E/AndroidRuntime(16711):    at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(16711):    at android.os.Looper.loop(Looper.java:224)
E/AndroidRuntime(16711):    at android.app.ActivityThread.main(ActivityThread.java:7520)
E/AndroidRuntime(16711):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(16711):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
E/AndroidRuntime(16711):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
E/AndroidRuntime(16711): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.nine_am.app.flutter_inappwebview.InAppWebViewFileProvider" on path: DexPathList[[zip file "/data/app/com.nine_am.app-ytDaqFCP0M6-QPYD_HI-wQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.nine_am.app-ytDaqFCP0M6-QPYD_HI-wQ==/lib/arm64, /data/app/com.nine_am.app-ytDaqFCP0M6-QPYD_HI-wQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]

这是我的 manifest.xml,请看下面

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nine_am.app">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="9am"
        android:usesCleartextTraffic="true"
        android:icon="@mipmap/launcher_icon">
        <provider
           android:name="com.com.nine_am.app.flutter_inappwebview.InAppWebViewFileProvider"
           android:authorities="${applicationId}.flutter_inappwebview.fileprovider"
           android:exported="false"
           android:grantUriPermissions="true">
            <meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/provider_paths" />
        </provider>
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

请检查这一切并给我一个解决方案。提前致谢!

标签: androidflutter

解决方案


注册您的提供商AndroidManifest.xml

<provider
    android:name="com.com.nine_am.app.flutter_inappwebview.InAppWebViewFileProvider"
    android:authorities="${applicationId}.flutter_inappwebview.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths" />
</provider>

编辑

将multidex添加到android

看到这里是步骤https://developer.android.com/studio/build/multidex


推荐阅读