Skip to content

Commit

Permalink
fix to make android annotations version 2.7 work with product flavour…
Browse files Browse the repository at this point in the history
…s on Gradle
  • Loading branch information
Anton Gravestam authored and Anton Gravestam committed Sep 26, 2013
1 parent b341012 commit 631d5e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
import java.util.Map;
import java.util.Set;

import static com.googlecode.androidannotations.rclass.ProjectRClassFinder.RESOURCE_PACKAGE_NAME_OPTION;

import javax.annotation.processing.Messager;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.SupportedOptions;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
Expand Down Expand Up @@ -318,6 +321,7 @@
OnActivityResult.class //
})
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedOptions({RESOURCE_PACKAGE_NAME_OPTION})
public class AndroidAnnotationProcessor extends AnnotatedAbstractProcessor {

private final TimeStats timeStats = new TimeStats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

public class ProjectRClassFinder {

public static final String RESOURCE_PACKAGE_NAME_OPTION = "resourcePackageName";
private ProcessingEnvironment processingEnv;

public ProjectRClassFinder(ProcessingEnvironment processingEnv) {
Expand All @@ -34,7 +35,10 @@ public ProjectRClassFinder(ProcessingEnvironment processingEnv) {
public IRClass find(AndroidManifest manifest) {

Elements elementUtils = processingEnv.getElementUtils();
String rClass = manifest.getApplicationPackage() + ".R";

// This is the hack we need to support product flavors
String rClass = getRClassPackageName(manifest) + ".R";
// String rClass = manifest.getApplicationPackage() + ".R";
TypeElement rType = elementUtils.getTypeElement(rClass);

if (rType == null) {
Expand All @@ -46,4 +50,12 @@ public IRClass find(AndroidManifest manifest) {
return new RClass(rType);
}

public String getRClassPackageName(AndroidManifest manifest) {
if (processingEnv.getOptions().containsKey(RESOURCE_PACKAGE_NAME_OPTION)) {
return processingEnv.getOptions().get(RESOURCE_PACKAGE_NAME_OPTION);
} else {
return manifest.getApplicationPackage();
}
}

}

0 comments on commit 631d5e9

Please sign in to comment.