Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android builds fails due to duplicate class with react-native-random-uuid #44

Open
Adnan-Bacic opened this issue Apr 18, 2023 · 2 comments

Comments

@Adnan-Bacic
Copy link

Adnan-Bacic commented Apr 18, 2023

ive been looking into generating random values in react-native. i found this library at first and used it together with the uuid library. i then saw this issue: #32

where someone suggested to add crypto.randomUUID() too. to keep the library clean, you made a new library: https://github.com/LinusU/react-native-random-uuid

i then installed that library to try it as well. then when i build the android app the build fails and i get an error like this:

* What went wrong:
Execution failed for task ':app:mergeLibDexDevelopmentDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingTaskDelegate
   > There was a failure while executing work items
      > A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingWorkAction
         > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
           Type org.linusu.BuildConfig is defined multiple times: /Users/adb/dev/APP_NAME/node_modules/react-native-get-random-values/android/build/.transforms/aa2fd757f1fb328047e3f797775fb731/transformed/classes/classes.dex, /Users/adb/dev/APP_NAME/node_modules/react-native-random-uuid/android/build/.transforms/ce3394d28852a5322f9e5e76c2b08d87/transformed/classes/classes.dex
           Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

with a link to: https://developer.android.com/build/dependencies?buildsystem=ndk-build#duplicate_classes

i think the problem lies here:

Type org.linusu.BuildConfig is defined multiple times

i dont know if this value can even be changed. i know some package names cannot be changed after they have been released.

this may not be a problem realistically, as there may not be a reason to have both libraries installed at the same time. i was just experimenting to see how they worked.

the build was also successful as soon as a deleted react-native-get-random-values.

also as a sidenote, im not sure if this is also the case for ios. i currently have some unrelated problems with some ios pods which means i cant even install pods successfully. maybe someone else can test it out to see if it also happens on ios.

@LinusU
Copy link
Owner

LinusU commented Apr 18, 2023

This is very interesting, thank you for reporting this!

I cannot find the string org.linusu.BuildConfig inside the repository, so I'm guessing that this is something that is generated 🤔

I would be very happy to receive more insight on this!

@Adnan-Bacic
Copy link
Author

Adnan-Bacic commented Apr 19, 2023

the earliest reference to BuildConfig i can find was added in version 0.68 of react-native: https://react-native-community.github.io/upgrade-helper/?from=0.67.5&to=0.68.0

though as you say, that string is most likely autogenerated. its also located in the build/ folder as shown in the error.

i think the real problem lies in duplicate package names. both the libraries have package="org.linusu" in the AndroidManifest.xml file. react-native just seems to concatenate the package name with .BuildConfig during the build.

every android app on a device must have a unique package name, and an app package names cannot be changed, as a phone would treat it as a new app.(https://developer.android.com/build/configure-app-module#set-application-id).

im unsure if libraries are also bound to the package names the same way that apps are after they have been published(i assume they are not). but the libraries should have unique package names. if its not possible to change it, my only other guess would be to make a new package of one of the libraries with a unique package name and update the docs to tell people to switch to the new one.

its a good idea to add projectname, instead of just the domain, in the package name, to make sure they are unique. ideally, i guess they could have package names along the lines of:
package="org.linusu.react-native-get-random-values"
package="org.linusu.react-native-random-uuid"

update:

i just tried manually editing the package name in react-native-get-random-uuid and the project builds successfully now.

i changed org.linusu in 3 files:

react-native-get-random-values/android/src/main/AndroidManifest.xml
react-native-get-random-values/android/src/main/java/org/linusu/RandomUuidModule.java
react-native-get-random-values/android/src/main/java/org/linusu/RandomUuidPackage.java

i tried doing the same thing for this package and also moved the 2 .java files to a new folder in the linusu folder, to match the new package name. this throws an error which i am currently looking in to.

i think the error is just related to the build/ folder in the libraries which still refer to the previous paths. when i deleted the libraries build/ folder, i could run my project again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants