How to properly set multiple applicationIds or package names in my manifests

丶灬走出姿态 提交于 2019-12-12 15:01:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/28237197/how-to-properly-set-multiple-applicationids-or-package-names-in-my-manifests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!