Reputation: 1678
I am integrating andoirdannotations into a gradle build process into a generic android project. When I attempt to build the project with the addition of apply plugin: 'androidannotations
I get the following failure:
$ gradle clean
FAILURE: Build failed with an exception.
* What went wrong:
Main Manifest missing from /tmp/RunTest/src/main/AndroidManifest.xml
Note(1): I want to maintain the generic android project structure. Note(2): I have successfully build/cleaned this project without the androidannotations plugin
build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.3'
classpath 'net.ealden.gradle.plugins:gradle-androidannotations-plugin:0.3.0'
}
}
apply plugin: 'android'
apply plugin: 'androidannotations'
repositories {
mavenCentral()
}
android {
def target = 'android-21'
def androidAnnotationsVersion = '2.7.1'
sourceSets {
main {
manifest {
srcFile 'AndroidManifest.xml'
}
java {
srcDir 'src'
}
res {
srcDir 'res'
}
assets {
srcDir 'assets'
}
resources {
srcDir 'src'
}
}
test {
java {
srcDir 'tests/src'
}
}
}
}
So, I've bailed out on trying to maintain the generic android project structure and forced the project directory structure into the structure noted here: http://tools.android.com/tech-docs/new-build-system/using-the-new-build-system.
As expected this resolved my Main Manifest missing from /tmp/RunTest/src/main/AndroidManifest.xml
however I am still getting no joy.
Now I am getting:
MyBox:RunTest $ gradle clean
Download http://repo1.maven.org/maven2/net/ealden/gradle/plugins/gradle-androidannotations-plugin/0.3.0/gradle-androidannotations-plugin-0.3.0.pom
Download http://repo1.maven.org/maven2/org/gradle/api/plugins/gradle-android-plugin/1.1.0/gradle-android-plugin-1.1.0.pom
Download http://repo1.maven.org/maven2/net/ealden/gradle/plugins/gradle-androidannotations-plugin/0.3.0/gradle-androidannotations-plugin-0.3.0.jar
Download http://repo1.maven.org/maven2/org/gradle/api/plugins/gradle-android-plugin/1.1.0/gradle-android-plugin-1.1.0.jar
FAILURE: Build failed with an exception.
* What went wrong:
Cannot add task ':processTestResources' as a task with that name already exists.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 9.28 secs
Upvotes: 0
Views: 3420
Reputation: 11329
To integrate Android Annotations into your project add the following to your project's build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
// other classpathes like gradle here, in my case
classpath 'com.android.tools.build:gradle:1.1.0'
// APT Dependency for annotation processing
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
Then apply not androidannotation as plugin but 'android-apt' in your module's build.gradle
// apply apt plugin from global gradle file
apply plugin: 'android-apt'
and also add the following to the build file:
// Tell apt where to find sources
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
// adjust the path to your module here
resourcePackageName 'de.company.app'
}
}
dependencies {
// Android Anotations for clean and readable code
apt "org.androidannotations:androidannotations:3.2"
compile 'org.androidannotations:androidannotations-api:3.2'
}
Then you should be able to use Android Annotations in your project. To keep an eclipse based project structure you can adjust the folders as you already did:
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Upvotes: 2
Reputation: 341
As an example you can look at the build.gradle file from
https://github.com/ealden/android-annotations-idea-test/blob/master/build.gradle
Upvotes: 0
Reputation: 3122
Upvotes: 1
Reputation: 28529
Looks like the androidannotations plugin applies the full Java gradle plugin that creates a processTestResources task which collides with the task we are trying to create.
It's unfortunate that we used the same name, but really you do not want to apply the full Java plugin to a project using the android plugin. The android plugin only applies the base Java plugin (which provides the ability to create Java compilation tasks but does not create the default ones created by the full Java plugin).
To be honest, our plugin does things very very differently from the regular Java and plugins that are meant to extend Java projects won't work on android projects (yet).
The first error you got looks like an issue we've had (but are having trouble reproducing) where some exception got thrown but Gradle ignored it, skipped evaluating the rest of the DSL, and kept going to trying to build. Since the sourceSets remapping was skipped, it's looking in the wrong place for the Manifest.
Upvotes: 2