Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Android Studio and Gradle #869

Description

@theDazzler

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

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
        // the latest version of the android-apt plugin
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.1'
    }
}

repositories {
    mavenCentral()
}

apply plugin: 'android'
apply plugin: 'android-apt'
def AAVersion = '3.0'

dependencies {
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}

apt {
    arguments {
        // you can set annotation processing options here, like these commented options:
        // logLevel 'INFO'
        // androidManifestFile 'path to file'
    }
}

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 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            resources.srcDirs = ['src/main/res']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['assets']
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}

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

Activity

  1. tbruyelle commented on Jan 10, 2014

    @tbruyelle
    Contributor

    I don't understand why the apt { arguments {}} part has been commented in the wiki, but it shouldn't !

    Correct configuration for android-apt and AA is :

    apt {
        arguments {
            resourcePackageName android.defaultConfig.packageName
            androidManifestFile variant.processResources.manifestFile
        }
    }
  2. DayS commented on Jan 10, 2014

    @DayS
    Contributor

    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.androidManifestFile is here to resolve this cases where AndroidManifest couldn't be find.

  3. DayS commented on Jan 10, 2014

    @DayS
    Contributor

    @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 ;)

  4. tbruyelle commented on Jan 10, 2014

    @tbruyelle
    Contributor

    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 in build/manifests/<build-variant>.

    I tried to remove the apt.arguments.androidManifestFilet configuration, 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)
    
  5. DayS commented on Jan 10, 2014

    @DayS
    Contributor

    Ok, we don't work with the same type of project structure :)

    I still fit maven hierarchy and my AndroidManifest is 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 androidManifestFile like you suggested. But resourcePackageName may not be override with flavors and in this case your config will crash because this argument will receive null.

    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 ?

  6. tbruyelle commented on Jan 10, 2014

    @tbruyelle
    Contributor

    The problem with removing resourcePackageName is when you use the packageNameSuffix feature 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 found
    

    If 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

  7. DayS commented on Jan 10, 2014

    @DayS
    Contributor

    I 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 :)

  8. DayS commented on Jan 10, 2014

    @DayS
    Contributor

    It should be better now.

    @theDazzler > Could you update your config and tell us if it works now.

  9. DayS commented on Jan 12, 2014

    @DayS
    Contributor

    This seems to work fine. I'm closing this issue then

  10. theDazzler commented on Jan 12, 2014

    @theDazzler
    Author

    I will try it when I get home.

  11. theDazzler commented on Jan 14, 2014

    @theDazzler
    Author

    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.

  12. T12E commented on Jan 14, 2014

    @T12E

    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 like build/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

  13. theDazzler commented on Jan 14, 2014

    @theDazzler
    Author

    I changed it to that to try to get rid of the error. I don't know if that's how it should be. But my project is the standard structure. Here is a screenshot
    screen shot 2014-01-14 at 3 40 05 am

  14. tbruyelle commented on Jan 14, 2014

    @tbruyelle
    Contributor

    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 is resources.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 ?

  15. Yougin commented on Jan 18, 2014

    @Yougin

    Bumped into the same issue, the "androidManifestFile variant.processResources.manifestFile" resolved it. Thank you.

  16. theDazzler commented on Jan 18, 2014

    @theDazzler
    Author

    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.

  17. theDazzler commented on Jan 18, 2014

    @theDazzler
    Author

    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
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions