WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'
Asked Answered
I

28

203

Suddenly when Syncing Gradle, I get this error:

WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'. It will be removed at the end of 2019. For more information, see https://d.android.com/r/tools/task-configuration-avoidance Affected Modules: app

I've got this build.gradle for the app module:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

apply plugin: 'io.fabric'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.2"
    defaultConfig {
        applicationId "..."
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "..."
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        versionNameSuffix = version_suffix

        [...]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

            [...]
        }
        debug {
            [...]
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61"
    implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "com.android.support:preference-v7:28.0.0"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
    implementation 'com.google.android.material:material:1.0.0-rc02'

    [...]
}

I can compile the app correctly, but it's a bit bothering, and as I see it, something will stop working at the end of 2019. Any ideas of what is it and how to solve it?

Issiah answered 23/9, 2018 at 20:36 Comment(6)
Just as a slight nit-pick, a warning is not an error. Even with a warning your code should compile in the same way, whereas an error would cause your build to fail. It's just advanced notice that the current way of doing things may not work in the future, and will likely be fixed with plugin updates. Did you also take the time to read the page linked in the error?Divorcement
My personal feeling is that it's being caused by a plugin that's not been updated to use the new Gradle API yet, which should fix itself in time.Divorcement
Look at this answer. #52412523Apterygial
Try this. https://mcmap.net/q/93067/-api-39-variant-getexternalnativebuildtasks-39-is-obsolete-and-has-been-replaced-with-39-variant-getexternalnativebuildprovidersHamo
Please see #52412523Spheroidal
This is still an issue with 4.3.1 and can be tracked at github.com/google/play-services-plugins/issues/65. Using version 4.2.0 in build.gradle (Project) seems like the most viable solution.Manville
C
83

This issue is fixed now with update Fabric Gradle version 1.30.0:

Update release: March 19, 2019

Please see this Link: https://docs.fabric.io/android/changelog.html#march-15-2019

Please update your classpath dependency in project level Gradle:

buildscript {
    // ... repositories, etc. ...

    dependencies {
        // ...other dependencies ...
        classpath 'io.fabric.tools:gradle:1.30.0'
    }
}
Cropland answered 16/4, 2019 at 8:32 Comment(9)
After upgrading the Fabric Gradle version Rebuild your project then your issue will be resolved.Cropland
this is not the answer. See Ewoks answer.Counterfoil
This is also a correct answer, the easy way to solve the facing problem.Cropland
I have now classpath 'io.fabric.tools:gradle:1.29.0'. What should I do?Chaco
@FaizanMubasher try downgrade your google service to 4.2Considering
@InfiniteLoops suggestion to downgrade to 4.2 seems to work.Sanborn
@Sanborn yeah that's my current version as of now.Considering
Upgraded Fabric to 1.31.0 & Downgraded Google Services to 4.2.0 SolvedCrowson
Fabric is no longer used, use Firebase Crashlytics.Ofeliaofella
B
100

I face this issue after updating to 3.3.0

If you are not doing what error states in gradle file, it is some plugin that still didn't update to the newer API that cause this. To figure out which plugin is it do the following (as explained in "Better debug info when using obsolete API" of 3.3.0 announcement):

  • Add 'android.debug.obsoleteApi=true' to your gradle.properties file which will log error with a more details
  • Try again and read log details. There will be a trace of "problematic" plugin
  • When you identify, try to disable it and see if issue is gone, just to be sure
  • go to github page of plugin and create issue which will contain detailed log and clear description, so you help developers fix it for everyone faster
  • be patient while they fix it, or you fix it and create PR for devs

Hope it helps others

