software-mansion / react-native-svg

SVG library for React Native, React Native Web, and plain React web projects.
MIT License
7.5k stars 1.13k forks source link

Android - Bundle release error #1340

Closed thiagobrez closed 1 year ago

thiagobrez commented 4 years ago

Hello all, and forgive me if this isn't the right place to ask, I've already asked on stack overflow with no response.

For some days now I've been stuck when trying to bundleRelease my React Native Android app using react-native-svg.

Error

Task :app:transformDexArchiveWithDexMergerForRelease FAILED
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: com.horcrux.svg.Brush$BrushType

I'm aware that this probably isn't a bug within react-native-svg but I came to ask for help if anyone has ever gone through this.

Apparently there's 2 or more dependencies trying to use BrushType and it throws this error.

I imagine that once I find the libraries using BrushType, I could do something like

implementation(:my-library) {
  exclude ...
}

Correct?

I can't remember 100%, but somehow I got to suspect that this may be an issue with installing both react-native-svg and react-native-masked-view. Has anyone ever seen this?

Please consider that I only have basic understanding of Android development.

Thanks in advance.

thiagobrez commented 4 years ago

Apparently I got it working by following recommendations on the jetify package.

Troubleshooting guide

You have a dependency that packages things in violation of Android packaging rules, like including an extra AndroidManifest.xml or similar: https://github.com/acaziasoftcom/react-native-bottomsheet/pull/23 - this will lead to dex merger issues about duplicate entries. Open pull requests with the libraries that do this.

I've deleted node_modules/react-native-svg/android/src/main/AndroidManifest.xml and it worked.

Any thoughts on this?

msand commented 4 years ago

Interesting, haven't seen that happen, have you tried closing the project / android studio and removing your android project .iml files and then restarting android studio > resync gradle > rebuild? Could you make a reproduction in a git repo?

thiagobrez commented 4 years ago

Hey @msand, thanks for the quick reply.

Yeah, I've tried that.

  • Already tried cleaning project, deleting .iml files, invalidating Android Studio caches, rebuilding, reinstalling node_modules and so on

Actually, my bundleRelease did pass but it froze (probably crashed) on the splash screen. So I had to give up on Android for now due to tight schedule and I'm working only on refining my iOS app.

I'll try to make a repro this weekend if I have time, but I don't really think it'll happen on a clean new project.

ali-io commented 4 years ago

i had the same exact issue, i'm not sure of the cause but here what worked with me.

npx react-native run-android --variant=release was giving me warnings:

error React Native CLI uses autolinking for native dependencies, but the following modules are linked manually: 
  - react-native-localize (to unlink run: "react-native unlink react-native-localize")
  - react-native-reanimated (to unlink run: "react-native unlink react-native-reanimated")
  - react-native-svg (to unlink run: "react-native unlink react-native-svg")
  - react-native-webview (to unlink run: "react-native unlink react-native-webview")

i unliked everyone of them, deleted the node_modules and ran yarn install again "also dont forget cd ios && opd install like i did" then everything worked

thiagobrez commented 4 years ago

Hey @msand, I'm kind of getting back to this..

I suspect there is a library that I use that is also using react-native-svg and would like to exclude it, can you tell me the group and module name? I'm not that familiar with Android and didn't figure it out.

E.g:

implementation(:my-library) {
  exclude group: 'com.hocrux.svg',module:'xxx'
}
visheshtungarev commented 4 years ago

hello I am facing the Exact same issue If anyone got the solution for this please update

thiagobrez commented 4 years ago

@visheshtungarev In my case, I had to exclude react-native-svg from react-native-jitsi-meet, that was also using the library.

I solved it by adding

implementation(project(':react-native-jitsi-meet')) {
  exclude group: 'com.facebook.react',module:'react-native-svg'
  ...
}

But I think the group path may change, this module was compiled as an external sdk.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

chrislarson commented 4 years ago

@thiagobrez did your app work fine with this library if it was built as a Release APK instead of a Release AAB? After installing this library, my Release AAB builds fine but freezes after the splash screen, yet my Release APK runs fine. Trying to narrow down whether this is the same issue you faced. Any insights appreciated.

thiagobrez commented 4 years ago

@chrislarson We're in the same page, AAB still freezing after splash screen for me. I'm afraid I got no other info for you 😕

flyskywhy commented 4 years ago

@visheshtungarev

search react-native-svg in ~/.gradle/caches , you should find something like this:

modules-2/files-2.1/com.aliyun.iot.aep.page/rn/0.3.6.1/f8da1a1f968048b95aa05063ebc156873d9d642d/rn-0.3.6.1.pom
61:      <groupId>com.aliyun.iot.sdk.external</groupId>
62:      <artifactId>react-native-svg</artifactId>

then replace your build.gradle which contains

api 'com.aliyun.iot.aep.page:rn:0.3.6.1'

with

api('com.aliyun.iot.aep.page:rn:0.3.6.1') {
    exclude group: 'com.aliyun.iot.sdk.external',module:'react-native-svg'
}
WoLewicki commented 1 year ago

Is it still an issue? Also, it does not look like a bug in the library but rather a misconfiguration of the project. I will close this issue then. Feel free to comment here if something is wrong and we can always reopen it then.