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

How to use KSP Processor provider on custom android library? #2000

Closed
dayo05 opened this issue Jul 15, 2024 · 2 comments
Closed

How to use KSP Processor provider on custom android library? #2000

dayo05 opened this issue Jul 15, 2024 · 2 comments

Comments

@dayo05
Copy link

dayo05 commented Jul 15, 2024

Hi I'm trying to write custom annotation processor on AAR(android library).

When I use without android-library gradle plugin then it works fine. But when I enable it then I got error described on #1333.

It seems the resource file of android library compressed twice(lib.aar -> classes.jar -> META-INF). Is there any other solution to resolve it or how to write custom processor with android library?

@danysantiago
Copy link
Member

KSP processor are run as part of the compilation of a project, in the host machine. Meanwhile AAR is the artifact of an Android library meant to be part of an application that runs in the Android device. Therefore putting the processor in the AAR and as part of an android library does not make sense.

You should have two different artifacts:

  1. The android library containing the runtime code and likely the annotations
  2. The annotation processor library containing the KSP processor and the META-INF file.

Your consumers would then depend on both artifacts and essentially use your library and processor.

For example, Room has its room-runtime artifacts containing the annotations and room-compiler containing the KSP processor.

@dayo05
Copy link
Author

dayo05 commented Jul 26, 2024

KSP processor are run as part of the compilation of a project, in the host machine. Meanwhile AAR is the artifact of an Android library meant to be part of an application that runs in the Android device. Therefore putting the processor in the AAR and as part of an android library does not make sense.

You should have two different artifacts:

  1. The android library containing the runtime code and likely the annotations
  2. The annotation processor library containing the KSP processor and the META-INF file.

Your consumers would then depend on both artifacts and essentially use your library and processor.

For example, Room has its room-runtime artifacts containing the annotations and room-compiler containing the KSP processor.

Thanks it was lead from my misunderstanding :)

@dayo05 dayo05 closed this as completed Jul 26, 2024
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