如何在我的清单中正确设置多个applicationIds或包名称 [英] How to properly set multiple applicationIds or package names in my manifests

查看:204
本文介绍了如何在我的清单中正确设置多个applicationIds或包名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与此问题直接相关的问题:,但将其引入另一个问题是有道理的。我在build.gradle中有这个:

  flavorGroups'fruit','paid'

productFlavors {
apple {
flavorGroup'fruit'
}
orange {
flavorGroup'fruit'
}
free {
flavorGroup '支付'
}
溢价{
flavorGroup'支付'
}
}

我现在有四个独特的应用程序。


  1. Apple Free

  2. Apple Paid
  3. Orange Free

  4. Orange付款

但是它们还没有独特的包名/应用程序ID。



在这种情况下,我如何设置四个独特的应用程序ID /包名?




我试过了什么?



在上一个问题中,@Scott Barta建议仅为清单中的每个应用程序设置包名。



当我尝试创建四个额外的清单时(注意:我在/ main中有单一的核心清单)出现错误:清单合并失败:AndroidManifest.xml清单中的主AndroidManifest.xml:package属性未被声明。看起来好像我从它不想构建的核心清单文件(在/ main中)中删除了软件包名称。

解决方案

定制 applicationId 的最简单方法是使用 Gradle的 applicationIdSuffix 属性。示例如下:

  defaultConfig {
applicationId'com.example'
}

flavorGroups'fruit','paid'

productFlavors {
apple {
flavorGroup'fruit'
applicationIdSuffix'.apple'
}
orange {
flavorGroup'fruit'
applicationIdSuffix'.orange'
}
free {
flavorGroup'paid'
applicationIdSuffix'.free'

溢价{
flavorGroup'paid'
applicationIdSuffix'.premium'
}
}

Gradle内置了全功能的编程语言Groovy,因此您可以做更多精心制作的巫毒比这个,但这是最简单的方法。


I have an issue that is directly related to this question: How to have two build flavors inherit from a root flavor in Android Studio? but it makes sense to pull it out into another question. I have this in my build.gradle:

flavorGroups 'fruit', 'paid'

productFlavors {
    apple {
        flavorGroup 'fruit'
    }
    orange {
        flavorGroup 'fruit'
    }
    free {
        flavorGroup 'paid'
    }
    premium {
        flavorGroup 'paid'
    }
}

I have four unique applications at this point.

  1. Apple Free
  2. Apple Paid
  3. Orange Free
  4. Orange Paid

But they do not have unique package names/application ids just yet.

How do I set up four unique app ids/package names in this situation?


What I've tried?

In the previous question @Scott Barta suggested just to set the package names in the manifest for each of the four application.

When I tried creating four additional manifests (Note: I had my single "core" manifest before in /main) I got an error: Manifest merger failed : Main AndroidManifest.xml at AndroidManifest.xml manifest:package attribute is not declared. It seems as though I removed the package name from the core manifest file (in /main) it doesn't want to build.

解决方案

The simplest way to customize the applicationId is to use Gradle's applicationIdSuffix property. Example below:

defaultConfig {
    applicationId 'com.example'
}

flavorGroups 'fruit', 'paid'

productFlavors {
    apple {
        flavorGroup 'fruit'
        applicationIdSuffix '.apple'
    }
    orange {
        flavorGroup 'fruit'
        applicationIdSuffix '.orange'
    }
    free {
        flavorGroup 'paid'
        applicationIdSuffix '.free'
    }
    premium {
        flavorGroup 'paid'
        applicationIdSuffix '.premium'
    }
}

Gradle has a full-featured programming language, Groovy, built in, so you can do more elaborate voodoo than this, but this is the easiest way.

这篇关于如何在我的清单中正确设置多个applicationIds或包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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