Note that there are some explanatory texts on larger screens.

plurals
  1. POGradle + Annotations + Flavors = won't run annotations processor
    primarykey
    data
    text
    <p>I have a Gradle build script that is using an annotations processor (Android Annotations) to generate code. Building was fine until I added a new <strong>Pro</strong> Flavor. I can build the <strong>Free</strong> flavor but when I build the <strong>Pro</strong> flavor the annotations processor isn't run. This causes missing code and the build fails.</p> <p>Here is my script:</p> <pre><code>buildscript { repositories { maven { url 'http://repo1.maven.org/maven2' } } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android' repositories { mavenCentral() maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } } ext.androidAnnotationsVersion = '3.0-SNAPSHOT'; configurations { apt } dependencies { compile files('libs/android-support-v13.jar') compile fileTree(dir: 'libs', include: '*.jar') apt "org.androidannotations:androidannotations:${androidAnnotationsVersion}" compile "org.androidannotations:androidannotations-api:${androidAnnotationsVersion}" } android { compileSdkVersion 17 buildToolsVersion "17.0.0" defaultConfig { minSdkVersion 7 targetSdkVersion 17 versionCode 29 versionName "2.0.3" packageName "com.MyCompany.MyApp" } productFlavors { free { buildConfig "final public static boolean PRO_VERSION = false;" } pro { packageName "com.MyCompany.MyApp.Pro" versionName (versionName + ".Pro") buildConfig "final public static boolean PRO_VERSION = true;" } } buildTypes { release { buildConfig "final public static String BASE_URL = \"http://data.MyCompany.com/\";", \ "final public static String APP_NAME = \"com.MyCompany.MyApp\";" } debug { buildConfig "final public static String BASE_URL = \"http://192.168.1.15/GDM/\";", \ "final public static String APP_NAME = \"com.MyCompany.MyApp\";" } } } def getSourceSetName(variant) { return new File(variant.dirName).getName(); } android.applicationVariants.all { variant -&gt; def aptOutputDir = project.file("build/source/apt") def aptOutput = new File(aptOutputDir, variant.dirName) println "****************************" println "variant: ${variant.name}" println "manifest: ${variant.processResources.manifestFile}" println "aptOutput: ${aptOutput}" println "****************************" android.sourceSets[getSourceSetName(variant)].java.srcDirs+= aptOutput.getPath() variant.javaCompile.options.compilerArgs += [ '-processorpath', configurations.apt.getAsPath(), '-AandroidManifestFile=' + variant.processResources.manifestFile, '-s', aptOutput ] variant.javaCompile.source = variant.javaCompile.source.filter { p -&gt; return !p.getPath().startsWith(aptOutputDir.getPath()) } variant.javaCompile.doFirst { aptOutput.mkdirs() } } </code></pre> <p>When building the <strong>free</strong> variants, the annotations processor is run as indicated by the following in the gradle output:</p> <pre><code>Note: Starting AndroidAnnotations annotation processing </code></pre> <p>When building the <strong>Pro</strong> variants, the annotations processor doesn't run, so the references to the generated code fails.</p> <p>The curious thing about this is, I found (truly by accident) that if I remove the <code>packageName "com.MyCompany.MyApp.Pro"</code> from the script....the annotations processor runs and it will build correctly. I need to update the the package name for Google Play.</p> <p>When looking in android studio, you can see that the apt (the Annotation Processing Tool) is showing the <strong>Pro</strong> version as being active even when I have the <strong>FreeDebug</strong> build variant selected. I am not sure this is indicative of a problem or if this is just a problem with the beta android studio (Android Studio version: 0.2.13). So take that with a grain of salt.</p> <p><img src="https://i.stack.imgur.com/E9UgL.jpg" alt="Build Folders in Android Studio"></p> <p>I'm new to the gradle build system but I <em>thought</em> I was getting the hang of it. I have looked at the script over and over again and I don't see why the annotations processor is not running for the <strong>pro</strong> variant. And aside from running the wrapper with the --info and --debug arguments, I don't know yet how to debug these problems.</p> <p>I've run the gradle wrapper with the <strong>-info</strong> and <strong>-debug</strong> to get extended output but there is nothing there that indicates any other error (or missing item) until it reaches the error caused by the missing generated code. So this leads me to believe it's just the fact that the androidannotations are not being run with that variant that is the root problem. (i.e. I don't think this is an error caused by something upstream and being misreported later on. I could be wrong though)</p> <p>I'm really at a loss and have been stuck with this for 2 days now.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload