17

I migrated my app to AndroidX and it's crashing on launch on API level 21. My application throws this exception:

10-08 09:42:50.930 11346-11346/com.example.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.test, PID: 11346
java.lang.RuntimeException: Unable to get provider androidx.core.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "androidx.core.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.example.test-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.test-1, /vendor/lib, /system/lib]]
    at android.app.ActivityThread.installProvider(ActivityThread.java:5121)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4713)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4596)
    at android.app.ActivityThread.access$1600(ActivityThread.java:169)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5487)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.example.test.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.test-1, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    at android.app.ActivityThread.installProvider(ActivityThread.java:5106)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4713) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4596) 
    at android.app.ActivityThread.access$1600(ActivityThread.java:169) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:146) 
    at android.app.ActivityThread.main(ActivityThread.java:5487) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
    at dalvik.system.NativeStart.main(Native Method)

And here is the provider definition in my AndroidManifest.xml file:

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.fileProvider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths" />
</provider>

On the latest API level it works fine. Any suggestions would be useful, thanks in advance.

0

5 Answers 5

12

It seems that this error came from incomplete configuration of MultiDex in your app. Here you may find the similar issue and here is an article answering it.

I suggest you to check the following (extending App class helped me):

Your Application class (App.class, for instance, if you use it) should extend from MultiDexApplication class:

public class BaseApplication extends MultiDexApplication {}

or if you don't use Application class check your manifest:

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.android.multidex.myapplication">
        <application
            ...
            android:name="android.support.multidex.MultiDexApplication">
            ...
        </application>
    </manifest>
Sign up to request clarification or add additional context in comments.

2 Comments

Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
Hi @akhirs ,My Application class is already extended but still i get this issues.
1

The documentation is outdated; use androidx.multidex for androidx:

implementation "androidx.multidex:multidex:2.0.1"

AndroidManifest.xml:

<application
    android:name="androidx.multidex.MultiDexApplication">
</application>

Use the Jetifier when it still uses any com.android.support libraries:

android.enableJetifier=true

1 Comment

Also add multiDexEnabled true inside defaultConfig
0

The problem is your React Native android project is not in AndroidX while react-native-image-picker is in an AndroidX environment; therefore, it is missing packages from the androidx package library.

Simple fix is adding the following lines to your ./android/gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

If you have any existing RN libraries that uses old android packages, your project won't build since they will be missing once you updated your project.

A clever tool found here deals with RN libraries that uses old android packages and brings them up to date.

npm i --save-dev jetifier
npx jetify
react-native run-android

All checked out and it's working on my end. Hope this helps anyone and please do share if it does.

Source https://github.com/react-native-community/react-native-image-picker/issues/1088#issuecomment-509755692

1 Comment

Thanks for your answer but It was NOT a ReactNative project.
0

Add tools:ignore="MissingClass". The error message and red marker will not disappear, but you can run “.\gradlew build --warning-mode all” in the console without an error appearing.

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="de.sample.FileProvider"
    android:exported="false"
    tools:ignore="MissingClass"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths"/>
</provider>

Comments

-1

add below ndk lib support to your project if you have used the external library -

ndk
     {
        abiFilters "armeabi-v7a", "x86", "x86_64", "arm64-v8a"
     }

inside the default config of your app level build.gradle file

defaultConfig 
    {
        applicationId "org.comcast.net"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        ndk
                {
                    abiFilters "armeabi-v7a", "x86", "x86_64", "arm64-v8a"
                }
    }

it has solved my problem, hopefully it will solve at your end also.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.