How to replace a string for a buildvariant with gradle in android studio?

后端 未结 4 444
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 03:54

I have two flavors of my project:

flavor1 -> packagename: com.example.flavor1 
flavor2 -> packagename: com.example.flavor2

Now I want

4条回答
  •  再見小時候
    2020-12-01 04:16

    In the current Android Gradle DSL, the ApplicationVariant class has changed and Saad's approach has to be rewritten e.g. as follows:

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.processManifest.doLast {
                replaceInManifest(output,
                        'GMAPS_KEY',
                        getGmapsKey(buildType))
    
                }
            }
        }
    
    def replaceInManifest(output, fromString, toString) {
        def updatedContent = output.processManifest.manifestOutputFile.getText('UTF-8')
            .replaceAll(fromString, toString)
        output.processManifest.manifestOutputFile.write(updatedContent, 'UTF-8')
    }
    

    The new DSL also offers a cleaner approach to get directly to the manifest file.

提交回复
热议问题