Issue
I have a library that uses Annotation Processing to create APIs for getting Resources here:
https://github.com/Comcast/resourceprovider
I just updated the android gradle plugin from 3.2.1 to 3.6.2 and suddenly the R class is not being found during Annotation Processing Rounds.
The code to find the R class is in the process function:
@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)) {......}
And I never get into that block. Everything works fine with Android Gradle Plugin 3.5.0.
Any help would be appreciated.
Solution
As stated in the issue: https://issuetracker.google.com/issues/153964091
temporarily, we can use android.generateRJava=true
to force R class generation. However, this will be removed in AGP 4.1
Answered By - M Dapp
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.