Android Gradle - 在哪里添加“android.debug.obsoleteApi=true" [英] Android Gradle - Where to add "android.debug.obsoleteApi=true"

查看:133
本文介绍了Android Gradle - 在哪里添加“android.debug.obsoleteApi=true"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

警告:API 'variant.getExternalNativeBuildTasks()' 已过时且已替换为variant.getExternalNativeBuildProviders()".它将于 2019 年底移除.有关更多信息,请参阅https://d.android.com/r/tools/task-configuration-avoidance.到确定是什么调用了variant.getExternalNativeBuildTasks(),使用-Pandroid.debug.obsoleteApi=true 在命令行上显示堆栈跟踪.受影响的模块:app

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:

要查看附加信息,您需要在您的项目的 gradle.properties 文件:

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

android.debug.obsoleteApi=true

android.debug.obsoleteApi=true

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

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

文档如下所示:

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:

无法获得根项目 [我的项目] 的未知属性android"org.gradle.api.Project 类型.

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

那么这个应该加在哪里呢?或者我是否混合了 gradle 文件的项目"和应用程序"的定义?

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

推荐答案

您需要将它放在 gradle.properties 文件中,该文件存在于项目级别,位于应用程序文件夹之外 不是在您当前尝试执行的 build.gradle 文件中.

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.

来自安卓开发者文档

使用过时 API 时的更好调试信息:当插件检测到您使用的 API 不再受支持时,它现在可以提供更详细的信息来帮助您确定使用该 API 的位置.要查看其他信息,您需要在项目的 gradle.properties 文件中包含以下内容:

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
您还可以通过从命令行传递 -Pandroid.debug.obsoleteApi=true 来启用该标志.

android.debug.obsoleteApi=true
You can also enable the flag by passing -Pandroid.debug.obsoleteApi=true from the command line.

您可以查看此链接.

这篇关于Android Gradle - 在哪里添加“android.debug.obsoleteApi=true"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