Beckiebeckley answered 16/1, 2019 at 9:30 Comment(6)
This is the most general, useful answer, in my opinion. In my case, this warning is emitted because of use of the Groovy-Android plugin (for Spock tests).Florin
This is the right answer. Who upvoted the gradle version update?Narcosynthesis
This also worked for me, is there any new on this issue? Meanwhile it is supposed nothing we could to do, is it right?Fritillary
@Fritillary actually there is... Contact developer of problematic plugin is step you need to do. It will not be resolved by itself and maybe not even by developer. In the meantime consider replacing plugin with some newer/modern and reconsider if you really need it, cause there is no guarantee whatsoever that 3rd party plugin will be ever fixedBeckiebeckley
Really helpful. In my case it was the Hugo plugin.Villon
after adding android.debug.obsoleteApi=true, To read the logged details: Go to Build tab at the bottom and within the "Build Output" window, click "Toggle View". When you click that the pretty, colors go away, scroll to the top where it says WARNING: API 'variant.getAssemble()' is obsolete. Then below it, it shows REASON: Called from: ... in my case it was due to medium.com/@xabaras/…Counterfoil
C
83

This issue is fixed now with update Fabric Gradle version 1.30.0:

Update release: March 19, 2019

Please see this Link: https://docs.fabric.io/android/changelog.html#march-15-2019

Please update your classpath dependency in project level Gradle:

buildscript {
    // ... repositories, etc. ...

    dependencies {
        // ...other dependencies ...
        classpath 'io.fabric.tools:gradle:1.30.0'
    }
}
Cropland answered 16/4, 2019 at 8:32 Comment(9)
After upgrading the Fabric Gradle version Rebuild your project then your issue will be resolved.Cropland
this is not the answer. See Ewoks answer.Counterfoil
This is also a correct answer, the easy way to solve the facing problem.Cropland
I have now classpath 'io.fabric.tools:gradle:1.29.0'. What should I do?Chaco
@FaizanMubasher try downgrade your google service to 4.2Considering
@InfiniteLoops suggestion to downgrade to 4.2 seems to work.Sanborn
@Sanborn yeah that's my current version as of now.Considering
Upgraded Fabric to 1.31.0 & Downgraded Google Services to 4.2.0 SolvedCrowson
Fabric is no longer used, use Firebase Crashlytics.Ofeliaofella
I
63

In my case, it was caused from gms services 4.3.0. So i had to change it to:

com.google.gms:google-services:4.2.0

I have found this by running:

gradlew sync -Pandroid.debug.obsoleteApi=true

in terminal. Go to view -> tool windows -> Terminal in Android Studio.

Inlay answered 30/6, 2019 at 9:30 Comment(5)
in Ubuntu, unable to run this command how i can do in ubuntu. asking to install package and i install that package still i am not able to run. is there any other way?Kovacev
I just changed my gms google service to 4.2 and the warning disappeared thanks.Considering
@VasudevVyas if in android Studio, just add ./ before the command, that is if the terminal is set to the root of your android project. Otherwise you'll have to cd to the root of the project.Hemistich
Why should I downgrade google-services dependency. It's not a solution.Toscano
@AhamadullahSaikat this will probably be fixed in the future releases. Then you can upgrade it again. This is a workaround until it's fixed by google.Inlay
S
34

This is just a warning and it will probably be fixed before 2019 with plugin updates so don't worry about it. I would recommend you to use compatible versions of your plugins and gradle.

You can check your plugin version and gradle version here for better experience and performance.

https://developer.android.com/studio/releases/gradle-plugin

Try using the stable versions for a smooth and warning/error free code.

Sordino answered 23/9, 2018 at 21:3 Comment(3)
It actually is more insidious than just a warning - it effects code editor and prevents you from searching references to classes.Thersathersites
this is not only in dev/canary editions, also in stable happen that, but, i think is a warning that with newer updates will be fixed.Ritz
@HarshilShah there is no guarantee that problematic plugin will ever be updated. Developers might never even know about the issue. Because of that the best we can do is following: https://mcmap.net/q/127062/-warning-api-39-variant-getjavacompile-39-is-obsolete-and-has-been-replaced-with-39-variant-getjavacompileprovider-39Beckiebeckley
A
24

I also faced the same issue. And after searching for a while, I figured it out that the warning was arising because of using the latest version of google-services plugin (version 4.3.0). I was using this plugin for Firebase functionalities in my application by the way. All I did was to downgrade my google-services plugin in buildscript in the build.gradle(Project) level file as follows:

