API 'variant.getJavaCompile()' 已过时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52447439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:27:38  来源:igfitidea点击:

API 'variant.getJavaCompile()' is obsolete

javaandroidgradlekotlin

提问by SinaMN75

I'm new to Kotlindevelopment and just after I added Kotlinto my project there's a problem with something obsoleted. I saw something like this before when we had to change compileto implementation, but I really don't understand what is this about.

我是Kotlin开发新手,就在我添加Kotlin到我的项目之后,一些过时的东西出现了问题。我以前在我们不得不更改compile为时看到了类似的内容implementation,但我真的不明白这是什么意思。

the warning I get:

我得到的警告:

API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.

build.gradle:

构建.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.sinamn75.androidtest"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}
repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    // Support
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0-rc02'
    implementation 'com.android.support:recyclerview-v7:28.0.0-rc02'
    implementation 'com.android.support:cardview-v7:28.0.0-rc02'
    implementation 'com.android.support:support-v4:28.0.0-rc02'
    implementation 'com.android.support:support-core-utils:28.0.0-rc02'
    implementation 'com.android.support:preference-v14:28.0.0-rc02'
    implementation 'com.android.support:exifinterface:28.0.0-rc02'
    // GooglePlay
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.android.gms:play-services-plus:15.0.1'
    implementation 'com.google.android.gms:play-services-places:15.0.1'
    implementation 'com.google.android.gms:play-services-vision:15.0.2'
    //AndPermission
    implementation 'com.yanzhenjie:permission:2.0.0-rc6'
    // AHNavigation
    implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
    // Lottie
    implementation 'com.airbnb.android:lottie:2.2.5'
    // SwitchButton
    implementation 'lib.kingja.switchbutton:switchbutton:1.1.7'
    // RoundedImageView
    implementation 'com.makeramen:roundedimageview:2.3.0'
    // Picasso
    implementation 'com.squareup.picasso:picasso:2.71828'
    // MaterialDialog
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
}

build.gradle:

构建.gradle:

buildscript {
    ext.kotlin_version = '1.2.70'

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha11'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
apply plugin: 'kotlin'

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task customClean(type: Delete) {
    delete rootProject.buildDir
}
clean.dependsOn customClean
repositories {
    mavenCentral()
}
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

采纳答案by ??????

Update:It seems like this is a bug in kotlin plugins which mentioned in here

更新:这似乎是这里提到的 kotlin 插件中的一个错误

However, using new release of kotlin plugin (When kotlin started using the new APIs) might get rid of the error as stated in here:

但是,使用新版本的 kotlin 插件(当 kotlin 开始使用新 API 时)可能会消除此处所述的错误:

https://github.com/JetBrains/kotlin/pull/1884/commits/1a17cb54a775ab3e55db66109cb12b7d54fbba6c

https://github.com/JetBrains/kotlin/pull/1884/commits/1a17cb54a775ab3e55db66109cb12b7d54fbba6c

And: https://github.com/JetBrains/kotlin/pull/1884

还有:https: //github.com/JetBrains/kotlin/pull/1884

The commit was actually for the fix of this issue:

提交实际上是为了解决这个问题:

This commit does not change anything functionally, it is only to avoid the warning message, as reporter in https://issuetracker.google.com/116198439

这个提交在功能上没有任何改变它只是为了避免警告消息,正如https://issuetracker.google.com/116198439 中的记者



After a deep search into codes, seems like getJavaCompile()is obsolete in your current gradle (alpha11version). However, you were using alphaversion of gradlewhich I don't really recommend that.

在对代码进行深入搜索之后,似乎getJavaCompile()在您当前的 gradle(alpha11版本)中已经过时了。但是,您使用的是我并不真正推荐的alpha版本gradle

Instead, try using the stable versions like:

相反,请尝试使用稳定版本,例如:

classpath 'com.android.tools.build:gradle:3.1.4'

And then warning should be gone I hope.

然后警告应该消失了,我希望。

回答by Pranav Pandey

This warning is related to the Kotlin plugins still using the older (deprecated) APIs.

此警告与仍在使用旧(已弃用)API 的 Kotlin 插件有关。

Please check the below issue on Google issue tracker:
https://issuetracker.google.com/issues/116198439

请在 Google 问题跟踪器上查看以下问题:https:
//issuetracker.google.com/issues/116198439

Duplicate issue with some more info:
https://issuetracker.google.com/issues/116148147

更多信息的重复问题:https:
//issuetracker.google.com/issues/116148147

It will be fixed when Kotlin plugin will start using the newer APIs. Please check the issues here:
https://youtrack.jetbrains.com/issue/KT-25428
https://github.com/JetBrains/kotlin/pull/1884

它将在 Kotlin 插件开始使用较新的 API 时修复。请在此处查看问题:
https: //youtrack.jetbrains.com/issue/KT-25428
https://github.com/JetBrains/kotlin/pull/1884

回答by Ramananda Sarkar

If used to google crashlytics

如果用于谷歌 crashlytics

Please do upgrade your gradle dependencies:

请升级您的 gradle 依赖项:

implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
classpath 'io.fabric.tools:gradle:1.26.1'

回答by Ketan Ramani

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.2.0' // Change classpath 'com.google.gms:google-services:4.3.0' to classpath 'com.google.gms:google-services:4.2.0'
    }
}