Using a different manifestPlaceholder for each Build Variant

前端 未结 6 534
长发绾君心
长发绾君心 2020-12-09 03:01

I will start by saying that I am very new to Gradle, so I apologize if this has already been answered.

I\'m working on an Android application that uses an API key to

6条回答
  •  误落风尘
    2020-12-09 03:27

    I believe that you need a manifestPlaceHolder to read that value in your Java code, right? If this is the case, you can already read the FLAVOR name in your generated BuildConfig.java. For example, if you define a flavor whose name is smartphone you can access that value using BuildConfig.FLAVOR String; then in your code you can use a simple if (BuildConfig.FLAVOR.equals("smartphone"))...

    But maybe you need to read a sort of configuration of your app, an apiKey. In that case, the best way to go is to create a Class or a string resource for every flavor; this is the link for you.

提交回复
热议问题