如何使用Android Gradle插件3.0.0+来操纵变量输出? [英] How can Variant Outputs be manipulated using the Android Gradle Plugin 3.0.0+?

查看:84
本文介绍了如何使用Android Gradle插件3.0.0+来操纵变量输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于Gradle的最新版本(3.0.0)的Android插件已破坏其用于操作

The latest version (3.0.0) of the Android Plugin for Gradle has broken its API for manipulating Variant Outputs. This API was used for manipulating files creating during builds (such as AndroidManifest.xml), and has been removed to improve configuration times.

哪些新的API可用于处理变量输出,它们与2.X API有何不同?

What new APIs are available to manipulate Variant Outputs, and how do they differ to the 2.X APIs?

推荐答案

outputFiles的更改现已记录在

The changes to outputFiles has now been documented on the Android Developer site.

本质上,建议不要访问直接从gradle API中访问outputFile的建议,而是访问包含该文件的目录.下面的代码段使用清单文件对此进行了演示,但也可以将其应用于其他outputFiles.

Essentially, instead of accessing the outputFile directly from the gradle API, the recommendation is to access the directory containing the file instead. The snippet below demonstrates this with a manifest file, but can be applied to other outputFiles as well.

android.applicationVariants.all { variant ->
    variant.outputs.all { output ->
        output.processManifest.doLast {

            String manifestPath = "$manifestOutputDirectory/AndroidManifest.xml"
            def manifestContent = file(manifestPath).getText()

            // Manipulate the file as needed
        }
    }
}

这篇关于如何使用Android Gradle插件3.0.0+来操纵变量输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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