Android Gradle annotationProcessor not available in parent module

大憨熊 提交于 2019-12-14 03:49:39

问题


I'm having the following setup:

ProjectA build.gralde:

dependencies {
    compile (project(':ProjectB'))
}

ProjectB build.gradle:

dependencies {
    annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
    compile "com.google.auto.value:auto-value:1.3"
    annotationProcessor "com.google.auto.value:auto-value:1.3"
}

And SomeClass in ProjectA that is implementing Parcelable

@AutoValue
public abstract class SomeClass implements Parcelable {
...
}

AutoValue won't generate any Parcelable related methods in AutoValue_SomeClass.

However, if I include auto-value-parcel annotationProcessor directly to ProjectA, the problem is resolved.

ProjectA build.gralde:

dependencies {
    compile (project(':projectB'))
    annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
}

Can anyone explain how auto-value-parcel annotationProcessor is being excluded from ProjectA?


回答1:


annotationProcessor dependencies are not exported to other projects. Also these are not exported with libraries.

AutoValue itself works, because you defined it with a compile dependency. This is something you should not do either. So an better dependency setup would look like...

ProjectB

dependencies {
    provided "com.jakewharton.auto.value:auto-value-annotations:$autoValueVersion"
    annotationProcessor "com.google.auto.value:auto-value:$autoValueVersion"
    annotationProcessor "com.ryanharter.auto.value:auto-value-parcel:$autoValueParcelVersion"
}

ProjectA

dependencies {
    compile project(':ProjectB')
    provided "com.jakewharton.auto.value:auto-value-annotations:$autoValueVersion"
    annotationProcessor "com.google.auto.value:auto-value:$autoValueVersion"
    annotationProcessor "com.ryanharter.auto.value:auto-value-parcel:$autoValueParcelVersion"
}

But not having annotationProcessor run on all projects would be even better.



来源:https://stackoverflow.com/questions/43813900/android-gradle-annotationprocessor-not-available-in-parent-module

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