35

I updated to AndroidStudio 3.3 which now gives a warning about deprecated libraries:

WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders()'. It will be removed at the end of 2019. For more information, see https://d.android.com/r/tools/task-configuration-avoidance. To determine what is calling variant.getExternalNativeBuildTasks(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace. Affected Modules: app

There is some more info provided at their web site:

https://developer.android.com/studio/releases/gradle-plugin?utm_source=android-studio#behavior_changes

but I don't exactly understand it. They say:

To see the additional info, you need to include the following in your project's gradle.properties file:

android.debug.obsoleteApi=true

So I took the build.gradle that is marked with (Project: [my project])

The document looks like this:

buildscript {
    ext.kotlin_version = '1.3.10'
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:4.0.1'
        classpath 'com.github.triplet.gradle:play-publisher:1.1.5'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://jitpack.io"
        }
        mavenCentral()
    }
}

project.ext.preDexLibs = !project.hasProperty('disablePreDex')

subprojects {
    project.plugins.whenPluginAdded { plugin ->
        if ("com.android.build.gradle.AppPlugin" == plugin.class.name) {
            project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
        } else if ("com.android.build.gradle.LibraryPlugin" == plugin.class.name) {
            project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
        }
    }
}
repositories {
    mavenCentral()
}

However, I don't understand, where I should add that line now. And no matter where I put it, I always get an error.

E.g. when writing it directly in the first line:

Could not get unknown property 'android' for root project [my project] of type org.gradle.api.Project.

So where is this supposed to be added? Or am I mixing the definitions of "Project" and "app" for the gradle files?

Tobias Reich
  • 4,952
  • 3
  • 47
  • 90
  • Now that you know the solution for this, have you find the solution for the warning? I am having the same issue with variant.getMergeResources() which is obsolete. I could use any hint for this. Thanks! – sunlover3 Aug 19 '19 at 07:39
  • To be honest, I haven't had a look at this issue for a while but let me know once you find out anything. :) – Tobias Reich Aug 20 '19 at 08:25

3 Answers3

51

You need to put it in gradle.properties file which is present at the project level, outside of the app folder not in build.gradle file which you are currently trying to do.

From the android developer documentation

Better debug info when using obsolete API: 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
You can also enable the flag by passing -Pandroid.debug.obsoleteApi=true from the command line.

You can check this Link.

Community
  • 1
  • 1
Nitesh
  • 3,868
  • 1
  • 20
  • 26
11

The easiest way is do it in the terminal at the root of the android project.

Run the following command:

 ./gradlew -Pandroid.debug.obsoleteApi=true
Allen
  • 2,979
  • 1
  • 29
  • 34
4

As stated in the error message, you should add that in gradle.properties file and not in any of your build.gradle files

Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84