Cannot build Android project with Gradle (using Android Annotations)
Asked Answered
N

1

10

I'm trying to use gradle to build my Android project wit Android Annotations but I still get errors. In my java classes AA is not found.

Also in gradle file I get some hints:

versionName "1.0" <- 'versionName' cannot be applied to '(java.lang.String)'

'main' in 'build' cannot be applied to '(groovy.lang.Closure)'

        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java', 'GENERATED_FOLDER']
            resources.srcDirs = ['src/main/resources']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
        }

Below is my full gradle script:

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

repositories {
    mavenCentral()
    mavenLocal()
}

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

dependencies {
    // Android annotations
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"

    compile 'com.android.support:appcompat-v7:19.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])

    // ORMLite
    compile 'com.j256.ormlite:ormlite-android:4.46'

    // Google Guava
    compile 'com.google.guava:guava:16.0.1'
}

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile
        resourcePackageName 'pl.grzeslowski.weaselmoney'
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    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', 'GENERATED_FOLDER']
            resources.srcDirs = ['src/main/resources']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
        }
    }
}

This is log from my console in Android Studio:

Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:weasel_moneyWeaselMoney:help

Welcome to Gradle 1.10.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

BUILD SUCCESSFUL

Total time: 6.111 secs

Process finished with exit code 0
Need answered 3/4, 2014 at 9:3 Comment(6)
can you add error messge from Gradle console?Wage
"BUILD SUCCESSFUL" message says, that you project compilation with Gradle finished with success. Where are you getting errors?Wage
In my .java files I cannot import com.googlecode.androidannotations.* because it is not foundNeed
try this blog.yageek.net/blog/2014/01/20/android-studioWage
also, open in your AS: Settings -> Compiler -> Annotation Processors, choose your project and check "Enable annotation processing"Wage
similar question with this answer : https://mcmap.net/q/1169156/-about-android-studio-0-5-39-sourcesets-39Mentor
M
1

Dont put your AA configuration on your General build.gradle put it in your app folder inside build.gradle, look @ this example

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.2'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName 'com.example.app'
        logLevel 'TRACE' //Use this to get AA log
        logAppenderConsole 'true' //Use this to get AA log
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt')
        }

        debug {
            debuggable true
        }
    }
    packagingOptions {
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
    }
}

dependencies {

    //Libs
    compile fileTree(dir: 'libs', include: ['*.jar'])

    //Dependency
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'org.springframework.android:spring-android-rest-template:2.0.0.M1' //If you're using REST
    compile 'com.google.code.gson:gson:1.7.2'
    compile 'org.codepond:wizardroid:1.3.0'

    //Android Annotations
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}
Mahayana answered 26/3, 2015 at 4:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.