迁移到 Gradle 实验版 2.5 时出现问题:AndroidConfig 没有这样的方法
Issue when migrating to Gradle Experimental 2.5 : no such method AndroidConfig
我刚刚将我的 Android Studio 设置更新为 1.3(截至 2015 年 8 月 31 日的最新稳定版),我需要使用最新的 NDK 集成。我之前的 Android Studio 版本是 1.2.1(同样稳定)。
在 Google Migration to Gradle Experimental Guide 之后,我设法轻松地调整了我的各种 gradle 脚本。
但是,Gradle 同步失败并出现以下错误:
Error:No such property: android for class: com.android.build.gradle.managed.ProductFlavor
[更新 1 -> 见下文,错误已更新]
当我尝试 Make
项目时,我得到了一些更详细的错误:
Error:(17, 1) A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
> No such property: android for class: com.android.build.gradle.managed.ProductFlavor
App指的是主要的应用代码(有activity等)。
使用功能 F4 > Jumping to Source
,它从我的 app
项目打开我的 build.gradle
脚本。
这是上述脚本的内容:
apply plugin: 'com.android.model.application' // experimental
model {
android {
compileSdkVersion = 21
buildToolsVersion = '22.0.1'
defaultConfig.with {
applicationId = "company.com.myapplication"
minSdkVersion.apiLevel = 10
targetSdkVersion.apiLevel = 21
versionCode = 1
versionName = "1.0"
// NDK
android.ndk {
moduleName = "MyAwesomeJNILib"
cFlags "-std=c99"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" @
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters += "armeabi"
}
create("arm7") {
ndk.abiFilters += "armeabi-v7a"
}
create("arm8") {
ndk.abiFilters += "arm64-v8a"
}
create("x86") {
ndk.abiFilters += "x86"
}
create("x86-64") {
ndk.abiFilters += "x86_64"
}
create("mips") {
ndk.abiFilters += "mips"
}
create("mips-64") {
ndk.abiFilters += "mips64"
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.okhttp:okhttp-android-support:2.4.0'
compile project(':bluetoothmanager')
compile 'joda-time:joda-time:2.8.1'
// Units Testing
//androidTestCompile 'junit:junit:4.12'
compile 'junit:junit:4.12' // experimental
}
如您所见,这里没有什么特别的。
但是您可能会注意到有一些单元测试设置:
// Units Testing
//androidTestCompile 'junit:junit:4.12'
compile 'junit:junit:4.12' // experimental
androidTestCompile
在迁移到 GradleExperimental 时无法解决,所以我修改了一个解决方案,我再也找不到(抱歉)我想去的地方简单地用 compile
代替 androidTestCompile
。
这是错误:
Error:(71, 0) Gradle DSL method not found: 'androidTestCompile()'
我试图比较上述指南中提供的 Google 的 NDK 示例之一(例如 hello-jini
)和 available here。
除了 packagingOptions
之外,我找不到任何导致我出错的差异。我试图删除 packagingOptions
但根本没有进行任何更改。
[更新 1]
您会注意到更详细的错误消息指出它在第 17 行,这是我声明我的 本机构建设置 的地方。
我修复了 cFlags
必须更改为 CFlags
的错误,并根据新版本 Gradle 的要求添加了 =
。
这确实有帮助,错误不再出现但更改为:
Error:No such property: android for class: com.android.build.gradle.managed.AndroidConfig
第一部分。
BuildType、flavors...在 android 块之外,但在模型块内。
apply plugin: 'com.android.model.application' // experimental
model {
android {
defaultConfig.with {
}
}
android.ndk {
}
android.buildTypes {
release {
}
}
android.productFlavors {
}
}
我刚刚将我的 Android Studio 设置更新为 1.3(截至 2015 年 8 月 31 日的最新稳定版),我需要使用最新的 NDK 集成。我之前的 Android Studio 版本是 1.2.1(同样稳定)。
在 Google Migration to Gradle Experimental Guide 之后,我设法轻松地调整了我的各种 gradle 脚本。
但是,Gradle 同步失败并出现以下错误:
Error:No such property: android for class: com.android.build.gradle.managed.ProductFlavor
[更新 1 -> 见下文,错误已更新]
当我尝试 Make
项目时,我得到了一些更详细的错误:
Error:(17, 1) A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
> No such property: android for class: com.android.build.gradle.managed.ProductFlavor
App指的是主要的应用代码(有activity等)。
使用功能 F4 > Jumping to Source
,它从我的 app
项目打开我的 build.gradle
脚本。
这是上述脚本的内容:
apply plugin: 'com.android.model.application' // experimental
model {
android {
compileSdkVersion = 21
buildToolsVersion = '22.0.1'
defaultConfig.with {
applicationId = "company.com.myapplication"
minSdkVersion.apiLevel = 10
targetSdkVersion.apiLevel = 21
versionCode = 1
versionName = "1.0"
// NDK
android.ndk {
moduleName = "MyAwesomeJNILib"
cFlags "-std=c99"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" @
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters += "armeabi"
}
create("arm7") {
ndk.abiFilters += "armeabi-v7a"
}
create("arm8") {
ndk.abiFilters += "arm64-v8a"
}
create("x86") {
ndk.abiFilters += "x86"
}
create("x86-64") {
ndk.abiFilters += "x86_64"
}
create("mips") {
ndk.abiFilters += "mips"
}
create("mips-64") {
ndk.abiFilters += "mips64"
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.okhttp:okhttp-android-support:2.4.0'
compile project(':bluetoothmanager')
compile 'joda-time:joda-time:2.8.1'
// Units Testing
//androidTestCompile 'junit:junit:4.12'
compile 'junit:junit:4.12' // experimental
}
如您所见,这里没有什么特别的。 但是您可能会注意到有一些单元测试设置:
// Units Testing
//androidTestCompile 'junit:junit:4.12'
compile 'junit:junit:4.12' // experimental
androidTestCompile
在迁移到 GradleExperimental 时无法解决,所以我修改了一个解决方案,我再也找不到(抱歉)我想去的地方简单地用 compile
代替 androidTestCompile
。
这是错误:
Error:(71, 0) Gradle DSL method not found: 'androidTestCompile()'
我试图比较上述指南中提供的 Google 的 NDK 示例之一(例如 hello-jini
)和 available here。
除了 packagingOptions
之外,我找不到任何导致我出错的差异。我试图删除 packagingOptions
但根本没有进行任何更改。
[更新 1]
您会注意到更详细的错误消息指出它在第 17 行,这是我声明我的 本机构建设置 的地方。
我修复了 cFlags
必须更改为 CFlags
的错误,并根据新版本 Gradle 的要求添加了 =
。
这确实有帮助,错误不再出现但更改为:
Error:No such property: android for class: com.android.build.gradle.managed.AndroidConfig
第一部分。
BuildType、flavors...在 android 块之外,但在模型块内。
apply plugin: 'com.android.model.application' // experimental
model {
android {
defaultConfig.with {
}
}
android.ndk {
}
android.buildTypes {
release {
}
}
android.productFlavors {
}
}