gpt4 book ai didi

android - 无法使用 Gradle 构建 Android 项目(使用 Android 注释)

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:14:12 26 4
gpt4 key购买 nike

我正在尝试使用 gradle 通过 Android 注释构建我的 Android 项目,但我仍然遇到错误。在我的 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

最佳答案

不要把你的 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"
}

关于android - 无法使用 Gradle 构建 Android 项目(使用 Android 注释),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22832711/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com