Vydia / react-native-background-upload

Upload files in your React Native app even while it's backgrounded. Supports Android and iOS, including camera roll assets.
MIT License
723 stars 330 forks source link

The package crashes Android app version #231

Open florinlazau opened 3 years ago

florinlazau commented 3 years ago

Hello,

I'm developing a cross-platform application and the package is working on IOS but causes app crash on Android. The crash appears when I start the app. I assume that is something with my sdk version : buildToolsVersion = "29.0.3" minSdkVersion = 21 compileSdkVersion = 29 targetSdkVersion = 29 supportLibVersion = "28.0.0" kotlinVersion = "1.3.61"

For recat native I'm using "0.63.3.

Is there any chance to run use the package on this version?

Many thanks, Florin

petrbela commented 3 years ago

I can confirm this. Crashes immediately when launching the app. It seems to be related to okhttp but I couldn't figure out how to make it work (manual linking didn't help either).

E/FileSystemModule: canceled due to java.lang.NoSuchMethodError: No static method delimiterOffset(Ljava/lang/String;IILjava/lang/String;)I in class Lokhttp3/internal/Util; or its super classes (declaration of 'okhttp3.internal.Util' appears in /data/app/app.zealous.development-1/base.apk:classes3.dex)
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
    Process: app.zealous.development, PID: 29995
    java.lang.NoSuchMethodError: No static method delimiterOffset(Ljava/lang/String;IILjava/lang/String;)I in class Lokhttp3/internal/Util; or its super classes (declaration of 'okhttp3.internal.Util' appears in /data/app/app.zealous.development-1/base.apk:classes3.dex)
        at okhttp3.JavaNetCookieJar.decodeHeaderAsJavaNetCookies(JavaNetCookieJar.java:91)
        at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.java:74)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:74)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:762)
petrbela commented 3 years ago

btw it doesn't conflict when I downgrade this package to 5.7.0 (which uses okhttp 3.x, same as React Native, which is still at 3.x because 4.x would drop support on Android API <21)

reime005 commented 3 years ago

@petrbela should be fixed if you add both implementation 'com.squareup.okhttp3:okhttp:4.3.0 and implementation 'com.squareup.okhttp3:okhttp:3.X.X (take the specific version from react-native)

petrbela commented 3 years ago

@reime005 That alone doesn't seem to fix the problem. Is there anything else that needs to tell the library which okhttp version to use?

ba-ddou commented 3 years ago

I am using RNBU with react-native 0.59 which uses okhttp 3.12.1 Forcing okhttp 3.4.1 in the resolution strategy causes the app to crash every time I try to open it, and here's the crash report:

Didn't find class "okhttp3.WebSocketListener" on path: DexPathList[[zip file "/data/app/~~p5SKMs82GEfBsE1Q9SdQrw==/com.gondemand.driver-9kiMTY2BiPvi4qyDMHmpNg==/base.apk"],nativeLibraryDirectories=[/data/app/~~p5SKMs82GEfBsE1Q9SdQrw==/com.gondemand.driver-9kiMTY2BiPvi4qyDMHmpNg==/lib/arm64, /data/app/~~p5SKMs82GEfBsE1Q9SdQrw==/com.gondemand.driver-9kiMTY2BiPvi4qyDMHmpNg==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64, /product/lib64]]

Forcing okhttp 3.12.1 in the resolution strategy causes this error when I try to upload a file:

Error: No field Companion of type Lokhttp3/MediaType$Companion; in class Lokhttp3/MediaType; or its superclasses (declaration of 'okhttp3.MediaType' appears in /data/app/~~jeymLDmC0xIb4qHjiLii-w==/com.gondemand.driver-XRGvnovvQ6cUj52aWWabzw==/base.apk!classes50.dex)%
ba-ddou commented 3 years ago

I was able to make this work by editing RNBU's app level build.gradle; I removed the okhttp module exclude directive

 exclude group:'com.squareup.okhttp3', module:'okhttp'    <- remove this line

And explicitly added okhttp3.4.1 as a dependency

 implementation "com.squareup.okhttp3:okhttp:3.4.1"  <- add this line

I'm wondering if there's a way to force this from my app's level build.gradle file without having edit RNBU's code

sadikyalcin commented 3 years ago

The solution would be to force using the same version. Add the following before dependencies declaration in app/build.gradle.

Use 4.9.1 or whatever the latest version is at current time.

configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:4.9.1'
}

dependencies {
//
        debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
                exclude group:'com.facebook.flipper'
                exclude group:'com.squareup.okhttp3', module:'okhttp'
        }
}

You shouldn't have to be changing the flipper settings in the dependencies.

luigbren commented 3 years ago

Any other solution? I also have this problem.

Error: No field Companion of type Lokhttp3/MediaType$Companion; in class Lokhttp3/MediaType; or its superclasses (declaration of 'okhttp3.MediaType'...

I added this line of code to be able to run my app, since it was giving me an error and closing. (crash)

configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.9.1'
}
PitzTech commented 3 years ago

The solution would be to force using the same version. Add the following before dependencies declaration in app/build.gradle.

configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.9.1'
}

dependencies {
//
        debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
                exclude group:'com.facebook.flipper'
                exclude group:'com.squareup.okhttp3', module:'okhttp'
        }
}

You shouldn't have to be changing the flipper settings in the dependencies.

Fixed the App Closing problem on React Native 0.61.5. Thank you!

luigbren commented 3 years ago

The solution would be to force using the same version. Add the following before dependencies declaration in app/build.gradle.

configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.9.1'
}

dependencies {
//
        debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
                exclude group:'com.facebook.flipper'
                exclude group:'com.squareup.okhttp3', module:'okhttp'
        }
}

You shouldn't have to be changing the flipper settings in the dependencies.

Fixed the App Closing problem on React Native 0.61.5. Thank you!

I was also happy with that solution, by placing those lines does not give error (Crash) to open the application, but in my case does not work, when uploading some content gives an error and does nothing ... no good that solution ... I had uninstall and reinstall RNBU V0.5.7, that version if it works perfec

r0b0t3d commented 3 years ago

Mine work when having this with rn 0.64.2

configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:4.9.1'
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp-urlconnection:4.9.1'
}
thongbbc commented 2 years ago

Mine work when having this with rn 0.64.2

configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:4.9.1'
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp-urlconnection:4.9.1'
}

Yeah this solution fix my issue, some library use okhttp does not match with version okhttp in RN core.

giriprabu commented 2 years ago

Mine work when having this with rn 0.64.2

configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:4.9.1'
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp-urlconnection:4.9.1'
}

Working on react-native~0.63.4

Nothing worked until I made this change. After making this change, the background upload is again working! Thank you!

MarquisAlexander commented 2 years ago

The solution would be to force using the same version. Add the following before dependencies declaration in app/build.gradle.

Use 4.9.1 or whatever the latest version is at current time.

configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:4.9.1'
}

dependencies {
//
        debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
                exclude group:'com.facebook.flipper'
                exclude group:'com.squareup.okhttp3', module:'okhttp'
        }
}

You shouldn't have to be changing the flipper settings in the dependencies.

bro, this worked for me! thanks! "react-native": "0.65.1"

Wetoria commented 1 year ago

Mine work when having this with rn 0.64.2

configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:4.9.1'
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp-urlconnection:4.9.1'
}

Thanks this. It save my life