Using ${applicationId} in library manifest

前端 未结 2 1596
情深已故
情深已故 2021-02-04 00:14

I\'m working on an SDK that uses an internal ContentProvider, I would like to use this SDK in a few projects, and declare it in the library manifest, so I\'ve tried this:

<
2条回答
  •  一个人的身影
    2021-02-04 01:06

    Was running into the same problem with several different variants and unique IDs, and ended up going with replacing a placeholder key when Gradle is building the app, kind of like so:

    Gradle 3+

    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.processManifest.doLast {
                File manifestFile = file("$manifestOutputDirectory/AndroidManifest.xml")
    
                replaceInFile(manifestFile, 'P_AUTHORITY', variant.applicationId)
            }
        }
    }
    
    def replaceInFile(file, fromString, toString) {
        def updatedContent = file.getText('UTF-8')
                .replaceAll(fromString, toString)
    
        file.write(updatedContent, 'UTF-8')
    }
    

    Gradle < 3

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

    And then in the manifest:

    
    

    That's come in handy quite a few times

提交回复
热议问题