vinzscam/react-native-file-viewer

Error migrating to AndroidX

SystemBlad opened this issue ยท 8 comments

Hi,
I using this great library and I was trying to migrate my react native project to AndroidX but the following error is show:

Error:
package android.support.v4.content does not exist

In the file:
android\src\main\java\com\vinzscam\reactnativefileviewer\RNFileViewerModule.java

Line:
8

Do you know when I will be able to use this library with AndroidX?

Thanks.

I ran into this same issue. Opened up #50

AndroidX is not yet included in react-native projects. #50 includes many unnecessary files and it doesn't keep retro compatibility with current projects.

I would recommend to append the following snippet to your android/app/build.gradle file:

preBuild.doFirst {
    ant.replaceregexp(match:'android.support.v4.content.', replace:'androidx.core.content.', flags:'g', byline:true) {
        fileset(dir: '../../node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer', includes: '*.java')
    }
}

Let me know if that works.

AndroidX is not yet included in react-native projects. #50 includes many unnecessary files and it doesn't keep retro compatibility with current projects.

I would recommend to append the following snippet to your android/app/build.gradle file:

preBuild.doFirst {
    ant.replaceregexp(match:'android.support.v4.content.', replace:'androidx.core.content.', flags:'g', byline:true) {
        fileset(dir: '../../node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer', includes: '*.java')
    }
}

Let me know if that works.

@vinzscam is working using the snippet code thanks.

FWIW. The AndroidX migration stuff was merged into React Native. facebook/react-native#23112. It seems like its coming in 0.60.

AndroidX is not yet included in react-native projects. #50 includes many unnecessary files and it doesn't keep retro compatibility with current projects.

I would recommend to append the following snippet to your android/app/build.gradle file:

preBuild.doFirst {
    ant.replaceregexp(match:'android.support.v4.content.', replace:'androidx.core.content.', flags:'g', byline:true) {
        fileset(dir: '../../node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer', includes: '*.java')
    }
}

Let me know if that works.

When I do this, in Android Studio, the project seems to build fine, but when i run react-native run-android, it gives me the same errors again

> Task :react-native-file-viewer:compileDebugJavaWithJavac FAILED
/Users/philip/Workspaces/clientbooks-mobile/node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer/FileProvider.java:3: error: package androidx.core.content does not exist
public class FileProvider extends androidx.core.content.FileProvider {
                                                       ^
/Users/philip/Workspaces/clientbooks-mobile/node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer/RNFileViewerModule.java:8: error: package androidx.core.content does not exist
import androidx.core.content.FileProvider;
                            ^
/Users/philip/Workspaces/clientbooks-mobile/node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer/RNFileViewerModule.java:57: error: cannot find symbol
        contentUri = FileProvider.getUriForFile(getCurrentActivity(), authority, newFile);

I have the same problem!

ital0 commented

@ws7one @vauruk please take a look in this topic: #60

java.lang.RuntimeException: Unable to get provider com.vinzscam.reactnativefileviewer.FileProvider: java.lang.ClassNotFoundException: Didn't find class "com.vinzscam.reactnativefileviewer.FileProvider" on path: DexPathList[[zip file "/data/app/com.preventioncloud-31cbX744wihkDqzlqjvVKg==/base.apk"],nativeLibraryDirectories=[/data/app/com.preventioncloud-31cbX744wihkDqzlqjvVKg==/lib/arm, /data/app/com.preventioncloud-31cbX744wihkDqzlqjvVKg==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
11-11 18:56:09.077 839 839 E AndroidRuntime: at android.app.ActivityThread.installProvider(ActivityThread.java:6242)
11-11 18:56:09.077 839 839 E AndroidRuntime: at android.app.ActivityThread.installContentProviders(ActivityThread.java:5805)
11-11 18:56:09.077 839 839 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722)
11-11 18:56:09.077 839 839 E AndroidRuntime: at android.app.ActivityThread.-wrap1(Unknown Source:0)
11-11 18:56:09.077 839 839 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
11-11 18:56:09.077 839 839 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
11-11 18:56:09.077 839 839 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
11-11 18:56:09.077 839 839 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6494)
11-11 18:56:09.077 839 839 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-11 18:56:09.077 839 839 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
11-11 18:56:09.077 839 839 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
11-11 18:56:09.077 839 839 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.vinzscam.reactnativefileviewer.FileProvider" on path: DexPathList[[zip file "/data/app/com.preventioncloud-31cbX744wihkDqzlqjvVKg==/base.apk"],nativeLibraryDirectories=[/data/app/com.preventioncloud-31cbX744wihkDqzlqjvVKg==/lib/arm, /data/app/com.preventioncloud-31cbX744wihkDqzlqjvVKg==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
11-11 18:56:09.077 839 839 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
11-11 18:56:09.077 839 839 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
11-11 18:56:09.077 839 839 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
11-11 18:56:09.077 839 839 E AndroidRuntime: at android.app.ActivityThread.installProvider(ActivityThread.java:6227)
11-11 18:56:09.077 839 839 E AndroidRuntime: ... 10 more
11-11 18:56:09.083 3287 17145 W ActivityManager: Force finishing activity com.preventioncloud/.MainActivity
11-11 18:56:09.089 3287 3378 I ActivityManager: Showing crash dialog for package com.preventioncloud u0

i am getting this type of runtime error after execute npx react-native run-android command app is successfully installed and crashed after splash screen and get these type of crash log any one can help me with this