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

Room + napt = javax.annotation.processing.FilerException: Attempt to recreate a file for type #14

Closed
bacecek opened this issue Nov 8, 2022 · 4 comments · Fixed by #15

Comments

@bacecek
Copy link
Contributor

bacecek commented Nov 8, 2022

Hi!
I have applied your plugin in module with Room and got the next issue:

Preparations:
Let's assume we have module with build.gradle like this:

plugins {
    id 'com.android.application'
    id 'com.sergei-lapin.napt'
}

dependencies {
    annotationProcessor 'androidx.room:room-compiler:2.4.3'
    implementation 'androidx.room:room-runtime:2.4.3'
}

And we have the sample project from tutorial: https://developer.android.com/training/data-storage/room#java.

Steps:

  1. Successful compilation of module
  2. Make some changes to any source file
  3. Recompile the module

Result:

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> javax.annotation.processing.FilerException: Attempt to recreate a file for type app.bacecek.defaultassistant.UserDao_Impl

This build fail is not reproducing without napt plugin.

Simple example is here: https://github.com/bacecek/sample-checking-assistant-role/tree/room_FilerException.

Environment:
Napt version 1.17, JDK 11, Gradle 7.5.1, Android Gradle Plugin 7.2.1, Room 2.4.3.

I'n not sure that the main cause of this problem is this plugin so it would be great if you will help me to investigate what is the main cause and maybe to fill the issue in Google's issue tracker.

@bacecek
Copy link
Contributor Author

bacecek commented Nov 8, 2022

I'm seeing that during incremental compilation before starting annotation processing URLClassLoader.getURLs() contains not only compiled kotlin classes, but also previous compiled java classes:

ClassLoader.getURLs: [file:/Users/bacecek/work/sample-checking-assistant-role/app/build/tmp/kotlin-classes/debug/, file:/Users/bacecek/work/sample-checking-assistant-role/app/build/intermediates/javac/debug/classes/]

And @Dao annotation has CLASS retention, so that annotation processor is trying to process UserDao class twice: as java source and as class file.

From my perspective, we can try to not add classes to Arguments.instance(context).getClassNames() that already exists in Arguments.instance(context).getFileObjects(). What do you think?

UPD: This is not so easy as I expected. Maybe you have any ideas how to fix it?

@sergei-lapin
Copy link
Owner

Hey, @bacecek! Seems like targeting KotlinCompile destinationDirectory directly does the trick and fixes this incremental scenario.

@sergei-lapin
Copy link
Owner

I'll prepare new release shortly

@bacecek
Copy link
Contributor Author

bacecek commented Nov 10, 2022

Great, thank you! Now it works

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

Successfully merging a pull request may close this issue.

2 participants