Android R class 在使用 Android Gradle 插件 3.6.2 的注释处理期间不可用
Android R class not available during annotation processing with Android Gradle plugin 3.6.2
我有一个库,它使用注释处理来创建用于在此处获取资源的 API:
https://github.com/Comcast/resourceprovider
我刚刚将 android gradle 插件从 3.2.1 更新到 3.6.2,突然在注释处理轮次期间找不到 R class。
查找 R class 的代码在过程函数中:
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(RpApplication.class)) {
// annotation is only allowed on classes, so we can safely cast here
TypeElement annotatedClass = (TypeElement) annotatedElement;
if (!isValidClass(annotatedClass)) {
continue;
}
try {
List<String> rStringVars = new ArrayList<>();
List<String> rPluralVars = new ArrayList<>();
List<String> rDrawableVars = new ArrayList<>();
List<String> rDimenVars = new ArrayList<>();
List<String> rIntegerVars = new ArrayList<>();
List<String> rColorVars = new ArrayList<>();
List<String> rIdVars = new ArrayList<>();
//lame. this assumes that the application class is at the top level. find a better way.
String packageName = getPackageName(processingEnv.getElementUtils(), annotatedClass);
String rClassName = packageName + R_CLASS_IDENTIFIER;
boolean generateIdProvider = annotatedElement.getAnnotation(RpApplication.class).generateIdProvider();
boolean generateStringProvider = annotatedElement.getAnnotation(RpApplication.class).generateStringProvider();
boolean generateColorProvider = annotatedElement.getAnnotation(RpApplication.class).generateColorProvider();
boolean generateDrawableProvider = annotatedElement.getAnnotation(RpApplication.class).generateDrawableProvider();
boolean generateIntegerProvider = annotatedElement.getAnnotation(RpApplication.class).generateIntegerProvider();
boolean generateDimensionProvider = annotatedElement.getAnnotation(RpApplication.class).generateDimensionProvider();
roundEnv.getRootElements().stream().filter(element -> element instanceof TypeElement).forEach(element -> {
TypeElement typeElement = (TypeElement) element;
if (typeElement.getQualifiedName().toString().equals(rClassName)) {......}
而且我从来没有进入过那个街区。 Android Gradle 插件 3.5.0 一切正常。
如有任何帮助,我们将不胜感激。
如问题所述:https://issuetracker.google.com/issues/153964091
暂时可以用android.generateRJava=true
强制Rclass生成。但是,这将在 AGP 4.1
中删除
我有一个库,它使用注释处理来创建用于在此处获取资源的 API:
https://github.com/Comcast/resourceprovider
我刚刚将 android gradle 插件从 3.2.1 更新到 3.6.2,突然在注释处理轮次期间找不到 R class。
查找 R class 的代码在过程函数中:
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(RpApplication.class)) {
// annotation is only allowed on classes, so we can safely cast here
TypeElement annotatedClass = (TypeElement) annotatedElement;
if (!isValidClass(annotatedClass)) {
continue;
}
try {
List<String> rStringVars = new ArrayList<>();
List<String> rPluralVars = new ArrayList<>();
List<String> rDrawableVars = new ArrayList<>();
List<String> rDimenVars = new ArrayList<>();
List<String> rIntegerVars = new ArrayList<>();
List<String> rColorVars = new ArrayList<>();
List<String> rIdVars = new ArrayList<>();
//lame. this assumes that the application class is at the top level. find a better way.
String packageName = getPackageName(processingEnv.getElementUtils(), annotatedClass);
String rClassName = packageName + R_CLASS_IDENTIFIER;
boolean generateIdProvider = annotatedElement.getAnnotation(RpApplication.class).generateIdProvider();
boolean generateStringProvider = annotatedElement.getAnnotation(RpApplication.class).generateStringProvider();
boolean generateColorProvider = annotatedElement.getAnnotation(RpApplication.class).generateColorProvider();
boolean generateDrawableProvider = annotatedElement.getAnnotation(RpApplication.class).generateDrawableProvider();
boolean generateIntegerProvider = annotatedElement.getAnnotation(RpApplication.class).generateIntegerProvider();
boolean generateDimensionProvider = annotatedElement.getAnnotation(RpApplication.class).generateDimensionProvider();
roundEnv.getRootElements().stream().filter(element -> element instanceof TypeElement).forEach(element -> {
TypeElement typeElement = (TypeElement) element;
if (typeElement.getQualifiedName().toString().equals(rClassName)) {......}
而且我从来没有进入过那个街区。 Android Gradle 插件 3.5.0 一切正常。
如有任何帮助,我们将不胜感激。
如问题所述:https://issuetracker.google.com/issues/153964091
暂时可以用android.generateRJava=true
强制Rclass生成。但是,这将在 AGP 4.1