How to resolve the deprecated warning for 'variant.getExternalNativeBuildTasks()' by switching to 'variant.getExternalNativeBuildProviders()'

I am currently using Android Studio 3.3 Canary 11 along with the gradle plugin version 3.3.0-alpha11. While syncing my gradle, I encounter a deprecation warning that states:

WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been 
replaced with 'variant.getExternalNativeBuildProviders()'.
It will no longer be available after 2019.
Affected Modules: app

This warning is associated with the following section of my app’s build.gradle file:

applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = "${variant.name}-${variant.versionName}.apk"
    }
}

Here’s a brief overview of my main build.gradle configuration:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha11'
        classpath "io.realm:realm-gradle-plugin:4.1.1"
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

ext {
    minSdkVersion = 21
    targetSdkVersion = 27
    compileSdkVersion = 27
    buildToolsVersion = '27.0.3'
    supportLibraryVersion = '27.1.1'
}

Also, here’s how my app module build.gradle looks like:

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    
    defaultConfig {
        applicationId "com.myapp.example"
        minSdkVersion rootProject.ext.minSdkVersion
        multiDexEnabled true
        versionCode appVersionCode
        versionName appVersionName
    }
    
    buildTypes {
        applicationVariants.all { variant ->
            variant.outputs.all {
                outputFileName = "${variant.name}-${variant.versionName}.apk"
            }
        }
        
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        
        debug {
            minifyEnabled true
            debuggable true
            versionNameSuffix '-DEBUG'
        }
    }
}

What modifications should I make to address this deprecation issue? Can you guide me on how to correctly implement the newer API?

Your deprecation warning looks like a false positive. The code you showed with applicationVariants.all and variant.outputs.all doesn’t use getExternalNativeBuildTasks() at all. This warning pops up when you have native build configs (CMake or ndk-build) in your project, even when the actual problematic code isn’t in your build files. I’ve hit this same issue with alpha versions of the Android Gradle Plugin. Usually it’s coming from internal plugin stuff or third-party plugins that haven’t caught up yet. Check if your Realm plugin might be the culprit. Since you’re on an alpha version, try updating to stable if you can. If you’re stuck with the current version, don’t worry - the warning won’t break your build, it’s just a compatibility heads-up. You’d only need to migrate to getExternalNativeBuildProviders() if you’re directly calling the deprecated method in custom tasks or plugin code.

The warning you are seeing is likely not due to the code you provided. The applicationVariants.all block you mentioned does not interact with native build configurations. This warning typically occurs when there are references to NDK or CMake setups in your project, or possibly due to third-party plugins that have not yet updated to the newer API. It’s possible that the Realm or Google Services plugins could be the source of this warning. I’ve encountered similar issues with older plugins not being compatible with newer Gradle versions. You may want to check your Android configuration for any externalNativeBuild sections or custom tasks invoking native build methods. Since you are currently using an alpha version of the Gradle plugin, there could also be a known bug that was addressed in a stable release. Fortunately, this deprecation warning will not impact your builds until after 2019, so you can continue developing without concern.

i think tom’s right! the warning likely comes from the realm or google services plugin using the old api. for now, just carry on - it’s not gonna break your build during these alpha versions.