代码之家  ›  专栏  ›  技术社区  ›  SinaMN75

API“variant.getJavaCompile()”已过时

  •  7
  • SinaMN75  · 技术社区  · 6 年前

    我是新来的 Kotlin 科特林 我以前看到过这样的事情当我们不得不改变的时候 compile implementation ,但我真的不明白这是怎么回事。

    我得到的警告是:

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

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

    内部版本.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"
        }
    }
    
    3 回复  |  直到 6 年前
        1
  •  12
  •   ʍѳђઽ૯ท    6 年前

    似乎这是kotlin插件中的一个bug in here

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

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

    以及: https://github.com/JetBrains/kotlin/pull/1884

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

    这个承诺 不会改变任何功能 , 只是为了避免 警告信息 https://issuetracker.google.com/116198439


    经过对代码的深入搜索 getJavaCompile() 在你现在的学校里已经过时了( alpha11 的版本 gradle 我不建议你这么做。

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

    我希望警告会消失。

        2
  •  6
  •   Pranav Pandey    6 年前

    此警告与Kotlin插件仍然使用旧的(不推荐使用的)api有关。


    https://issuetracker.google.com/issues/116198439

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

    当Kotlin插件开始使用更新的api时,它将被修复。请检查以下问题:
    https://youtrack.jetbrains.com/issue/KT-25428
    https://github.com/JetBrains/kotlin/pull/1884

        3
  •  1
  •   ʍѳђઽ૯ท    5 年前

    如果习惯谷歌crashlytics

    请升级您的gradle依赖项:

    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
    classpath 'io.fabric.tools:gradle:1.26.1'
    
        4
  •  1
  •   Ketan Ramani    5 年前
    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'
        }
    }