AutoService comment could not be generated META-INF file

background

In writing annotation processors, the first is to inherit AbstractProcessor, and declare the following steps:

  • You need to create resources in the main resource file folder library catalog processors;

  • Establish META-INF folder in the resources / services directory folder;

  • Javax.annotation.processing.Processor create files in the META-INF / services directory folder;

  • Full name is written in the comment processor javax.annotation.processing.Processor file, a packet including path;

Such statements down too much trouble? This is by reason of the introduction of auto-service.

Add comments at the top of the class: @AutoService (Processor.class), this annotation processor is developed by Google, it can be used to generate META-INF / services / javax.annotation.processing.Processor file information.

Use the problems encountered

Our use of imported auto-service library module_processor in;

implementation 'com.google.auto.service:auto-service:1.0-rc6'

In the top class of notes to add service:

@AutoService(Processor.class)
public class BindViewProcessor extends AbstractProcessor {
 ...}

After compiling the project there has never been generated META-INF directory is normal is generated in the directory module_processor the annotation processor project / build / classes / java / main / META-INF.

Solution one:

Some say the problem is the version of gradle

(1) The original build.gradle in the root directory of the dependent gradle version 3.5.3 instead

dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

gradle version (2) and gradle-wrapper.properties file is modified version of an earlier version 4.X

Option One I have not tried, I do not know whether feasible, but also to change gradle versions may impact on the original project will be.

Option Two: to continue to use gradle5.4.1 version:

Since Gradle 5.0 ignores the compile classpath annotationProcessor, it is necessary to add manually AnnotationProcessor 'com.google.auto.service: auto-service: 1.0 -rc6' to annotation processor path as follows:

implementation 'com.google.auto.service:auto-service:1.0-rc6'
annotationProcessor 'com.google.auto.service:auto-service:1.0-rc6'

Gradle complete script:

apply plugin: 'java-library'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.auto.service:auto-service:1.0-rc6'
    annotationProcessor 'com.google.auto.service:auto-service:1.0-rc6'
    implementation 'com.squareup:javapoet:1.10.0'
    implementation project(':module_annotation')
}

sourceCompatibility = "7"
targetCompatibility = "7"

When finished, the next re-compiled, you can see the META-INF files become cooked:

Guess you like

Origin blog.csdn.net/cpcpcp123/article/details/103871815