Repository navigation
Android Studio and Gradle #869
Description
Activity
I don't understand why the
apt { arguments {}}part has been commented in the wiki, but it shouldn't !Correct configuration for
android-aptand AA is :apt { arguments { resourcePackageName android.defaultConfig.packageName androidManifestFile variant.processResources.manifestFile } }The AndroidManifest file is auto-discovered by recursively search in parent folders. So there is no reason to always specify the path to this file. It works pretty fine with IntelliJ and Gradle build with CLI.
However, the
apt.arguments.androidManifestFileis here to resolve this cases where AndroidManifest couldn't be find.@tbruyelle & @theDazzler > Could you give us your projects hierarchy to understand why you need to specify
androidManifestFile? Also, you should have anandroidannotations.logfile in your output folder. A copy/paste may be useful too ;)The AndroidManifest file is auto-discovered by recursively search in parent folders. So there is no reason to always specify the path to this file. It works pretty fine with IntelliJ and Gradle build with CLI.
You mean AA is able to find the correct manifest, according to the current build variant (with Android NBS, final manifest are located in
build/manifests/<build-variant>/AndroidManifest.xml).
That's something new, last time I looked at the sources (some months ago), AA just looked at the root folder.@tbruyelle & @theDazzler > Could you give us your projects hierarchy to understand why you need to specify androidManifestFile ? Also, you should have an androidannotations.log file in your output folder. A copy/paste may be useful too ;)
I use the standard NBS hierarchy, I have a manifest pattern in
src/main/, but the final manifests are inbuild/manifests/<build-variant>.I tried to remove the
apt.arguments.androidManifestFiletconfiguration, and it just doesn't work :error: 10:01:18.84 [main] ERROR o.a.h.AndroidManifestFinder:134 - Could not find the AndroidManifest.xml file, going up from path [/Users/tbruyelle/projects/myproject/app/build/source/apt/debug] found using dummy file [] (max atempts: file:///Users/tbruyelle/projects/myproject/app/build/source/apt/debug/dummy1389344478084.java)Ok, we don't work with the same type of project structure :)
I still fit maven hierarchy and my
AndroidManifestis in root folder. As AA was originally designed for this, we're looking at the root folders.I just did some tests and we should always specify
androidManifestFilelike you suggested. ButresourcePackageNamemay not be override with flavors and in this case your config will crash because this argument will receivenull.I think we should update the wiki with this :
apt { arguments { androidManifestFile variant.processResources.manifestFile // uncomment the following line if you redefine packageName in flavors // resourcePackageName android.defaultConfig.packageName } }WDYT ?
The problem with removing
resourcePackageNameis when you use thepackageNameSuffixfeature of NBS [1]. This feature is very useful and I think very used by NBS users, because it allows you to deploy different versions of the same application on the same device (for me it was the feature which make me switch from maven to NBS!).So with
packageNameSuffix, the package name may be different from the resource file package. For instance if I have the following configuration for the debug build :android { buildTypes { debug { packageNameSuffix ".debug" } }AA will fail with that error :
ERROR o.a.r.ProjectRClassFinder:44 - The generated com.myproject.debug.R class cannot be foundIf you don't define your package in
android.defaultConfig(it's not mandatory, as it's already defined in the manifest), you can hard declare it :apt { arguments { androidManifestFile variant.processResources.manifestFile resourcePackageName 'com.myproject' } }[1] http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Types
Reacted by zhangzhenfang and JasonI understand your point, but you're still talking of a project with custom config. I don't know if it's the case for most of the projects out there.
I don't really like to duplicate package name here, that's why I suggested to keep default behavior by leaving the config commented.However, I'll update the wiki and try to explain all of this :)
It should be better now.
@theDazzler > Could you update your config and tell us if it works now.
This seems to work fine. I'm closing this issue then
I will try it when I get home.
I tried a few different solutions as suggested and none of them work. Here is my build.gradle:
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.7.+' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.1' } } apply plugin: 'android' repositories { mavenCentral() mavenLocal() } apply plugin: 'android-apt' def AAVersion = '3.0' dependencies { compile 'com.android.support:appcompat-v7:+' apt "org.androidannotations:androidannotations:$AAVersion" compile "org.androidannotations:androidannotations-api:$AAVersion" } apt { arguments { androidManifestFile variant.processResources.manifestFile resourcePackageName 'com.anno.test' // If you're using Android NBS flavors you should use the following line instead of hard-coded packageName // resourcePackageName android.defaultConfig.packageName // You can set optional annotation processing options here, like these commented options: // logLevel 'INFO' // logFile '/var/log/aa.log' } } android { compileSdkVersion 19 buildToolsVersion "19.0.0" defaultConfig { minSdkVersion 7 targetSdkVersion 19 versionCode 1 versionName "1.0" } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['res'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } } }It gives this error: "Main manifest missing from ../Annoation_test/app/AndroidManifest.xml". Then I changed the sourceSets to this:
sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src/res'] res.srcDirs = ['src/res'] assets.srcDirs = ['assets'] } }which gives these errors:
No resource found that matches the given name (at 'icon' with value '@drawable/ic_launcher'). No resource found that matches the given name (at 'label' with value '@string/app_name'). No resource found that matches the given name (at 'theme' with value '@style/AppTheme'). No resource found that matches the given name (at 'label' with value '@string/app_name').My project structure is the standard Android Studio project structure. I just made a new app and edited my build.gradle file, that's all.
It gives this error: "Main manifest missing from ../Annoation_test/app/AndroidManifest.xml".
Strange error, because giving your configuration
androidManifestFile variant.processResources.manifestFile, the manifest path should be more something likebuild/manifests/<build-variant>/AndroidManifest.xml.sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src/res'] res.srcDirs = ['src/res'] assets.srcDirs = ['assets'] } }This is not the standard project structure : http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Project-Structure
From the screenshot yes it's standard structure, and so you dont need to redefine the sourcesets (moreover you redefined them badly, for instance
resources.srcDirs = ['src/res']is not correct, correct value isresources.srcDirs = ['src/main/res'])How do you build your project. From Android Studio ? Did you try from command line with a simple
./gradlew app:assembleDebug?Bumped into the same issue, the "androidManifestFile variant.processResources.manifestFile" resolved it. Thank you.
I changed my build file to use this for srcSets:
sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' java.srcDirs = ['src/main/java'] resources.srcDirs = ['src/main/res'] res.srcDirs = ['src/main/res'] assets.srcDirs = ['assets'] } }It took away the compile errors but none of the annotations are available in my app. For example, if I try to use @EActivity, it doesn't ask to import it.
I build my project using android studio. I ran ./gradlew app:assembleDebug and got:
:app:compileDebugNdk UP-TO-DATE :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV71900Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:compileDebugJava UP-TO-DATE :app:preDexDebug UP-TO-DATE :app:dexDebug UP-TO-DATE :app:processDebugJavaRes UP-TO-DATE :app:validateDebugSigning :app:packageDebug UP-TO-DATE :app:assembleDebug UP-TO-DATE BUILD SUCCESSFUL

I'm trying to get AA to work in Android Studio using Gradle and nothing seems to work. This is the error I'm getting:
: 20:21:07.345 [Daemon] ERROR o.a.h.AndroidManifestFinder:134 - Could not find the AndroidManifest.xml file, going up from path
This is a brand new android project. I haven't done anything except try to get AA working.
Here is my build.gradle file
I've tried changing the paths in the sourcesets but it doesn't work. How can I get this to work with Android Studio? The code in the wiki for Gradle does not work