Android:计算任务图错误

时间:2018-06-20 00:20:53

标签: android gradle android-gradle

更新项目后,我似乎收到了Gradle错误:

Configuration on demand is not supported by the current version of the Android Gradle plugin since you are using Gradle version 4.6 or above. Suggestion: disable configuration on demand by setting org.gradle.configureondemand=false in your gradle.properties file or use a Gradle version less than 4.6.

打开选项卡进行进一步检查时,它显示如下:

org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'com.android.application']
Caused by: org.gradle.api.tasks.StopExecutionException: Configuration on demand is not supported by the current version of the Android Gradle plugin since you are using Gradle version 4.6 or above. Suggestion: disable configuration on demand by setting org.gradle.configureondemand=false in your gradle.properties file or use a Gradle version less than 4.6.

我尝试了两个建议,它们分别或一起没有用。请在下面查看我的Gradle文件。

Gradle项目文件

buildscript {
ext.kotlin_version = '1.2.50'
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "io.realm:realm-gradle-plugin:5.0.0"
    classpath 'com.google.gms:google-services:4.0.0'




    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
allprojects {
repositories {
    google()
    jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

成绩模块文件

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'realm-android'

apply plugin: 'kotlin-kapt'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 27
defaultConfig {
    applicationId "com.example.blah.blah"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        postprocessing {
            removeUnusedCode false
            removeUnusedResources false
            obfuscate false
            optimizeCode false
            proguardFile 'proguard-rules.pro'
        }
    }
}}
dependencies {
implementation 'com.stripe:stripe-android:6.1.2'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'junit:junit:4.12'
implementation "cz.msebera.android:httpclient:4.4.1.2"

implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-core-utils:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation  'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation files('libs/stripe-java-5.23.1.jar')
implementation  'com.android.volley:volley:1.0.0'
implementation  'com.google.code.gson:gson:2.8.2'}

apply plugin: 'com.google.gms.google-services'

Gradle属性文件

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
#org.gradle.parallel=true

我希望有人能启发我。如果需要,我会上传更多文件数据。

2 个答案:

答案 0 :(得分:3)

根据错误。您需要

  

当前版本的设备不支持按需配置   由于您使用的是Gradle 4.6或更高版本,因此是Android Gradle插件。   建议:通过设置禁用按需配置   org.gradle.configureondemand=false in您的gradle.properties文件或   使用低于4.6的Gradle版本。

这样做

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
org.gradle.configureondemand=false

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
#org.gradle.parallel=true

注意:IDE中还有一个选项“按需配置”(在搜索工具中搜索,您会在“编译器”选项下找到它)取消选中该选项并在全局gradle属性中添加“ org.gradle.configureondemand = false”该文件通常位于C驱动器(windows)或您的OS分区(MAC或linux)中,并且不要忘记启用隐藏文件(Windows->查看选项和Mac Command + Shift +。)

更多信息

configuration on demand in Gradle

what exactly is “configuration on demand” in Gradle?


或者您也可以降级gradle版本。

转到Project->Gradle->wrapper并打开gradle-wrapper.properties文件

并将distributionUrl的值更改为

distributionUrl = https\://services.gradle.org/distributions/gradle-4.4-all.zip

Supported gradle versions in android

答案 1 :(得分:0)

在Android Studio菜单列表上单击文件,然后选择无效缓存,然后它将显示一个对话框,单击无效并重新启动。这个对我有用。此外,我在您的gradle.properties中已将 org.gradle.configureondemand = false设置为,如上面Pavneet_Singh所述,然后使缓存无效。