Gradle dagger lint: ignore by package

2019-03-23 19:20发布

I've created an Android project using Gradle. I've added a dagger library

dependencies {
    compile 'com.squareup.dagger:dagger-compiler:1.2.1'
    compile 'com.squareup.dagger:dagger:1.2.1'
}

After trying to compile the project I get a build failure due to lint exceptions:

InvalidPackage: Package not included in Android

../../../../../../.gradle/caches/modules-2/files-2.1/com.squareup.dagger/dagger-compiler/1.2.1/c8bf6c2fda9b27f4d44a2aa4280df525a1408771/dagger-compiler-1.2.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from dagger.internal.codegen.GraphAnalysisErrorHandler. ../../../../../../.gradle/caches/modules-2/files-2.1/com.squareup.dagger/dagger-compiler/1.2.1/c8bf6c2fda9b27f4d44a2aa4280df525a1408771/dagger-compiler-1.2.1.jar: Invalid package reference in library; not included in Android: javax.lang.model.type. Referenced from dagger.internal.codegen.GeneratorKeys. ../../../../../../.gradle/caches/modules-2/files-2.1/com.squareup.dagger/dagger-compiler/1.2.1/c8bf6c2fda9b27f4d44a2aa4280df525a1408771/dagger-compiler-1.2.1.jar: Invalid package reference in library; not included in Android: javax.lang.model.util. Referenced from dagger.internal.codegen.GraphAnalysisErrorHandler. ../../../../../../.gradle/caches/modules-2/files-2.1/com.squareup/javawriter/2.3.0/4b290e394ea3109be5c0b7f08ff75de089125122/javawriter-2.3.0.jar: Invalid package reference in library; not included in Android: javax.lang.model.element. Referenced from com.squareup.javawriter.JavaWriter.

So, I have to either fix or make lint ignore dagger packages. I've setup lint.xml but I can't figure out a way to ignore:

 <issue id="InvalidPackage">
  <ignore ...INSERT DECLARATION TO IGNORE DAGGER PACKAGE... />
 </issue>

Thanks.

2条回答
迷人小祖宗
2楼-- · 2019-03-23 19:34

Found the answer here: https://android.googlesource.com/platform/tools/base/+/e6a5b9c7c1bca4da402de442315b5ff1ada819c7

adding in build.gradle in android section, lintOptions solved the issue for me:

android {
...

   lintOptions {
       disable 'InvalidPackage'
   }
}

adding the same ignore statement in lint.xml did not worked for me.

查看更多
Juvenile、少年°
3楼-- · 2019-03-23 19:40

FYI, as of version 0.10.1 of the Android Gradle plugin this will no longer be necessary; lint will automatically ignore these issues found within Dagger: https://android-review.googlesource.com/#/c/93140/

查看更多
登录 后发表回答