【问题标题】:API 'variant.getJavaCompile()' is obsoleteAPI 'variant.getJavaCompile()' 已过时
【发布时间】:2018-09-21 16:02:56
【问题描述】:

我是 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"
    }
}

【问题讨论】:

  • 您能否粘贴Build.gradle 文件代码,以便我们更轻松地为您提供帮助?此外,variant.getJavaCompile() 似乎已过时,但不确定将在何处替换为 variant.getJavaCompileProvider()
  • 感谢回答,问题是我找不到这个variant.getJavaCompile() 我添加了gradle文件@ʍѳђઽ૯ท
  • 你能添加你正在使用的IDE和版本吗?
  • Android Studio 3.3 金丝雀 @AbhinavSuman
  • 最后一个工作的 alpha 是类路径 'com.android.tools.build:gradle:3.3.0-alpha10'。除此之外,应用程序将无法解析 R 资源

标签: java android gradle kotlin


【解决方案1】:

更新:这似乎是 kotlin 插件中的一个错误,其中提到了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() 在您当前的 gradle(alpha11 版本)中似乎已过时。但是,您使用的是gradlealpha 版本,我不建议您这样做。

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

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

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

【讨论】:

  • 尽管这会暂时消除警告,但这不是解决方案。如果 op 想要使用 Canary 版本的 Android Studio,为什么不呢?问题是,这是一个警告,不是由操作所写的任何内容引起的。可以放心地忽略它,因为它将在 2019 年底之前修复,而不需要操作员做任何事情。
  • 当然,这只是警告。由于 OP 担心这个问题,我想我已经解释了一切,使用稳定版本的 gradle 应该会有所帮助(现在)。
  • 它不是正确的答案,不是每个用户总是使用相同的版本......如果只是警告,那么它有解决方案
  • @Lokesh 更新了答案。感谢您提及顺便说一句。
【解决方案2】:

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

请在 Google 问题跟踪器上查看以下问题:
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】:

    如果习惯于 google crashlytics

    请升级您的 gradle 依赖项:

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

    【讨论】:

      【解决方案4】:
      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'
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2019-12-11
        • 2019-11-23
        • 2019-06-15
        • 2019-07-14
        • 2019-06-13
        • 2019-09-21
        • 2019-09-28
        • 1970-01-01
        相关资源
        最近更新 更多