Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot build Android project with Gradle (using Android Annotations)

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
like image 479
MAGx2 Avatar asked Apr 03 '14 09:04

MAGx2


People also ask

Which Gradle is required for Android project development?

If you are using Gradle for Android, you need to move to version 3.3 or higher of both the Android Gradle Plugin and Android Studio.

What is BuildConfig in Android?

BuildConfig is a class containing static constants that is included in every Android application. BuildConfig includes some default fields such as DEBUG and FLAVOR but you can also add custom values via build.

What is Gradle project Sync failed in Android Studio?

It could be that you are using gradle in offline mode. To uncheck it go to File > Settings > Gradle , uncheck the Offline Work checkbox, and click Apply Make sure you have internet connection and sync the project again.

Where is the build Gradle File in Android Studio?

gradle file is located inside your project folder under app/build. gradle.


1 Answers

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"
}
like image 173
zhakid Avatar answered Sep 21 '22 23:09

zhakid