buildscript{
    dependencies {
       // From =>
       classpath 'com.google.gms:google-services:4.3.0'
       // To =>
       classpath 'com.google.gms:google-services:4.2.0'
    }
}
Ascetic answered 13/7, 2019 at 6:52 Comment(1)
I upgraded to 4.3.2 without this warning coming back.Customer
L
17

1) Add android.debug.obsoleteApi=true to your gradle.properties. It will show you which modules is affected by your the warning log.

2) Update these deprecated functions.

  • variant.javaCompile to variant.javaCompileProvider

  • variant.javaCompile.destinationDir to variant.javaCompileProvider.get().destinationDir

Longerich answered 20/8, 2019 at 9:7 Comment(0)
B
10

Change your Google Services version from your build.gradle:

dependencies {
  classpath 'com.google.gms:google-services:4.2.0'
}
Bolte answered 17/7, 2019 at 0:22 Comment(3)
I'm on 4.3.0 and the issue is still there.Shavonda
@wesleyfranks the same. But if I switch to 4.2.0 I don't have the problem anymore...Maisonette
I'm on 4.3.1 and the issue is still thereCelsacelsius
C
8

This is a warning spit out by build tools for two reasons.
1. One of the plugin is relying on Task instead of TaskProvider, there is nothing much we can do.
2. You have configured usage of task, where as it supports TaskProvider.

WARNING: API 'variant.getGenerateBuildConfig()' is obsolete and has been replaced with 'variant.getGenerateBuildConfigProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance

WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance

WARNING: API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance

Look out for snippets as below & update.

android {
    <library|application>Variants.all { variant ->
        /* Disable Generating Build config */
        // variant.generateBuildConfig.enabled = true // <- Deprecated
        variant.generateBuildConfigProvider.configure {
            it.enabled = true // Replacement
        }
    }
}

Similarly, find usages of 'variant.getJavaCompile()' or 'variant.javaCompile', 'variant.getMergeResources()' or 'variant.mergeResources'. Replace as above.

More information at Task Configuration Avoidance

Cocainize answered 25/9, 2018 at 18:1 Comment(10)
This happens in every Android Studio project. Nothing to do with snippets you mentioned...Thersathersites
@IgorGanapolsky, It would also happen in terminal. Try executing ./gradlew. This has nothing to do with AS, it is in build tools. Upgrade/downgrade to com.android.tools.build:gradle:3.2.0 & execute ./gradlew. This will not come.Cocainize
Did not find variant.generateBuildConfig.enabled in my project. I still get the above warningCanoness
Did not find variant.generateBuildConfig.enabled in my project. I still get the above warningCanoness
@Cocainize This is the most useful answer as per my problem, can you still help with this code snippet? codeshare.io/G6ogzkCorsage
@RaghavSatyadev It is from android build tools, output.outputFile calls deprecated API. This is just a warning, you can still use it.Cocainize
@Cocainize I know, but at some point I have to update it. So was askingCorsage
@RaghavSatyadev You need not update, when android build tools update, this warning will go away :)Cocainize
We're now at gradle plugin 3.5.3 and this warning remains. I tried replacing javaCompile with javaCompileProvider, and it works even though AS does not offer any auto-complete for it. However, the provider that is returned does not have the same properties as the old task. Example: groovy.lang.MissingPropertyException: Could not get unknown property 'source' for provider(task compileReleaseJavaWithJavac, class com.android.build.gradle.tasks.AndroidJavaCompile) of type org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreatingProvider_Decorated.Kentledge
Is there a 1-1 migration guide for how to use the provider instead? I think the "task config avoidance" page was quite unclear.Kentledge
D
5

Upgrading the Kotlin (Plugin and stdLib) version to 1.3.1 solved that warning in my case. Update the Kotlin version in whole project by replacing existing Kotlin version with :

ext.kotlin_version = '1.3.50'
Doxology answered 17/11, 2018 at 4:16 Comment(2)
ext.kotlin_version = '1.3.10' or '1.3.50'Aquacade
this was my issue. before was ext.kotlin_version = '1.2.71' .. Changed it to the answer above and it worked fine! -- i deleted my /android and /ios folders and then ran flutter create . to rebuild the Flutter app and it placed ext.kotlin_version = '1.2.71' in my build.gradleCharissa
H
5

