无法使用Gradle构建Android项目(使用Android Annotations)

时间:2014-04-03 09:03:09

标签: android gradle android-annotations

我正在尝试使用gradle来构建我的Android项目Android Annotations,但我仍然会遇到错误。在我的java类中找不到AA。

同样在gradle文件中我得到一些提示:

versionName“1.0”< - 'versionName'无法应用于'(java.lang.String)'

'build'中的'main'不能应用于'(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']
        }

以下是我的完整gradle脚本:

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']
        }
    }
}

这是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

1 个答案:

答案 0 :(得分:1)

不要将AA配置放在General build.gradle上 把它放在build.gradle里面的app文件夹中,看看@这个例子

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"
}