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

Type fyi.fax.klassindex.SubclassIndex is defined multiple times #65

Open
albertvaka opened this issue Oct 13, 2024 · 4 comments
Open

Type fyi.fax.klassindex.SubclassIndex is defined multiple times #65

albertvaka opened this issue Oct 13, 2024 · 4 comments

Comments

@albertvaka
Copy link

albertvaka commented Oct 13, 2024

I get this error when building https://github.com/KDE/kdeconnect-android/

One definition seems to be in the library-4.1.0.jar:fyi/fax/klassindex/SubclassIndex.class
and the other in build\intermediates\classes\release\transformReleaseClassesWithAsm\dirs\fyi\fax\klassindex\SubclassIndex.class

I see that the second instance (generated) is meant to override the first (bundled, throws AnnotationNotProcessedException if used) but for some reason gradle is not overriding them, just failing.

Any idea what could be causing this?

Edit: This error is printed in the minifyReleaseWithR8 step of the build, so when the minification happens. If I disable minification, it works.

Edit 2: I found the code of R8 where the defined multiple times error is thrown: https://r8.googlesource.com/r8/+/refs/heads/main/src/main/java/com/android/tools/r8/utils/ProgramClassCollection.java#98

@matfax
Copy link
Owner

matfax commented Oct 17, 2024

Thanks for reporting this and providing me with a source. I will investigate it.

@albertvaka
Copy link
Author

albertvaka commented Nov 30, 2024

Any idea how to fix this? I'm thinking it might be better to not provide those placeholder classes that cause the conflict. Actually, I think we could even direct people to use the generated classes directly and not provide the klassindex:library at all. What do you think?

@matfax
Copy link
Owner

matfax commented Nov 30, 2024

I think the issue was that the placeholder class is necessary for compile time or at least IDE checks to not complain about the missing class. I'm hoping that ksp will make this redundant, so that generated classes are properly recognized without a placeholder, eliminating the minimization conflict from R8. Btw, if the generated classes are in the class index with the newer Gradle versions, there's no need to include the :library.

There might be other workarounds with Gradle, to manually delete the placeholders at the right time so that the IDE relies on the placeholder while R8 is only presented with the generated index class.

I'm about halfway through the ksp migration. The end of next week will be a convenient time to return to this.

@albertvaka
Copy link
Author

albertvaka commented Dec 3, 2024

I've ended up building an alternative with KSP support and without the need of the runtime library part: https://github.com/albertvaka/classindexksp

Feel free to copy-paste as much as you want if you decide to add KSP support to KlassIndex :)

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