Downgrading the version of Gradle worked for me:

classpath 'com.android.tools.build:gradle:3.2.0'
Hedgehop answered 3/2, 2019 at 11:21 Comment(4)
downgrading is never an optionTraverse
This is the answer what I want .Thank you!Brassware
downgrading is fine in certain circumstancesElisabeth
Of course it will. This is no brainer! But how long when you run out of downgrades?Despoliation
G
4

Go back from classpath 'com.android.tools.build:gradle:3.3.0-alpha13' to classpath 'com.android.tools.build:gradle:3.2.0'

this worked for me

Gerhard answered 10/10, 2018 at 9:16 Comment(2)
that's just temporal workaround cause you can't stay forever on 3.2.0, especially when final 3.3.0 is already outBeckiebeckley
downgrade gradle version is not an option! .Koziel
N
4

Updating gradle to gradle:3.3.0

The default 'assemble' task only applies to normal variants. Add test variants as well.

android.testVariants.all { variant ->
    tasks.getByName('assemble').dependsOn variant.getAssembleProvider()
}

also comment apply fabric

//apply plugin: 'io.fabric'
Nocturnal answered 15/1, 2019 at 14:36 Comment(6)
What are the "normal" variants? What is android.testVariants.all {...} code for (what is the purpose of it)? Where is this quoted text from? Can you please update the answer?Beckiebeckley
I've changed Manifest path for chrashlytics crashlytics { manifestPath = "$buildDir/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml" }Endostosis
@Beckiebeckley normal variants are build variants (debug/release) they using a specific set of rules..you can set many different variants (flavors).. Additionally, you can create testing source sets that target specific build variants.Nocturnal
I know about flavours but not sure that this applies here and how it is related. That's why I asked if you can update the answer by clarifying what source did you quote and to fix formatting (guess you mixed formatting of code with comment)Beckiebeckley
read title of post "WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'" i have the same and that's the way how ive fix..Nocturnal
There is no guarantee that fabric was the source of the issue at all. Actually with this "solution" we have no clue where was the issue. In addition, there is no explanation why to do anything with testVariants and how is that related?!? That's why original answer of @KrsteMoskov is misleading and apply just to specific use case if it solves anything at all. To help you get "on board" I formatted your answer properly and left the content as you wrote it, so others can decide if this is useful for themBeckiebeckley
G
4

Update fabric plugin to the latest in project level Gradle file (not app level). In my case, this line solved the problem

classpath 'io.fabric.tools:gradle:1.25.4'

to

classpath 'io.fabric.tools:gradle:1.29.0'
Gaylene answered 11/4, 2019 at 6:22 Comment(0)
P
3

In my case

build.gradle(Project)

was

ext.kotlin_version = '1.2.71'

updated to

ext.kotlin_version = '1.3.0'

looks problem has gone for now

Platelet answered 6/2, 2019 at 9:6 Comment(1)
That's strange. I updated to 1.4.0 and it appeared. Maybe after upgrade. :)Hedley
B
2

In my case, I had to comment out com.google.firebase.firebase-crash plugin:

apply plugin: 'com.android.application'
// apply plugin: 'com.google.firebase.firebase-crash' <== this plugin causes the error

It is a bug since Android Studio 3.3.0

Benares answered 20/1, 2019 at 9:12 Comment(1)
For me it's happens because I'm using oss-licenses-pluginJehiel
D
2

if I remove this row from application gradle:

apply plugin: 'io.fabric'

error will not appear anymore.

Reference link github

Donata answered 27/1, 2019 at 13:19 Comment(1)
DO NOT DO THIS otherwise Crashlytics will stop working. This is just hiding the problem.Firehouse
B
2

When the plugin detects that you're using an API that's no longer supported, it can now provide more-detailed information to help you determine where that API is being used. To see the additional info, you need to include the following in your project's gradle.properties file:

android.debug.obsoleteApi=true
Bulky answered 29/1, 2019 at 6:42 Comment(2)
where build,gradle or app.gradleUnderlinen
just search for gradle.properties file in your projectBulky
W
2

Migrate your project to androidX.

