'How to resolve the duplicate class error in between react native and android sdk?
I have a third party image recognition sdk library for my android application. Noe i want to integrate that to my react native project using native modules. I have some conflicts between the sdk's code and react native code.
I have tried removing the conflict from react native by the below code
implementation ("com.facebook.react:react-native:+") {
exclude group: "com.facebook.yoga", module: "proguard-annotations"
}
My error looks as below
Duplicate class com.facebook.proguard.annotations.DoNotStrip found in modules 3rd party sdk (3rdpartysdk.aar) and jetified-proguard-annotations-1.19.0 (com.facebook.yoga:proguard-annotations:1.19.0)
Duplicate class com.facebook.proguard.annotations.KeepGettersAndSetters found in modules 3rd party sdk (3rdpartysdk.aar) and jetified-react-native-0.67.1-runtime (com.facebook.react:react-native:0.67.1)
I have tried several things from the internet, but none relly seems to help
react-native : 0.67.1
Solution 1:[1]
This is very tricky. Without knowing the third party library, the alternatives are:
1.-Remove the conflicting transitive dependency from the root's gradle file. Is similar to what you are doing, but targets the entire path, and you can customize it as much as you want:
subprojects {
afterEvaluate {project ->
project.configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.facebook.react' && details.requested.name.equals('react-native')){
//add exclusion rules here
}
}
}
}
}
2.-Remove the conflicting class from one of conflicting libraries. Given that the class would be in the path, it may work, but it depends on how the class is being used. An extra alternative here would be removing the class from all libraries, then inserting a dynamic dependency in all the affected libraries. So you'll have to use the Copy task, like this. Theoretical example:
task unzipJar(type: Copy) {
from zipTree('$yourLibrary.aar')
into ("$buildDir/libs/$yourLibrary")
include "**/*.class"
exclude "**/Unmodifiable.class"
}
subprojects {
afterEvaluate {project ->
project.configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.facebook.react' && details.requested.name.equals('react-native')){
files("$buildDir/libs/$yourLibrary") {
builtBy "unzipJar"
}
}
}
}
}
}
An alternative to this is to run the unzipJar task and then put the resulting aar into your local maven repo, that way you can just replace the dependency normally. Good luck.
Solution 2:[2]
You can use JavaScript to do that in all the websites you want to redirect. And also turn off your HTTP forwarding as the javascript will automatically forward you to that website along with your parameters!
// https://letsgrow.in/
var currentUrl = window.location.href;
var urlParam = currentUrl.substring(20);
var newLink = 'https://letsgrow.web.app/'+urlParam;
window.onload=function(){
window.location.replace(newLink)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fco P. |
| Solution 2 | HackNetAyush |
