0

I have been working on a project for a couple of months integrating gstreamer to a basic react-native Android app. The starting point was react-native-gstreamer but with a number of modifications to the gstreamer pipeline etc.

My debug builds (created with yarn android or ./gradlew assembleDebug) have been working reliably, on emulated and real devices, but I can't get a release build / signed APK ./gradlew assembleRelease to work. The build scan showing the error (created with ./gradlew assembleRelease --scan, doesn't appear to contain any sensitive information?) is at scans.gradle.com. The error I am stuck on is

C:\Temp\MyApp\app\intermediates\project_dex_archive\release\out\org\freedesktop\gstreamer\GStreamer.dex: D8: Type org.freedesktop.gstreamer.GStreamer is defined multiple times: C:\Temp\MyApp\app\intermediates\project_dex_archive\release\out\org\freedesktop\gstreamer\GStreamer.dex, C:\Temp\MyApp\react-native-gstreamer.transforms\b22258b54d8d354026f3fb18b0251db4\transformed\classes\classes.dex 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.

I'm new to Android development (experienced C++/Python mainly), so I could be missing something obvious, this seems to be a common issue (see below) but the link in the error doesn't help me and the solutions I have found have not worked.

The most likely cause that I can't pin down is some sort of dependency clash, similar to this issue also, but I don't have lots of dependencies, it seems specifically related to gstreamer, and I don't know where to dig further to find the clash.

./gradlew app:dependencies doesn't show any obviously bad dependencies. react-native-gstreamer has a dependency on com.facebook.react:react-native:+ -> 0.63.4 (*) and doesn't appear in any other context in the dependencies (i.e. the above dependency appears a few times in the output, but react-native-gstreamer isn't a dependency of other packages and doesn't have other dependencies and there are no other occurrences of gstreamer)

Similar errors elsewhere on stackoverflow and solutions which I have unsuccessfully tested:

  • Delete gradle folder - fault still occurs
  • Enable multiDex in build.gradle - fault still occurs (note minSdkVersion is set to 21, so some messages suggest this should not be necessary, but tried anyway)
  • Similar to this but I am not aware of any dependency
  • ./gradlew clean and ./gradlew assembleRelease - fault still occurs
  • Various solutions
    • look at the path given in AS, it should point to \app\build\intermediates\project_dex_archive\debug\out. Go to this path, delete all the *.jar files, leaving the most recent one - fault still occurs (removed file is recreated on next build)
    • Delete the build directory (C:/Temp/MyApp above) - fault still occurs
  • Multidex changes - it looks like this is now outdated for minSdkVersion >= 21, no upvotes and one comment that it didn't fix the original poster's problem, not tested.
rolinger
  • 665
  • 7
  • 17
  • 1
    `C:\Temp\MyApp\app\intermediates\project_dex_archive\release\out\org\freedesktop\gstreamer\GStreamer.dex` - the `project_dex_archive` folder generally contains output artifacts which were built from project source files. Is it possible that your `app` module contains `GStreamer.java` source file? If yes - then it might be the root cause of the conflict, since you're most likely have similar artifact which comes from a third party dependency (`react-native-gstreamer.transforms\b22258b54d8d354026f3fb18b0251db4\transformed\classes\classes.dex`). – Alex Lipov Dec 21 '21 at 19:10
  • The instructions I followed for linking included copying GStreamer.java into the react-native-gstreamer folder so thanks @AlexLipov you're exactly right I have a copy of it in my project, would that be different between debug and release builds? Should I just be able to delete the copied across GStreamer.java file? Or reference the one in the binary Android build? Or delete the supplied ones in the Android build? – rolinger Dec 21 '21 at 22:44
  • 1
    I would expect `debug` builds to fail on this as well, perhaps the `release` variant performs stricter validations. I'm not familiar with this library and with a way you're expected to integrate it in your project - but you should definitely have the class either in your source files or in your dependencies, not both. – Alex Lipov Dec 22 '21 at 07:30
  • 1
    Found the duplicate, I had followed https://stackoverflow.com/questions/45044210/gstreamer-examples-in-android-studio/46223465#46223465 and copied GStreamer.java manually to the top level, which was clashing with the automatically sed'ed version from the gstreamer Android build makefile. @AlexLipov if you would like to post the above as an answer I'll mark it as accepted. – rolinger Jan 11 '22 at 16:08

1 Answers1

1

The error message mentions two dex sources which contain the org.freedesktop.gstreamer.GStreamer class:

  • C:\Temp\MyApp\app\intermediates\project_dex_archive\release\out\org\freedesktop\gstreamer\GStreamer.dex
  • C:\Temp\MyApp\react-native-gstreamer.transforms\b22258b54d8d354026f3fb18b0251db4\transformed\classes\classes.dex

First source's project_dex_archive folder generally contains output artifacts which were built from project source files. Is it possible that your app module contains GStreamer.java source file?
If yes - then it might be the root cause of the conflict, since you're most likely have similar artifact packaged in a third party dependency (the second dex source: react-native-gstreamer).

Alex Lipov
  • 13,503
  • 5
  • 64
  • 87