dependencies are upgraded to androidX. so if you want to use androidX contents migrate your project to androidX.

With Android Studio 3.2 and higher, you can quickly migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

Downgrading dependencies may fix your problem this time - but not recommended

Wattenberg answered 12/7, 2019 at 6:5 Comment(1)
I have AndroidX and i´m still getting the message.Koziel
C
1

This fixed my problem.. All I needed to do was to downgrade my google-services plugin in buildscript in the build.gradle(Project) level file as follows

buildscript{
     dependencies {
        // From =>
        classpath 'com.google.gms:google-services:4.3.0'
        // To =>
        classpath 'com.google.gms:google-services:4.2.0'
        // Add dependency
        classpath 'io.fabric.tools:gradle:1.28.1'
    }
}
Carnahan answered 11/7, 2019 at 10:21 Comment(0)
D
0

Here a temporary workaround, If you are using room just upgrade to 1.1.0 or higher

implementation "android.arch.persistence.room:runtime:1.1.0"

it removes this warning for me.

Desert answered 18/10, 2018 at 16:30 Comment(1)
yes, when I update the version, theses warning are goneDesert
G
0

keep you Project(not app) Build.gradle dependncies classpath version code is new

 dependencies {
    classpath 'com.android.tools.build:gradle:3.5.0-beta01'
    classpath 'com.novoda:bintray-release:0.8.1'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
Geriatrician answered 18/5, 2019 at 7:2 Comment(0)
H
0

This is a popular question. If you do not use these methods, the solution is updating the libraries. Please update your kotlin version, and all your dependencies like fabric, protobuf etc. If you are sure that you have updated everything, try asking the author of the library.

Haver answered 15/7, 2019 at 13:37 Comment(0)
D
0

Upgrading protobuf-gradle-plugin to version 0.8.10 solved my problem. Replace your existing protobuf with

classpath 'gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.10'
Downs answered 25/9, 2019 at 8:51 Comment(0)
I
0

That's mostly due to libraries which are obsolete. To check for new updates manually, you should navigate to

Analyze > "Run Inspection By Name"

run inspection by name android result

That should be enough. Another option is to run a gradle dependency update using

./gradlew dependencyUpdates

that will produce a report like this:

:dependencyUpdates

------------------------------------------------------------
: Project Dependency Updates (report to plain text file)
------------------------------------------------------------

The following dependencies are using the latest milestone version:
 - com.github.ben-manes:gradle-versions-plugin:0.15.0

The following dependencies have later milestone versions:
 - com.google.auto.value:auto-value [1.4 -> 1.4.1]
 - com.google.errorprone:error_prone_core [2.0.19 -> 2.0.21]
 - com.google.guava:guava [21.0 -> 23.0-rc1]
 - net.ltgt.gradle:gradle-apt-plugin [0.9 -> 0.10]
 - net.ltgt.gradle:gradle-errorprone-plugin [0.0.10 -> 0.0.11]

...
Ideational answered 26/9, 2019 at 21:14 Comment(0)
M
0

upgrading the google services in project-level build.gradle solved my problem.

After upgrading:

dependencies {
    ...
    classpath 'com.google.gms:google-services:4.3.2'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
Merrifield answered 5/11, 2019 at 6:24 Comment(0)
E
0

I had same problem and it solved by defining kotlin gradle plugin version in build.gradle file.

change this

 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

to

 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50{or latest version}"
Engstrom answered 20/2, 2020 at 8:44 Comment(1)
Thanks! So, we also have to change in app\build.gradle: implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.0". Then instead of warning we will receive the same message as information.Hedley
H
0

In my case I followed this. Summary, in gradle app level: change this :

variant.outputs.all { output ->
    variant.assemble.doLast {
        ....
    }
}

to

variant.outputs.all { output ->
variant.getAssembleProvider().configure() {
    it.doLast { 
        ....
    }
}
Hotfoot answered 1/3, 2020 at 19:25 Comment(0)
F
0

Change this with new provider API as follows

variant.getJavaCompileProvider().configure() { javaCompile ->
      // You have javaCompile object, you can play with it here. 
}

Thanks

Floss answered 26/3, 2023 at 6:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.