diff --git a/AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/AndroidAnnotationProcessor.java b/AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/AndroidAnnotationProcessor.java index f51b159ab5..70c9dc469f 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/AndroidAnnotationProcessor.java +++ b/AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/AndroidAnnotationProcessor.java @@ -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; @@ -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(); diff --git a/AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/rclass/ProjectRClassFinder.java b/AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/rclass/ProjectRClassFinder.java index 63b702dd32..2737b1bb2c 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/rclass/ProjectRClassFinder.java +++ b/AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/rclass/ProjectRClassFinder.java @@ -25,6 +25,7 @@ public class ProjectRClassFinder { + public static final String RESOURCE_PACKAGE_NAME_OPTION = "resourcePackageName"; private ProcessingEnvironment processingEnv; public ProjectRClassFinder(ProcessingEnvironment processingEnv) { @@ -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) { @@ -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(); + } + } + }