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

144,904

Solution 1

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

Solution 2

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

Solution 3

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.

Solution 4

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.

Solution 5

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'
    }
}
Share:
144,904

Related videos on Youtube

Arnyminer Z
Author by

Arnyminer Z

Updated on July 08, 2022

Comments

  • Arnyminer Z
    Arnyminer Z almost 2 years

    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?

    • Michael Dodd
      Michael Dodd almost 6 years
      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?
    • Michael Dodd
      Michael Dodd almost 6 years
      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.
    • Rahul Kushwaha
      Rahul Kushwaha over 5 years
    • 0xAliHn
      0xAliHn over 5 years
    • David Figueroa
      David Figueroa over 5 years
    • Asghar Musani
      Asghar Musani almost 5 years
      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.
  • IgorGanapolsky
    IgorGanapolsky almost 6 years
    This happens in every Android Studio project. Nothing to do with snippets you mentioned...
  • VenomVendor
    VenomVendor over 5 years
    @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.
  • IgorGanapolsky
    IgorGanapolsky over 5 years
    It actually is more insidious than just a warning - it effects code editor and prevents you from searching references to classes.
  • Marlon López
    Marlon López over 5 years
    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.
  • Ewoks
    Ewoks over 5 years
    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?
  • A.N.R.I
    A.N.R.I over 5 years
    I've changed Manifest path for chrashlytics crashlytics { manifestPath = "$buildDir/intermediates/aapt_friendly_merged_manifests/debu‌​g/processDebugManife‌​st/aapt/AndroidManif‌​est.xml" }
  • Krste Moskov
    Krste Moskov over 5 years
    @Ewoks 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.
  • Ewoks
    Ewoks over 5 years
    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)
  • Krste Moskov
    Krste Moskov over 5 years
    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..
  • AutonomousApps
    AutonomousApps over 5 years
    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).
  • Mikhail
    Mikhail over 5 years
    For me it's happens because I'm using oss-licenses-plugin
  • Ewoks
    Ewoks over 5 years
    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 them
  • Ewoks
    Ewoks over 5 years
    @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: stackoverflow.com/a/54213973/304270
  • Ewoks
    Ewoks over 5 years
    that's just temporal workaround cause you can't stay forever on 3.2.0, especially when final 3.3.0 is already out
  • Sergio KS
    Sergio KS over 5 years
    yes, when I update the version, theses warning are gone
  • Pier Betos
    Pier Betos over 5 years
    This is the right answer. Who upvoted the gradle version update?
  • kbsbng
    kbsbng over 5 years
    Did not find variant.generateBuildConfig.enabled in my project. I still get the above warning
  • kbsbng
    kbsbng over 5 years
    Did not find variant.generateBuildConfig.enabled in my project. I still get the above warning
  • Jorgesys
    Jorgesys over 5 years
    downgrade gradle version is not an option! .
  • Raghav Satyadev
    Raghav Satyadev over 5 years
    @VenomVendor This is the most useful answer as per my problem, can you still help with this code snippet? codeshare.io/G6ogzk
  • VenomVendor
    VenomVendor over 5 years
    @RaghavSatyadev It is from android build tools, output.outputFile calls deprecated API. This is just a warning, you can still use it.
  • Raghav Satyadev
    Raghav Satyadev over 5 years
    @VenomVendor I know, but at some point I have to update it. So was asking
  • VenomVendor
    VenomVendor over 5 years
    @RaghavSatyadev You need not update, when android build tools update, this warning will go away :)
  • Billyjoker
    Billyjoker over 5 years
    This also worked for me, is there any new on this issue? Meanwhile it is supposed nothing we could to do, is it right?
  • Ewoks
    Ewoks over 5 years
    @Billyjoker 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 fixed
  • AlvaroSantisteban
    AlvaroSantisteban over 5 years
    Really helpful. In my case it was the Hugo plugin.
  • Roshana Pitigala
    Roshana Pitigala about 5 years
    downgrading is never an option
  • Muhammad Noman
    Muhammad Noman about 5 years
    After upgrading the Fabric Gradle version Rebuild your project then your issue will be resolved.
  • Someone Somewhere
    Someone Somewhere about 5 years
    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/…
  • Someone Somewhere
    Someone Somewhere about 5 years
    this is not the answer. See Ewoks answer.
  • Muhammad Noman
    Muhammad Noman about 5 years
    This is also a correct answer, the easy way to solve the facing problem.
  • Faizan Mubasher
    Faizan Mubasher almost 5 years
    I have now classpath 'io.fabric.tools:gradle:1.29.0'. What should I do?
  • Vasudev Vyas
    Vasudev Vyas almost 5 years
    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?
  • Infinite Loops
    Infinite Loops almost 5 years
    I just changed my gms google service to 4.2 and the warning disappeared thanks.
  • Infinite Loops
    Infinite Loops almost 5 years
    @FaizanMubasher try downgrade your google service to 4.2
  • Guanaco Devs
    Guanaco Devs almost 5 years
    @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.
  • Ahamadullah Saikat
    Ahamadullah Saikat almost 5 years
    Why should I downgrade google-services dependency. It's not a solution.
  • HondaGuy
    HondaGuy almost 5 years
    @InfiniteLoops suggestion to downgrade to 4.2 seems to work.
  • Numan Karaaslan
    Numan Karaaslan almost 5 years
    @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.
  • Infinite Loops
    Infinite Loops almost 5 years
    @HondaGuy yeah that's my current version as of now.
  • linjiejun
    linjiejun almost 5 years
    This is the answer what I want .Thank you!
  • Mukeshkumar S
    Mukeshkumar S almost 5 years
    Upgraded Fabric to 1.31.0 & Downgraded Google Services to 4.2.0 Solved
  • wesley franks
    wesley franks almost 5 years
    I'm on 4.3.0 and the issue is still there.
  • wesley franks
    wesley franks almost 5 years
    I did this solution and the error went away. Thank you
  • diAz
    diAz almost 5 years
    @wesleyfranks the same. But if I switch to 4.2.0 I don't have the problem anymore...
  • Roger Oba
    Roger Oba almost 5 years
    DO NOT DO THIS otherwise Crashlytics will stop working. This is just hiding the problem.
  • Сергей
    Сергей almost 5 years
    Working! Thanks
  • Jorgesys
    Jorgesys almost 5 years
    I have AndroidX and i´m still getting the message.
  • pvalle
    pvalle almost 5 years
    I'm on 4.3.1 and the issue is still there
  • tagy22
    tagy22 over 4 years
    I upgraded to 4.3.2 without this warning coming back.
  • Pushkin
    Pushkin over 4 years
    ext.kotlin_version = '1.3.10' or '1.3.50'
  • MaylorTaylor
    MaylorTaylor over 4 years
    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.gradle
  • martinseal1987
    martinseal1987 over 4 years
    downgrading is fine in certain circumstances
  • Jithish P N
    Jithish P N over 4 years
    where build,gradle or app.gradle
  • Hamed safari
    Hamed safari over 4 years
    just search for gradle.properties file in your project
  • JHH
    JHH over 4 years
    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$TaskCreat‌​ingProvider_Decorate‌​d.
  • JHH
    JHH over 4 years
    Is there a 1-1 migration guide for how to use the provider instead? I think the "task config avoidance" page was quite unclear.
  • CoolMind
    CoolMind almost 4 years
    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.
  • CoolMind
    CoolMind almost 4 years
    That's strange. I updated to 1.4.0 and it appeared. Maybe after upgrade. :)
  • sud007
    sud007 over 2 years
    Of course it will. This is no brainer! But how long when you run out of downgrades?
  • Abhinav Saxena
    Abhinav Saxena over 2 years
    Fabric is no longer used, use Firebase Crashlytics.