首页 > 解决方案 > 迁移到 AndroidX - android.support.FILE_PROVIDER_PATHS

问题描述

我在从 java 迁移到 kotlin 或 android 到 androidx 时遇到了这个问题,这是我的错误

java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority androidx.multidex.provider

2019-10-05 21:52:23.494 14821-14821/com.prodege.answer W/System.err: 在 androidx.core.content.FileProvider.b(FileProvider.java:606) 2019-10-05 21:52 :23.494 14821-14821/com.prodege.answer W/System.err: 在 androidx.core.content.FileProvider.a(FileProvider.java:579) 2019-10-05 21:52:23.494 14821-14821/com。 prodege.answer W/System.err:在 androidx.core.content.FileProvider.a(FileProvider.java:417) 2019-10-05 21:52:23.494 14821-14821/com.prodege.answer W/System.err :在 com.prodege.answer.ui.surveyWebView.SurveysWebViewActivity.openCamera(SurveysWebViewActivity.kt:379) 2019-10-05 21:52:23.494 14821-14821/com.prodege.answer W/System.err:在 com. prodege.answer.ui.surveyWebView.SurveysWebViewActivity.access$openCamera(SurveysWebViewActivity.kt:33) 2019-10-05 21:52:23.494 14821-14821/com.prodege.answer W/System.err: at com.prodege.answer.ui.surveyWebView.SurveysWebViewActivity$loadWebView$2.onShowFileChooser(SurveysWebViewActivity.kt:175) 2019-10-05 21:52:23.494 14821-14821/com.prodege.answer W/System.err: 在 xl.a (PG:537) 2019-10-05 21:52:23.494 14821-14821/com.prodege.answer W/System.err: 在 agE.runFileChooser(PG:72) 2019-10-05 21:52:23.494 14821 -14821/com.prodege.answer W/System.err:在 android.os.MessageQueue.nativePollOnce(本机方法) 2019-10-05 21:52:23.495 14821-14821/com.prodege.answer W/System.err : 在 android.os.MessageQueue.next(MessageQueue.java:326) 2019-10-05 21:52:23.495 14821-14821/com.prodege.answer W/System.err: 在 android.os.Looper.loop( Looper.java:160) 2019-10-05 21:52:23.495 14821-14821/com.prodege.answer W/System.err: 在 android.app.ActivityThread.main(ActivityThread.java:6669) 2019-10- 05 21:52:23。495 14821-14821/com.prodege.answer W/System.err: at java.lang.reflect.Method.invoke(Native Method) 2019-10-05 21:52:23.495 14821-14821/com.prodege.answer W /System.err:在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 2019-10-05 21:52:23.495 14821-14821/com.prodege.answer W/System.err : 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

这是我的清单文件,我还扩展了 multiDexApp

<provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.prodege.answer.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths" />
    </provider>

这是我的 buil.gradle 文件

android {
compileSdkVersion 29
defaultConfig {
    applicationId "com.prodege.answer"
    minSdkVersion 21
    targetSdkVersion 29
    versionCode 1
    versionName "2.4"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        //  buildConfigField "boolean", "URBAN_AIRSHIP_DEBUG_MODE", "false"
        minifyEnabled true
        useProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        //  buildConfigField "boolean", "URBAN_AIRSHIP_DEBUG_MODE", "true"
        minifyEnabled true
        useProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
    enabled = true
}

kapt {
    javacOptions {
        // Increase the max count of errors from annotation processors.
        // Default is 100.
        option("-Xmaxerrs", 1000)
    }
}

dexOptions {
    javaMaxHeapSize "4g"

}

}

依赖项{实现文件树(包括:['*.jar'],目录:'libs')

//Kotlin support dependencies
implementation kotlinDependencies.core
implementation kotlinDependencies.coroutinesCore
implementation kotlinDependencies.coroutinesAndroid

// Kotlin Extension for Simplified coding
implementation androidxDependencies.ktx

//Android x design and backward compatibility support dependencies
implementation androidxDependencies.appCompat
implementation androidxDependencies.constraintlayout
implementation androidxDependencies.lifecycleExtention
implementation androidxDependencies.recyclerView
implementation androidxDependencies.multiDex
implementation androidxDependencies.roomRuntime
kapt androidxDependencies.roomCompiler


//Google dependencies
implementation googleDependencies.material
implementation googleDependencies.gson

// Network Library Retrofit dependencies
implementation networkDependencies.retrofit
implementation networkDependencies.retrofitGsonConveter
implementation networkDependencies.scalarConveter
implementation networkDependencies.okHttpLogs
implementation networkDependencies.kotlinCoroutineAdapterFactory
/* UI Related Dependencies */
implementation uiDependencies.glide
implementation 'com.facebook.stetho:stetho:1.5.1'

/* Koin DI */
implementation kotlinDI.core
implementation kotlinDI.scope
implementation kotlinDI.viewModel


implementation analyticsSdk.adjust

implementation(name: 'fraudforce-lib-release-3.1.0', ext: 'aar')
implementation project(path: ':library')

implementation 'com.daimajia.androidanimations:library:2.3@aar'



// Testing Dependencies
androidTestImplementation androidxTestingDependencies.archCore
androidTestImplementation androidxTestingDependencies.core
androidTestImplementation androidxTestingDependencies.contrib
androidTestImplementation androidxTestingDependencies.intents
androidTestImplementation androidxTestingDependencies.uiAutoMator

//UA Dependencies
implementation uaFirebase.core
implementation uaFirebase.firebaseDynamicLink
implementation uaFirebase.firebaseMsg
implementation uaFirebase.urbanairship
implementation(uaFirebase.crashlytics)
{
    transitive = true
}
testImplementation "junit:junit:$junitVersion"

//sense360
implementation sense360Dep.sense360

//Cuebiq
/*implementation(cuebiqDep.cuebiq) {
    exclude module: 'okhttp'
    exclude module: 'okio'
    exclude module: 'play-services-location'
    exclude module: 'gson'
}*/

//gimbal
implementation gimbalDep.gimbalSdk
implementation gimbalDep.gimbalImpl

implementation(gmsPlayServices.location) {
    force = true
}

implementation gmsPlayServices.gmsServicesAds
implementation gmsPlayServices.goodleMap
implementation gmsPlayServices.goodleMapUtil

implementation(gmsPlayServices.gmsServices) {
    force = true
}

implementation 'com.github.rahatarmanahmed:circularprogressview:2.5.0'
/* BlinkReceipt dependencies*/
implementation project(':LibBlinkReceipt')
implementation "com.jaredrummler:android-device-names:1.0.9"
implementation blinkReceiptDependencies.retrofitscalers
implementation blinkReceiptDependencies.okio
implementation blinkReceiptDependencies.easyPermission

}

标签: android

解决方案


import androidx.multidex.BuildConfig // NOT DO THIS!!!

val uri = FileProvider.getUriForFile(this,
            BuildConfig.APPLICATION_ID+ ".provider", _tempFile)

不要使用 androidx.multidex.BuildConfig,因为这个值不是你的应用程序的值:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package androidx.multidex;

public final class BuildConfig {
    public static final boolean DEBUG = false;
    public static final String APPLICATION_ID = "androidx.multidex";
    public static final String BUILD_TYPE = "release";
    public static final String FLAVOR = "";
    public static final int VERSION_CODE = -1;
    public static final String VERSION_NAME = "";

    public BuildConfig() {
    }
}

推荐阅读