API&x27;variant.getJavaCompile()';已经过时了
我是API&x27;variant.getJavaCompile()';已经过时了,java,android,gradle,kotlin,Java,Android,Gradle,Kotlin,我是Kotlin开发的新手,刚将Kotlin添加到我的项目中,就出现了一个过时的问题。 以前,当我们不得不将编译更改为实现时,我看到过类似的情况,但我真的不明白这是怎么回事 我得到的警告是: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'. It will be removed at the end of 2019. build.gr
Kotlin
开发的新手,刚将Kotlin
添加到我的项目中,就出现了一个过时的问题。
以前,当我们不得不将编译
更改为实现
时,我看到过类似的情况,但我真的不明白这是怎么回事
我得到的警告是:
API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
build.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'
}
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"
}
}
build.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'
}
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"
}
}
更新:这似乎是kotlin插件中提到的一个bug 但是,使用新版本的kotlin插件(当kotlin开始使用新API时)可能会消除以下错误: 以及: 提交实际上是为了修复此问题: 此提交不会在功能上更改任何内容,只是为了避免 警告消息,如中的报告者所示
在深入搜索代码后,在您当前的gradle(
alpha11
version)中似乎已过时。但是,您使用的是alpha版本的gradle
,我并不推荐这样做
相反,请尝试使用以下稳定版本:
classpath 'com.android.tools.build:gradle:3.1.4'
然后,我希望警告应该消失。此警告与Kotlin插件仍在使用旧的(不推荐使用的)API有关 请在Google issue tracker上查看以下问题:
重复问题并提供更多信息:
当Kotlin插件开始使用更新的API时,它将被修复。请检查此处的问题:
如果用于谷歌crashlytics 请升级您的gradle依赖项:
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
classpath 'io.fabric.tools:gradle:1.26.1'
你能粘贴
Build.gradle
文件代码吗,这样我们可以更轻松地帮助你?另外,variant.getJavaCompile()
似乎已经过时,但不确定在哪里可以用variant.getJavaCompileProvider()
替换。感谢您的回答,问题是我找不到这个variant.getJavaCompile()
我添加了gradle文件@ઽ૯ท你能添加你正在使用的IDE和版本吗?Android studio 3.3 canary@abhinavsumante最后一个可用的alpha是classpath'com.Android.tools.build:gradle:3.3.0-alpha10'。除此之外,该应用程序将无法解析R resourcesEven。尽管这将暂时消除警告,但这不是一个解决方案。如果op想要使用安卓Studio的金丝雀版本,为什么不呢?问题是,这是一个警告,不是由op写的任何东西引起的。它可以被安全地忽略,因为它将在2019年底之前被修复,op不会做任何事情。当然,这只是一个警告。由于OP关注这个问题,我想我已经解释了一切,使用稳定版本的gradle
应该会有所帮助(目前)。答案不正确,不是每个用户都使用相同的版本。。。如果只是警告,那么它就有了solution@Lokesh更新了答案。谢谢你提到顺便说一句。