我刚刚将我的 Android Studio 设置更新到 1.3(截至 2015 年 8 月 31 日的最新稳定版),我需要使用最新的 NDK 集成。我以前的 Android Studio 版本是 1.2.1(同样稳定)。
正在关注 Google Migration to Gradle Experimental Guide我设法轻松调整我的各种 gradle 脚本。
但是,Gradle Sync 失败并出现以下错误:
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 行,这是我声明我的本地build设置的地方。
我修复了 cFlags
必须更改为 CFlags
的错误,并根据新版本 Gradle 的要求添加了 =
。
这确实有帮助,错误不再出现但更改为:
Error:No such property: android for class: com.android.build.gradle.managed.AndroidConfig
最佳答案
对于第一部分。
BuildType、flavors...在 android block 之外,但在 model block 内。
apply plugin: 'com.android.model.application' // experimental
model {
android {
defaultConfig.with {
}
}
android.ndk {
}
android.buildTypes {
release {
}
}
android.productFlavors {
}
}
关于android - 迁移到 Gradle Experimental 2.5 : no such method AndroidConfig 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32310523/