java - API 'variant.getJavaCompile()' 已过时

标签 java android gradle kotlin

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

我收到的警告:

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'
}

build.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"
    }
}

最佳答案

更新:这似乎是 kotlin 插件中的一个错误,其中提到了 in here

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

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

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

提交实际上是为了修复这个问题:

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


在深入搜索代码后,看起来像 getJavaCompile()在您当前的 gradle(alpha11 版本)中已过时。但是,您使用的是 gradlealpha 版本,我不建议这样做。

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

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

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

关于java - API 'variant.getJavaCompile()' 已过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52447439/

相关文章:

java - Spring 3.0 REST 实现还是 Jersey ?

java - Libgdx Gwt 使用补间引擎编译错误

gradle - 如何获取 .jar 依赖项的文件路径位置?

java - 如何将 javax.microedition.lcdui 包安装到 Netbeans 中

Java 泛型通配符 : Why does this not compile?

java - 重构以内联类用法?

android - 浏览器下载后打开我自己的 Activity

java - 扩展类并实现接口(interface)的通用类

android - 单击列表项时如何进行 fragment 事务?

gradle - 依赖同一依赖项的多个配置