Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API 'variant.getJavaCompile()' is obsolete

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

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:

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"
    }
}
like image 350
SinaMN75 Avatar asked Sep 21 '18 16:09

SinaMN75


4 Answers

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

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

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

And: 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


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

Instead, try using the stable versions like:

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

And then warning should be gone I hope.

like image 76
ʍѳђઽ૯ท Avatar answered Oct 17 '22 19:10

ʍѳђઽ૯ท


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'
    }
}
like image 32
Ketan Ramani Avatar answered Oct 04 '22 14:10

Ketan Ramani


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

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

Duplicate issue with some more info:
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

like image 6
Pranav Pandey Avatar answered Oct 17 '22 20:10

Pranav Pandey


If used to google crashlytics

Please do upgrade your gradle dependencies:

implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
classpath 'io.fabric.tools:gradle:1.26.1'
like image 1
Ramananda Sarkar Avatar answered Oct 17 '22 20:10

Ramananda Sarkar