How do I use custom Java Annotation Processor in Gradle?

血红的双手。 提交于 2019-12-05 07:56:49

there's a plugin to make it work. It works perfectly with modules that are on Maven, not sure about local .jar files, but you sure give it a try:

here the plugin page: https://bitbucket.org/hvisser/android-apt

and here my build.gradle with it:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        ... add this classpath to your buildscript dependencies
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt' << apply the plugin after the android plugin

dependencies {
    // in dependencies you call it
    apt 'com.company.myAnnotation:plugin:1.0-SNAPSHOT'
    compile 'com.company.myAnnotation:api:1.0-SNAPSHOT'

and it should work.

Use the android-apt plugin. Better yet, fork a sample project that already uses the android-apt plugin for developing local annotation processors.

Read about the sample project here.

what you are doing is perfectly right, here is an example of one of my projects that I use as a library:

dependencies {
    compile project(':boundservice')
}

of course what you should do also is to define the module you added your library as

android-library plagin and not application.

This should happen automatically if you do it using the New Module -> Android Library option, but maybe as this project, as I understand... has nothing to do with Android you should just chose the Java Library option.

When you do that and sync the build.gradle file (maybe a little clean build should help as well) you should be able to use your class files in the Android project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!