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

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?

The answer is


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


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.


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.


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

Change your Google Services version from your build.gradle:

dependencies {
  classpath 'com.google.gms:google-services:4.2.0'
}

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


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


Downgrading the version of Gradle worked for me:

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

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'

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


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'

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


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


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'

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


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

if I remove this row from application gradle:

apply plugin: 'io.fabric'

error will not appear anymore.

Reference link github


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

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.


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
}

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.


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

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 { 
        ....
    }
}

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
}

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]

...

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'

Questions with android tag:

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks Why am I seeing net::ERR_CLEARTEXT_NOT_PERMITTED errors after upgrading to Cordova Android 8? "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util No Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator WebView showing ERR_CLEARTEXT_NOT_PERMITTED although site is HTTPS WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' GoogleMaps API KEY for testing Can I use library that used android support with Androidx projects. How to allow all Network connection types HTTP and HTTPS in Android (9) Pie? Android Material and appcompat Manifest merger failed Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 How to format DateTime in Flutter , How to get current time in flutter? How to change package name in flutter? Failed to resolve: com.android.support:appcompat-v7:28.0 What is AndroidX? Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve FirebaseInstanceIdService is deprecated installation app blocked by play protect Handling back button in Android Navigation Component Android design support library for API 28 (P) not working Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Install Android App Bundle on device Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. How to develop Android app completely using python? Invoke-customs are only supported starting with android 0 --min-api 26 Flutter.io Android License Status Unknown How to open Android Device Monitor in latest Android Studio 3.1 Default interface methods are only supported starting with Android N How can I change the app display name build with Flutter? Error:(9, 5) error: resource android:attr/dialogCornerRadius not found error: resource android:attr/fontVariationSettings not found Flutter does not find android sdk Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0) Error : Program type already present: android.support.design.widget.CoordinatorLayout$Behavior flutter run: No connected devices Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6 Still getting warning : Configuration 'compile' is obsolete and has been replaced with 'implementation' PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT (in windows 10)

Questions with android-studio tag:

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK Invoke-customs are only supported starting with android 0 --min-api 26 How do I convert 2018-04-10T04:00:00.000Z string to DateTime? How to open Android Device Monitor in latest Android Studio 3.1 flutter run: No connected devices Dart SDK is not configured PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT (in windows 10) Execution failed for task ':app:compileDebugJavaWithJavac' Android Studio 3.1 Update Android Studio AVD - Emulator: Process finished with exit code 1 Android Studio Emulator and "Process finished with exit code 0" How can I fix "Design editor is unavailable until a successful build" error? INSTALL_FAILED_USER_RESTRICTED : android studio using redmi 4 device Why AVD Manager options are not showing in Android Studio Failed to resolve: com.android.support:appcompat-v7:27.+ (Dependency Error) "The specified Android SDK Build Tools version (26.0.0) is ignored..." Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0 Getting error "The package appears to be corrupt" while installing apk file Android studio 3.0: Unable to resolve dependency for :app@dexOptions/compileClasspath': Could not resolve project :animators Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0] Android Studio 3.0 Flavor Dimension Issue Android Studio - Failed to notify project evaluation listener error Could not find com.android.tools.build:gradle:3.0.0-alpha1 in circle ci Gradle error: Minimum supported Gradle version is 3.3. Current version is 3.2 Application Installation Failed in Android Studio Error:Failed to open zip file. Gradle's dependency cache may be corrupt Difference between signature versions - V1 (Jar Signature) and V2 (Full APK Signature) while generating a signed APK in Android Studio? Error:Cause: unable to find valid certification path to requested target How to switch from the default ConstraintLayout to RelativeLayout in Android Studio Installation failed with message Invalid File Warnings Your Apk Is Using Permissions That Require A Privacy Policy: (android.permission.READ_PHONE_STATE) error: package com.android.annotations does not exist 'Source code does not match the bytecode' when debugging on a device How to completely uninstall Android Studio from windows(v10)? How to show DatePickerDialog on Button click? You have not accepted the license agreements of the following SDK components Enable VT-x in your BIOS security settings (refer to documentation for your computer) "unable to locate adb" using Android Studio DELETE_FAILED_INTERNAL_ERROR Error while Installing APK Gradle Sync failed could not find constraint-layout:1.0.0-alpha2 This view is not constrained vertically. At runtime it will jump to the left unless you add a vertical constraint Android Studio Error: Error:CreateProcess error=216, This version of %1 is not compatible with the version of Windows you're running

Questions with compilation tag:

WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' How to enable C++17 compiling in Visual Studio? How can I use/create dynamic template to compile dynamic Component with Angular 2.0? Microsoft Visual C++ Compiler for Python 3.4 C compile : collect2: error: ld returned 1 exit status Error:java: invalid source release: 8 in Intellij. What does it mean? Eclipse won't compile/run java file IntelliJ IDEA 13 uses Java 1.5 despite setting to 1.7 OPTION (RECOMPILE) is Always Faster; Why? (.text+0x20): undefined reference to `main' and undefined reference to function How to fix error with xml2-config not found when installing PHP from sources? Undefined Symbols for architecture x86_64: Compiling problems The POM for project is missing, no dependency information available How can I compile and run c# program without using visual studio? Compiling dynamic HTML strings from database Compilation error - missing zlib.h How to create a shared library with cmake? Javac is not found How do I link object files in C? Fails with "Undefined symbols for architecture x86_64" What is the difference between a token and a lexeme? Mismatch Detected for 'RuntimeLibrary' How to fix JSP compiler warning: one JAR was scanned for TLDs yet contained no TLDs? How to recompile with -fPIC C++ compile error: has initializer but incomplete type How to watch and compile all TypeScript sources? How to compile python script to binary executable Cross compile Go on OSX? Less aggressive compilation with CSS3 calc How to run Java program in command prompt Compiling and Running Java Code in Sublime Text 2 What are .a and .so files? ARM compilation error, VFP registers used by executable, not object file How do I invoke a text editor from the terminal? Why does changing 0.1f to 0 slow down performance by 10x? Compile error: package javax.servlet does not exist What's an object file in C? Unable to locate tools.jar Is there a way to compile node.js source files? How do I run Java .class files? Expected initializer before function name javac : command not found Compiling php with curl, where is curl installed? Java: How can I compile an entire directory structure of code ? How do I show a console output/window in a forms application? How can I check the syntax of Python script without executing it? How can I compile a Java program in Eclipse without running it? The project cannot be built until the build path errors are resolved. Using G++ to compile multiple .cpp and .h files Skipping Incompatible Libraries at compile How do I compile and run a program in Java on my Mac?

Questions with android-gradle-plugin tag:

WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Android Material and appcompat Manifest merger failed Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries Invoke-customs are only supported starting with android 0 --min-api 26 error: resource android:attr/fontVariationSettings not found Exception : AAPT2 error: check logs for details Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project Failed to resolve: com.android.support:appcompat-v7:27.+ (Dependency Error) "The specified Android SDK Build Tools version (26.0.0) is ignored..." Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0 Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Android studio 3.0: Unable to resolve dependency for :app@dexOptions/compileClasspath': Could not resolve project :animators Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0] Failed to resolve: com.android.support:appcompat-v7:26.0.0 No resource found that matches the given name: attr 'android:keyboardNavigationCluster'. when updating to Support Library 26.0.0 Failed to resolve: com.android.support:cardview-v7:26.0.0 android Android dependency has different version for the compile and runtime ionic 2 - Error Could not find an installed version of Gradle either in Android Studio Gradle error: Minimum supported Gradle version is 3.3. Current version is 3.2 Kotlin Error : Could not find org.jetbrains.kotlin:kotlin-stdlib-jre7:1.0.7 Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK - Android Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored' error: package com.android.annotations does not exist Automatically accept all SDK licences Class file for com.google.android.gms.internal.zzaja not found Error:Conflict with dependency 'com.google.code.findbugs:jsr305' Could not find method android() for arguments Android Studio - Failed to apply plugin [id 'com.android.application'] The number of method references in a .dex file cannot exceed 64k API 17 Android- Error:Execution failed for task ':app:transformClassesWithDexForRelease' Error: No toolchains found in the NDK toolchains folder for ABI with prefix: llvm configuring project ':app' failed to find Build Tools revision "Gradle Version 2.10 is required." Error Gradle version 2.2 is required. Current version is 2.10 Android Studio Gradle: Error:Execution failed for task ':app:processDebugGoogleServices'. > No matching client found for package Error "File google-services.json is missing from module root folder. The Google Services Plugin cannot function without it" Error:Execution failed for task ':app:transformClassesWithDexForDebug' Error:Unknown host services.gradle.org. You may need to adjust the proxy settings in Gradle Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.1.0) and test app (23.0.1) differ Error: Execution failed for task ':app:clean'. Unable to delete file HttpClient won't import in Android Studio Android Gradle Apache HttpClient does not exist? Error running android: Gradle project sync failed. Please fix your project and try again Could not find or load main class org.gradle.wrapper.GradleWrapperMain Execution failed for task ':app:compileDebugAidl': aidl is missing finished with non zero exit value Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to Error:Execution failed for task ':ProjectName:mergeDebugResources'. > Crunching Cruncher *some file* failed, see logs

Questions with google-fabric tag:

The iOS Simulator deployment targets is set to 7.0, but the range of supported deployment target version for this platform is 8.0 to 12.1 WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'