Resolving the deprecated 'variant.getExternalNativeBuildTasks()' issue in Android Studio 3.3

I am currently using Android Studio 3.3 Canary 11 with gradle plugin version 3.3.0-alpha11, and I encounter a deprecation warning during the gradle sync process:

WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete. The recommended alternative is 'variant.getExternalNativeBuildProviders()'. This will be completely removed after 2019.
Affected Modules: app

This warning relates to the following code snippet in my app module’s build.gradle file:

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

I’m a bit confused about what changes I should implement here. As this code seems to just handle APK file naming, I’m unsure why it’s causing the deprecation warning.

As for my project level build.gradle:

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'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext {
    minSdkVersion = 21
    targetSdkVersion = 27
    compileSdkVersion = 27
    buildToolsVersion = '27.0.3'
    supportLibraryVersion = '27.1.1'
    appCompactLibraryVersion = '27.1.1'
    playServicesVersion = '15.0.1'
    firebaseVersionCore = '16.0.1'
    firebaseVersionPerf = '16.0.0'
    firebaseVersionMessaging = '17.1.0'
    lottieVersion = '2.5.0'
}

And here is my app module’s build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'

android {
    realm {
        syncEnabled = false
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        applicationId "com.myapp.example"
        minSdkVersion rootProject.ext.minSdkVersion
        multiDexEnabled true
        versionCode appVersionCode
        versionName appVersionName
        vectorDrawables.useSupportLibrary = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

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

        release {
            shrinkResources true
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            lintOptions {
                disable 'MissingTranslation'
            }
        }

        debug {
            shrinkResources true
            minifyEnabled true
            useProguard true
            debuggable true
            versionNameSuffix '-DEBUG'
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'debug-proguard-rules.pro'
            ext.enableCrashlytics = false
            crunchPngs false
        }
    }

    flavorDimensions "default"

    lintOptions {
        checkReleaseBuilds false
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LGPL2.1'
    }
    buildToolsVersion '28.0.2'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "com.android.support:appcompat-v7:$rootProject.appCompactLibraryVersion"
    implementation "com.android.support:support-compat:$rootProject.supportLibraryVersion"
    implementation "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:design:$rootProject.supportLibraryVersion"
    
    api 'com.squareup.retrofit2:retrofit:2.4.0'
    api 'com.squareup.okhttp3:okhttp:3.11.0'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.android.support:multidex:1.0.3'
    
    implementation "com.google.firebase:firebase-core:$rootProject.firebaseVersionCore"
    implementation "com.google.firebase:firebase-perf:$rootProject.firebaseVersionPerf"
    implementation "com.google.firebase:firebase-messaging:$rootProject.firebaseVersionMessaging"
    
    api('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
        transitive = true
    }
}

apply plugin: 'com.google.gms.google-services'

I would appreciate detailed guidance on the necessary adjustments to eliminate this deprecation warning.

Had the same issue with gradle 3.3.0-alpha builds. The warning wasn’t from my APK naming code either. ExternalNativeBuildTasks deprecation gets thrown by plugins that iterate through variants and check for native build tasks. I’m betting it’s your realm-gradle-plugin or one of the firebase plugins - they hook into the build process. Comment out realm and firebase plugins one at a time to see which one’s causing it. Your realm plugin 4.1.1 probably isn’t fully compatible with gradle plugin 3.3.0-alpha11 yet. Try upgrading realm or downgrading your gradle plugin until the plugin ecosystem catches up with alpha releases.

that’s weird - your apk naming code shouldn’t trigger that ExternalNativeBuildTasks warning. that warning typically comes from native code builds like cmake or ndk stuff. check if you’ve got other plugins or dependencies calling the deprecated method. could be realm or firebase doing it indirectly.

That deprecation warning has nothing to do with your APK naming code - it’s completely unrelated. The warning pops up when something calls the old getExternalNativeBuildTasks() method, which handles CMake or NDK builds. I’ve debugged this before and it’s usually a third-party plugin that hasn’t caught up with your newer gradle version. Looking at your setup, I’d bet it’s the google-services plugin version 3.2.1 - that’s pretty outdated for your alpha gradle plugin. Try bumping it to 4.0.0 or newer. Also check if firebase-plugins 1.1.5 plays nice with gradle 3.3.0-alpha11. These service plugins love to poke around build variants and probably use deprecated APIs under the hood.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.