突然,当同步Gradle,我得到这个错误:

警告:API 'variant.getJavaCompile()'已经过时 替换为'variant.getJavaCompileProvider()'。 它将在2019年底被移除。 欲了解更多信息,请参见https://d.android.com/r/tools/task-configuration-avoidance 受影响模块:app

我有这样的身材。应用模块的Gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

apply plugin: 'io.fabric'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.2"
    defaultConfig {
        applicationId "..."
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "..."
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        versionNameSuffix = version_suffix

        [...]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

            [...]
        }
        debug {
            [...]
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61"
    implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "com.android.support:preference-v7:28.0.0"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
    implementation 'com.google.android.material:material:1.0.0-rc02'

    [...]
}

我可以正确地编译应用程序,但它有点麻烦,在我看来,有些东西将在2019年底停止工作。你知道它是什么,如何解决它吗?


当前回答

将 gradle 更新为 gradle:3.3.0

默认的“assemble”任务只适用于普通的变量。还可以添加测试变体。

android.testVariants.all { variant ->
    tasks.getByName('assemble').dependsOn variant.getAssembleProvider()
}

还有注释apply fabric

//apply plugin: 'io.fabric'

其他回答

从类路径'com.android.tools.build:gradle:3.3.0-alpha13'返回到类路径'com.android.tools.build:gradle:3.2.0'

这对我很有效

这个问题现在已经在Fabric Gradle 1.30.0版本更新中得到解决:

更新发布日期:2019年3月19日

请参阅此链接:https://docs.fabric.io/android/changelog.html#march-15-2019

请在项目级Gradle中更新你的类路径依赖:

buildscript {
    // ... repositories, etc. ...

    dependencies {
        // ...other dependencies ...
        classpath 'io.fabric.tools:gradle:1.30.0'
    }
}

升级protobuf-gradle-plugin到0.8.10版本解决了我的问题。将您现有的protobuf替换为

classpath 'gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.10'

1)在gradle.properties中添加android.debug.obsoleteApi=true。它将显示哪些模块受到警告日志的影响。

2)更新这些废弃的功能。

变体。javaCompile转换为variant.javaCompileProvider variant.javaCompile.destinationDir来 .destinationDir variant.javaCompileProvider.get ()

这是构建工具提出的警告,有两个原因。 1. 其中一个插件依赖于Task而不是TaskProvider,我们无能为力。 2. 您已经配置了task的用法,其中它支持TaskProvider。

WARNING: API 'variant.getGenerateBuildConfig()' is obsolete and has been replaced with 'variant.getGenerateBuildConfigProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance

WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance

WARNING: API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance

请注意下面的片段并更新。

android {
    <library|application>Variants.all { variant ->
        /* Disable Generating Build config */
        // variant.generateBuildConfig.enabled = true // <- Deprecated
        variant.generateBuildConfigProvider.configure {
            it.enabled = true // Replacement
        }
    }
}

类似地,查找' variable . getjavacompile()'或'variant. getjavacompile()'的用法。javaCompile', ' variable . getmergeresources()'或' variable . mergeresources '。如上所述替换。

更多信息请参见任务配置避免