8

When building a signed release APK I'm getting following error:

.gradle/caches/transforms-2/files-2.1/532a317ccd54c8ae4f622faeb8b534a9/jetified-wordup-core-0.2.1-runtime.jar:de/codereddev/wordup/database/WordDao_Impl$5.class,
Type de.codereddev.wordup.database.WordDao_Impl$5 is defined multiple times:
/home/codered_dev/.gradle/caches/transforms-2/files-2.1/532a317ccd54c8ae4f622faeb8b534a9/jetified-wordup-core-0.2.1-runtime.jar:de/codereddev/wordup/database/WordDao_Impl$5.class,
/home/codered_dev/MySoundboardApp/app/build/intermediates/javac/release/classes/de/codereddev/wordup/database/WordDao_Impl$5.class

This Room DAO definition comes from a library I created myself.

Looking into the .jar file I can find this:

enter image description here

This only happens on release. I can still build and run debug without any problems.

Unfortunately I can't find the error. Hopefully anyone here might have a hint for me.

I first assumed it might be due to the fact that the library contains a standard definition of a Room database and my application using the library contains its own custom definition holding the same DAOs. So annotation processors would maybe process the DAOs twice. But I couldn't check this properly.

If it's important to know: I'm also using Koin for dependency injection.

CodeRed
  • 481
  • 4
  • 17
  • 1
    Hi, I work on the R8 team, and have a question. The message you have quoted above (`Type de.codereddev.wordup.database.WordDao_Impl$5 is defined multiple times: /home/codered_dev/.gradle/caches/transforms-2/files-2.1/532a317ccd54c8ae4f622faeb8b534a9/jetified-wordup-core-0.2.1-runtime.jar:de/codereddev/wordup/database/WordDao_Impl$5.class,`) ends with a `,`. There should be a reference to the second class where the definition was also found. Can you double-check if there is a second class reference in the error message? – sgjesse Jul 27 '20 at 09:22
  • @sgjesse I've edited my post to the extended error message. – CodeRed Jul 27 '20 at 11:34
  • 1
    The update shows that the class `de.codereddev.wordup.database.WordDao_Impl$5` is in 1) the dependency `jetified-wordup-core-0.2.1-runtime` and in the app code itself `app/build/intermediates/javac/release/classes/de/codereddev/wordup/database/WordDao_Impl$5.class`. For R8 there can be no duplicate classes. Most likely you will need to not have DAOs defined twice. – sgjesse Aug 05 '20 at 11:51
  • Could it be that because in the framework there is a `RoomDatabase` (RD) definition containing a getter for the DAO aswell as the app has it's own definition of a RD that also contains the getter for the DAO? Otherwise this wouldn't make sense as there is no definition of the DAO class in the app. – CodeRed Aug 06 '20 at 13:26

3 Answers3

3

Unfortunately I don't exactly know the reason but I got the library working by removing the Room kaptCompiler from the library and instead only have it in the app that is using the library.

CodeRed
  • 481
  • 4
  • 17
1

This can happen if the same package is used by different module, e.g. a library and the app using the library both using org.foo.bar as package. If different packages are used, the error will go away.

k_o_
  • 5,143
  • 1
  • 34
  • 43
0

I solved this problem:

In my lib-base, I have a WordDao(baseDatabase),

abstract fun dao(): WordDao

but in my module-word(wordDatabase), there is also one

abstract fun dao(): WordDao

So, after I delete the abstract fun dao(): WordDao in module-word,I solved this problem

pnkj
  • 406
  • 5
  • 17