Android Gradle - 在哪里添加 "android.debug.obsoleteApi=true"

标签 android android-studio android-gradle-plugin

我已更新到 AndroidStudio 3.3,它现在会发出有关已弃用库的警告:

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

他们的网站上提供了更多信息:

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

但我并不完全理解它。他们说:

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

android.debug.obsoleteApi=true

所以我拿了标有 (Project: [my project]) 的 build.gradle

文档如下所示:

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()
}

但是,我不明白,我现在应该在哪里添加该行。而且无论我把它放在哪里,我总是会出错。

例如直接写在第一行的时候:

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

那么应该在哪里添加呢?还是我混合了 gradle 文件的“项目”和“应用程序”的定义?

最佳答案

你需要把它放到 gradle.properties 文件中code> 文件,您当前正在尝试执行此操作。

来自 android 开发者文档

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.

您可以查看 Link .

关于Android Gradle - 在哪里添加 "android.debug.obsoleteApi=true",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54198773/

相关文章:

android - View 的屏幕截图始终为空。安卓

android-studio - RecyclerView( Kotlin ): Adding an swipe to delete functionality on a ToDo app with data in SQL database

android - com.android.tools.build:gradle:2.1.0及更高版本在构建时出错

android - 如何在 Android Studio 中构建 AOSP 项目

android - Android Studio的.idea/libraries中 "Gradle_"开头的文件是怎么生成的?

android - 错误 :org. gradle.internal.UncheckedException: 构建命令失败

java - 无法在 Android 中的 URL 中发送阿拉伯字符

java - 读取文本文件并将其拆分为数组 - Android

java - 特征检测

java - 在Android Studio上通过Intent将变量 "date"传递给另一个类,NULL OBJECT REFERENCE