Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.support.v4.content.FileProvider class not found in android Kitkat

I am using FileProvider in my app. As usual I declared <Provider> tag in AndroidManifest.xml file as below.

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

When I run it on android device which has lollipop version it works fine. when I try it on kitkat version it shows following errors:

FATAL EXCEPTION: main
              Process: com.jk.android.perfectphotoeditor2018, PID: 24992
              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.jk.android.perfectphotoeditor2018-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.jk.android.perfectphotoeditor2018-2, /system/lib]]
                  at android.app.ActivityThread.installProvider(ActivityThread.java:5071)
                  at android.app.ActivityThread.installContentProviders(ActivityThread.java:4648)
                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4588)
                  at android.app.ActivityThread.access$1500(ActivityThread.java:151)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1290)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:136)
                  at android.app.ActivityThread.main(ActivityThread.java:5299)
                  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:932)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:748)
                  at dalvik.system.NativeStart.main(Native Method)
               Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.jk.android.perfectphotoeditor2018-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.jk.android.perfectphotoeditor2018-2, /system/lib]]
                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
                  at android.app.ActivityThread.installProvider(ActivityThread.java:5056)
                  at android.app.ActivityThread.installContentProviders(ActivityThread.java:4648) 
                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4588) 
                  at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1290) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:136) 
                  at android.app.ActivityThread.main(ActivityThread.java:5299) 
                  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:932) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:748) 
                  at dalvik.system.NativeStart.main(Native Method)

I had tried many solutions like this but it doesn't work for me. so, help me for solve this problem.

build.gradle dependencies:

dependencies {
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
    testCompile 'junit:junit:4.12'
    /* Add the CSDK framework dependencies (Make sure these version numbers are correct) */
    //    compile 'com.aviary.android.feather.sdk:aviary-sdk:3.6.3'
    compile 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.adobe.creativesdk.foundation:auth:0.9.1251'
    compile 'com.adobe.creativesdk:image:4.8.4'
    compile 'com.localytics.android:library:4.0.1'
    compile 'com.android.support:design:25.4.0'
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.support:support-v4:25.4.0'
    compile 'com.intuit.sdp:sdp-android:1.0.4'
    compile 'com.github.bumptech.glide:glide:4.3.1'
    compile 'com.google.android.gms:play-services-ads:9.4.0'
    implementation 'com.android.support:support-v4:25.4.0'
}
like image 843
Jaydip Kalkani Avatar asked Dec 19 '17 13:12

Jaydip Kalkani


People also ask

How do I install FileProvider on Android?

fileprovider . To get a content URI for the file default_image. jpg in the images/ subdirectory of your internal storage add the following code: File imagePath = new File(Context.

How do I use FileProvider?

To make FileProvider work follow these three steps: Define the FileProvider in your AndroidManifest file. Create an XML file that contains all paths that the FileProvider will share with other applications. Bundle a valid URI in the Intent and activate it.


2 Answers

The following code works for me (I've migrated to AndroidX):

<provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="${applicationId}.provider"
        android:exported="false"
        android:grantUriPermissions="true"
        tools:ignore="WrongManifestParent">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths" />
</provider>
like image 196
Frank Eno Avatar answered Oct 24 '22 07:10

Frank Eno


If you have migrated to AndroidX you have to change the name in AndroidManifest.xml to androidx.core.content.FileProvider

That was the crash in my case.

like image 26
peresisUser Avatar answered Oct 24 '22 08:10

peresisUser