WARNING: API 'variant.getPackageLibrary()' is obsolete and has been replaced with 'variant.getPackageLibraryProvider()'

KotlinAndroid Gradle-Plugin

Kotlin Problem Overview


I just upadated kotlin to 1.3.30 and I now get this error when syncing gradle:

> WARNING: API 'variant.getPackageLibrary()' is obsolete and has been > replaced with 'variant.getPackageLibraryProvider()'. It will be > removed at the end of 2019. For more information, see > https://d.android.com/r/tools/task-configuration-avoidance. To > determine what is calling variant.getPackageLibrary(), use > -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace. Affected Modules: hydatabase

Here is my build.gradle:

apply plugin: 'com.squareup.sqldelight'
apply plugin: 'kotlin-multiplatform'
apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 19
    }
    lintOptions {
        abortOnError false
    }
}

sqldelight {
    Database {
        packageName = "com.company.hydatabase"
    }
}

kotlin {
    targets {
        fromPreset(presets.jvm, 'jvm')
        fromPreset(presets.android, 'android')
    }

    sourceSets {
        commonMain.dependencies {
            api 'org.jetbrains.kotlin:kotlin-stdlib-common'
        }
        jvmMain.dependencies {
            api 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
            // ICU4J: Use DecimalFormat
            // Get rid of this when minSDKLevel = API 24 - Nougat (7.0)
            // https://developer.android.com/guide/topics/resources/internationalization.html
            api 'com.ibm.icu:icu4j:60.2'
        }
        androidMain.dependencies {
            implementation 'org.jetbrains.kotlin:kotlin-stdlib'
            api "com.squareup.sqldelight:android-driver:1.1.1"
        }
        androidMain.dependsOn jvmMain
    }
}

task copyDatabase(type: Copy) {
    from "${rootProject.file('hyappcommon/Databases/').path}"
    into "${rootProject.file('hydatabase/src/main/assets/databases/').path}"
    include '**/*.sqlite'
}

preBuild.dependsOn(copyDatabase)

// workaround for https://youtrack.jetbrains.com/issue/KT-27170
configurations {
    compileClasspath
}

Kotlin Solutions


Solution 1 - Kotlin

If you debug, it shows REASON: The Kotlin plugin is currently calling this API. We are working to solve this.

To see this error please run ./gradlew -Pandroid.debug.obsoleteApi=true --stacktrace

Solution 2 - Kotlin

As tommyboy said, the Kotlin plugin is calling this deprecated API. If you don't want to get this warning while Kotlin is working on this, you can just use the previous version of Kotlin plugin like:

dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21"
}

Solution 3 - Kotlin

It's probably a bug and fixed soon

You can revert back to the previous version or add this line to gradle.properties

android.debug.obsoleteApi=true

Solution 4 - Kotlin

In my project gradle file I had

buildscript {
    ext.kotlin_version = '1.3.31'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

Simple changing ext.kotlin_version = '1.3.31' to ext.kotlin_version = '1.3.41' solved the problem

when using version 1.3.31 i had tried gradlew -Pandroid.debug.obsoleteApi=true

It mentioned

> WARNING: API 'variant.getPackageLibrary()' is obsolete and has been > replaced with 'variant.getPackageLibraryProvider()'. It will be > removed at the end of 2019. > For more information, see https://d.android.com/r/tools/task-configuration-avoidance. > > REASON: The Kotlin plugin is currently calling this API. We are working to solve this. > > WARNING: Debugging obsolete API calls can take time during > configuration. It's recommended to not keep it on at all times.

Looks like it is solved in 1.3.41

Solution 5 - Kotlin

It's an issue with the Kotlin plugin, as mentioned here. It'll get fixed in a later version.

Solution 6 - Kotlin

After I updated Kotlin to 1.3.30, the following dependencies cause the error:

dependencies {
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
    // ... other dependencies
}

I have reported the issue here:

https://github.com/bintray/gradle-bintray-plugin/issues/284

https://github.com/dcendents/android-maven-gradle-plugin/issues/81

By the way, you can ignore that error message.

Solution 7 - Kotlin

The issue is tracked here and it is fixed.

Just use the Kotlin Gradle plugin v 1.3.40 or higher.

> WARNING: API 'variant.getPackageLibrary()' is obsolete and has been replaced with 'variant.getPackageLibraryProvider()'. It will be removed at the end of 2019.

enter image description here

Solution 8 - Kotlin

Just updated to "v1.3.40-release-Studio3.4-1" plugin.

as you can see in https://youtrack.jetbrains.com/issue/KT-30784

Solution 9 - Kotlin

I met this problem when I use kotlin plugin with library plugin. I found that if you use kotlin plugin with application plugin, it works well. But if you use kotlin plugin with library plugin, it will cause this problem. So that means:

// work well:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

// error:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

As the error diplayed that, you can use ./gradlew -Pandroid.debug.obsoleteApi=true --stacktrace to find out with module caused this problem.

Then I found that one of my module used the wrong plugin combination above. And that seems to be a bug of kotlin plugin. So finally, I upgraded the kotlin plugin, and then it worked well. Below is the kotlin plugin that I finally used:

buildscript {
    ext.kotlin_version = '1.3.40'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

Solution 10 - Kotlin

You can run this command in the root project

gradlew -Pandroid.debug.obsoleteApi=true

and the warning will be disappeared.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBenjaminView Question on Stackoverflow
Solution 1 - KotlintommyboyView Answer on Stackoverflow
Solution 2 - KotlinJack'View Answer on Stackoverflow
Solution 3 - KotlinAmir Hossein GhasemiView Answer on Stackoverflow
Solution 4 - KotlinJohnView Answer on Stackoverflow
Solution 5 - KotlinDmitriy PView Answer on Stackoverflow
Solution 6 - KotlinAnggrayudi HView Answer on Stackoverflow
Solution 7 - KotlinGabriele MariottiView Answer on Stackoverflow
Solution 8 - KotlinReza BigdeliView Answer on Stackoverflow
Solution 9 - KotlinJeff WongView Answer on Stackoverflow
Solution 10 - KotlinYt100View Answer on Stackoverflow