简体   繁体   English

如何在Android Gradle中消除默认的构建变体

[英]How to eliminate default build variants in android gradle

We have already different build variants in our project (dev,qa and others), making the default variants irrelevant and confusing. 我们的项目中已经有不同的构建变体(dev,qa和其他),这使得默认变体无关紧要且令人困惑。

Is there a way to completely remove the default build variants, namely debug and release ? 有没有办法完全删除默认的构建版本,即debugrelease They're already generating compiler errors that won't be fixed since they won't be supported anymore. 他们已经在生成编译器错误,由于不再受支持,因此无法修复。 I'd like them to be completely removed from existence. 我希望将它们从存在中彻底移除。

If that's not possible I'd like to make most tasks that depend on them to be obsolete as if they never existed, like assembleDebug , compileDebugSources , installDebug , testDebugUnitTest etc. 如果不可能的话,我想使大多数依赖于它们的任务过时,就好像它们永远不存在一样,例如assembleDebugcompileDebugSourcesinstallDebugtestDebugUnitTest等。

It's ok to override a couple of tasks and generate nice error messages, but I'm afraid I'd end up overriding lots of tasks. 可以覆盖几个任务并生成漂亮的错误消息是可以的,但是我恐怕最终会覆盖很多任务。

Putting these on build.gradle will make most if not all references to debug variant tasks to disapear. 将它们放在build.gradle上会使大多数(即使不是全部)调试变量任务引用消失。

android.variantFilter { variant ->
    if(variant.buildType.name.equals('debug') ) {
        variant.setIgnore(true);
    }
}

It's interesting to note though that if you have another variant based on debug it will still work. 有趣的是,如果您有另一个基于debug的变体,它将仍然有效。 For example you can still run QA variant if you have it defined this way: 例如,如果您通过以下方式定义了质量检查变体,则仍然可以运行它:

buildTypes {
    qa {
        initWith debug
        . . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过gradle构建不同的android变种 - how to build different variants of android through gradle 如何在 gradle kts 中排除(忽略)android 构建变体 - How to exclude (ignore) android build variants in gradle kts 在Android Studio中使用Gradle构建变体 - Build Variants using Gradle in Android Studio 在Gradle中为Android中的库项目构建变体 - Build variants in Gradle for a Library Project in Android Android studio gradle flavors 未显示在 Build Variants 中 - Android studio gradle flavors not showing in Build Variants 如何在gradle任务中构建两个变体 - How to build two variants in a gradle task 在Android Studio / gradle中进行免费/专业版构建变体时,如何处理免费版本中的库导入? - When doing free/pro build variants in Android Studio/gradle, how to handle import for library in free version? 在Android Gradle项目中,有没有办法在嵌套依赖项中传递构建变体配置? - In Android Gradle projects, is there a way to pass build variants configuration in nested dependencies? Android Studio gradle 风格未正确显示构建变体 - Android Studio gradle flavors not showing Build Variants correctly android studio中带有gradle的风味构建变体的最佳实践 - best practice for flavored build variants with gradle in android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM