How to update deprecated 'getExternalNativeBuildTasks()' method in Android Gradle plugin?

I’m having trouble with Android Studio 3.3 Canary 11 and gradle plugin 3.3.0-alpha11. When I try to sync my project, I get this warning:

WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been 
replaced with 'variant.getExternalNativeBuildProviders()'.
It will be removed at the end of 2019.

The error points to this part of my gradle file:

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

What changes do I need to make to fix this? I’ve looked at my project and app build.gradle files but I’m not sure what to update. Any help would be great!

hey there! i had the same issue. try updating your gradle plugin to the latest version. in your project-level build.gradle, change:

classpath ‘com.android.tools.build:gradle:3.3.0-alpha11’

to:

classpath ‘com.android.tools.build:gradle:3.5.0’

that fixed it for me. hope it helps!

I’ve encountered this issue in one of my projects recently. The warning you’re seeing is due to changes in the Android Gradle Plugin aimed at improving build performance. While updating the plugin version can help, it’s not always feasible, especially for legacy projects.

Here’s what worked for me without requiring a full plugin update:

In your app-level build.gradle file, try replacing the applicationVariants block with this:

android {
applicationVariants.all { variant →
variant.outputs.all { output →
outputFileName = “${variant.name}-${variant.versionName}.apk”
}
}
}

This approach avoids using the deprecated method altogether. After making this change, clean and rebuild your project. If you’re still seeing issues, you might need to update your Gradle wrapper version in the gradle-wrapper.properties file.

Remember, these deprecation warnings are usually a heads-up for future removals, so it’s good practice to address them when you can. Hope this helps!

I’ve dealt with this issue before. The warning is due to changes in the Android Gradle Plugin. While updating the plugin version can help, it’s not always the best solution, especially if you’re working on a legacy project.

Instead, try modifying your build.gradle file. Add this line to your android block:

android {

androidResources {
ignoreAssetsPattern ‘!.svn:!.git:!.ds_store:!.scc:.:!CVS:!thumbs.db:!picasa.ini:!*~’
}
}

This approach worked for me without requiring a full plugin update. It essentially tells Gradle to ignore certain file patterns during the build process, which can bypass the deprecated method call.

Remember to clean and rebuild your project after making this change. If you’re still having issues, consider gradually updating your dependencies one by one to identify any conflicts.