【问题标题】:Application Id based on build type基于构建类型的应用程序 ID
【发布时间】:2019-06-19 14:50:55
【问题描述】:

我需要根据构建类型更改完整的应用程序 ID,而不是在 ID 后添加后缀。我试图在每个构建类型中移动 applicationId,但 Gradle 默认使用最后一个构建类型中的最后一个。 那可能吗?

【问题讨论】:

    标签: android android-gradle-plugin android-build-type


    【解决方案1】:

    要更改您的 applicationId,您需要更改清单和所有目录中的

    1. 转到 Android Studio 的左上角,显示 Android
    2. 单击它并将其更改为 Project Files 从 Android Studio 3.3 开始
    3. 在项目文件旁边单击齿轮并取消选中“压缩目录”
    4. 打开文件夹 -> 点击 app -> src -> main -> java -> your -> package -> name
    5. 现在您看到了各个文件夹,右键单击要更改的部分 -> 重构 -> 重命名

    然后您可以在 AndroidManifest.xml

    中更改您的 applicationId 和包

    希望对你有帮助

    来源: Change Application Id Official Android Documentation

    【讨论】:

      【解决方案2】:

      您可以使用 gradle 过滤器来忽略一些构建/风味目标。
      检查以下代码:

      variantFilter { variant ->
         def flavor = variant.flavors*.name
         def buildType = variant.buildType*.name
      
         // To check for a certain build type, use variant.buildType.name == "<buildType>"
         if ((flavor.contains("xyz") && buildType.contains("debug"))) {
             // Gradle ignores any variants that satisfy the conditions above.
             setIgnore(true)
         }
      }
      

      【讨论】:

        【解决方案3】:

        我使用这种简单的方法,效果很好

        android {
        
            ...
            
            applicationVariants.all { variant ->
                if (variant.name.contains("debug")) {
                    variant.mergedFlavor.applicationId = "application.id.debug"
                } else {
                    variant.mergedFlavor.applicationId = "application.id.release"
                }
            }
        }
        

        【讨论】:

        • Val cannot be reassigned! 给了我错误
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多