警告:API'variable.getJavaCompile()'已过时,已替换为'variant.getJavaCompileProvider()'

Arn*_*r Z 188 android compilation android-studio android-gradle-plugin google-fabric

在Syncing 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'

    [...]
}
Run Code Online (Sandbox Code Playgroud)

我已经build.gradle为app模块做了这个:

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'

    [...]
}
Run Code Online (Sandbox Code Playgroud)

我可以正确编译应用程序,但它有点麻烦,而且正如我所看到的,某些东西将在2019年底停止工作.任何想法是什么,以及如何解决它?

Ewo*_*oks 88

更新到3.3.0后我遇到了这个问题

如果你没有在gradle文件中执行什么错误状态,那么它仍然没有更新到导致此错误的新API.要找出哪个插件,请执行以下操作(如3.3.0声明中的"使用过时API时更好的调试信息"中所述):

  • 'android.debug.obsoleteApi = true'添加到gradle.properties文件中,该文件将记录错误并提供更多详细信息
  • 再试一次,阅读日志详细信息.会有一些"有问题"的插件
  • 当你确定时,尝试禁用它,看看问题是否已经消失,只是为了确定
  • 转到插件的github页面并创建包含详细日志和清晰描述的问题,以便您帮助开发人员更快地为每个人修复它
  • 在他们修复它时要有耐心,或者你修复它并为开发者创建PR

希望它能帮助别人

  • 添加`android.debug.obsoleteApi = true`后,要读取记录的详细信息,请执行以下操作:转到底部的“构建”选项卡,然后在“构建输出”窗口中,单击“切换视图”。当您单击漂亮的颜色时,请滚动至顶部,显示“警告:API'variant.getAssemble()'已过时”。然后在其下显示`REASON:Called from:`...在我的情况下,这是由于https://medium.com/@xabaras/automatically-copying-proguard-mapping-file-to-apk-build-目录-d7eed285632 (5认同)
  • 我认为这是最通用,最有用的答案。就我而言,由于使用[Groovy-Android插件](https://github.com/groovy/groovy-android-gradle-plugin)(针对Spock测试)而发出此警告。 (3认同)
  • 这是正确的答案。谁支持gradle版本更新? (2认同)

M.N*_*man 73

此问题已通过更新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'
    }
}
Run Code Online (Sandbox Code Playgroud)

  • @FaizanMubasher尝试将您的Google服务降级到4.2 (7认同)
  • 我现在有`classpath'io.fabric.tools:gradle:1.29.0'`。我该怎么办? (5认同)
  • @InfiniteLoops建议降级到4.2似乎可行。 (4认同)
  • 这也是正确的答案,是解决面临问题的简便方法。 (2认同)

Num*_*lan 60

In my case, it was caused from gms services 4.3.0. So i had to change it to:

com.google.gms:google-services:4.2.0
Run Code Online (Sandbox Code Playgroud)

I have found this by running:

gradlew sync -Pandroid.debug.obsoleteApi=true
Run Code Online (Sandbox Code Playgroud)

in terminal. Go to view -> tool windows -> Terminal in Android Studio.

  • @AhamadullahSaikat这可能会在将来的版本中修复。然后,您可以再次对其进行升级。在Google修复此问题之前,这是一种解决方法。 (4认同)
  • 我刚刚将我的gms Google服务更改为4.2,警告消失了,谢谢。 (3认同)
  • 为什么我应该降级google-services依赖关系。这不是解决方案。 (3认同)
  • @VasudevVyas,如果在android Studio中,只需在命令前添加`。/`,也就是说,如果终端设置为android项目的根目录。否则,您将必须cd到项目的根目录。 (2认同)

Har*_*hah 34

这只是一个警告,它可能会在2019年之前修复插件更新,所以不用担心.我建议你使用兼容版本的插件和gradle.

您可以在此处查看插件版本和gradle版本,以获得更好的体验和性能.

https://developer.android.com/studio/releases/gradle-plugin

尝试使用稳定版本获得平滑且无警告/无错误的代码.

  • 它实际上比仅仅是一个警告更加阴险 - 它会影响代码编辑器并阻止您搜索对类的引用. (24认同)
  • 它现在是一个错误,我不能构建应用程序 (9认同)

Fah*_*ved 24

我也面临同样的问题。经过一段时间的搜索,我发现警告是由于使用最新版本的google-services插件(版本4.3.0)引起的。顺便说一下,我在我的应用程序中将此插件用于Firebase功能。我所做的就是google-services在build.gradle(Project)级别文件中的buildscript中降级我的插件,如下所示:

buildscript{
    dependencies {
       // From =>
       classpath 'com.google.gms:google-services:4.3.0'
       // To =>
       classpath 'com.google.gms:google-services:4.2.0'
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 我已升级到4.3.2,但未收到此警告。 (2认同)

Mor*_*Koh 10

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

2) 更新这些已弃用的函数。

  • variant.javaCompilevariant.javaCompileProvider

  • variant.javaCompile.destinationDirvariant.javaCompileProvider.get().destinationDir


小智 9

从以下位置更改您的Google服务版本build.gradle

dependencies {
  classpath 'com.google.gms:google-services:4.2.0'
}
Run Code Online (Sandbox Code Playgroud)


Ven*_*dor 8

这是构建工具发出的警告,原因有两个.
1.其中一个插件依赖于Task而不是TaskProvider,我们无能为力.
2.您已配置任务的使用,因为它支持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
Run Code Online (Sandbox Code Playgroud)

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

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

同样,找到'variant.getJavaCompile()''variant.javaCompile','variant.getMergeResources()'或的用法'variant.mergeResources'.如上所述替换.

有关任务配置规避的更多信息

  • @IgorGanapolsky,它也会发生在终端.尝试执行`./ gradlew`.这与AS无关,它与构建工具无关.升级/降级到`com.android.tools.build:gradle:3.2.0`并执行`./gradlew`.这不会来的. (2认同)

erl*_*man 5

在我的情况下,将Kotlin插件stdLib)版本升级到 1.3.1解决了该警告。通过将现有 Kotlin 版本替换为以下内容来更新整个项目中的 Kotlin 版本:

ext.kotlin_version = '1.3.50'
Run Code Online (Sandbox Code Playgroud)


小智 5

降级 Gradle 的版本对我有用:

classpath 'com.android.tools.build:gradle:3.2.0'
Run Code Online (Sandbox Code Playgroud)

  • 降级永远不是一种选择 (4认同)

归档时间:

查看次数:

116426 次

最近记录:

6 年,3 月 前