迁移到 Gradle Experimental 2.5 时的问题:没有这样的方法 AndroidConfig [英] Issue when migrating to Gradle Experimental 2.5 : no such method AndroidConfig

查看:30
本文介绍了迁移到 Gradle Experimental 2.5 时的问题:没有这样的方法 AndroidConfig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将我的 Android Studio 设置更新为 1.3(截至 2015 年 8 月 31 日的最新稳定版本),我需要使用最新的 NDK 集成.我之前的 Android Studio 版本是 1.2.1(也很稳定).

I have just updated my Android Studio setup to 1.3 (latest stable as of 31st of August 2015) and I need to use the latest NDK integration. My previous Android Studio version was 1.2.1 (stable as well).

遵循 Google 迁移到 Gradle 实验指南我设法轻松地适应了我的各种 gradle 脚本.

Following Google Migration to Gradle Experimental Guide I managed to easily adapt my various gradle scripts.

但是,Gradle Sync 失败并显示以下错误:

However, Gradle Sync fails with the following error :

Error:No such property: android for class: com.android.build.gradle.managed.ProductFlavor

[更新 1 -> 见下文,错误已更新]

当我尝试Make这个项目时,我得到了一个更详细的错误:

When I attempt to Make the project, I obtain a little more detailed error :

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 是指主要的应用代码(包括活动和其他).

App refers to the main application code (with activities and other).

使用功能 F4 >跳转到源代码,它会从我的 app 项目中打开我的 build.gradle 脚本.

Using the feature F4 > Jumping to Source, it opens my build.gradle script from my app project.

这是上述脚本的内容:

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
}

如您所见,这里没有什么特别花哨的东西.但是您可能会注意到有一些单元测试设置:

As you can see, there is nothing very fancy here. But you might notice there is some unit testing setup :

// Units Testing
//androidTestCompile 'junit:junit:4.12'
compile 'junit:junit:4.12' // experimental

androidTestCompile 在迁移到 GradleExperimental 时无法解决,所以我修改了一个解决方案,我再也找不到(抱歉)我可以简单地放置 compile 而不是 androidTestCompile.这是错误:

androidTestCompile could not be resolved while migrating to GradleExperimental so I modified following a solution I can no longer find (sorry) where I would simple put compile in stead of androidTestCompile. This was the error :

Error:(71, 0) Gradle DSL method not found: 'androidTestCompile()'

我尝试比较前面指南中提供的 Google 的 NDK 示例之一(例如 hello-jini)和 此处提供.

I tried to compare one of Google's NDK sample (hello-jini for example) as provided in the aforemention guide and available here.

除了 packagingOptions 我找不到任何导致我出错的差异.我试图删除 packagingOptions 但这根本没有做任何改变.

Except the packagingOptions I could not find any differences that would be responsible for my awry. I tried to remove packagingOptions but that did not make a single change at all.

[更新 1]

您会注意到更详细的错误消息指出它在第 17 行,这是我声明我的本机构建设置的地方.我修复了 cFlags 必须更改为 CFlags 的错误,并根据新版本的 Gradle 的要求添加了 =.这确实有帮助,错误不再出现,但更改为:

You will notice that the more detailed error message states that it's in line #17 which is where I declare my native build settings. I fixed the error which was cFlags must be changed to CFlags and I added the = as required by the new version of Gradle. This did help, the error does not appear anymore but changed for :

Error:No such property: android for class: com.android.build.gradle.managed.AndroidConfig

推荐答案

第一部分.

BuildType、flavors... 在 android 块之外,但在模型块内.

BuildType, flavors... are outside the android block, but inside the model block.

apply plugin: 'com.android.model.application' // experimental

model {
    android {
         defaultConfig.with {

         }
     }

    android.ndk {

    }

    android.buildTypes {
            release {

            }
        }
    android.productFlavors {

    }
}

这篇关于迁移到 Gradle Experimental 2.5 时的问题:没有这样的方法 AndroidConfig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