androidgradleandroid-gradle-pluginandroid-manifestsecret-key

secrets-gradle-plugin not working with Android manifest


Following https://github.com/google/secrets-gradle-plugin and https://developers.google.com/maps/documentation/android-sdk/secrets-gradle-plugin I'm trying to move my API key to the local.properties file, however, when I try to use the variable in my manifest file I get this error :

"Attribute meta-data#API_KEY@value at AndroidManifest.xml:20:13-44 requires a placeholder substitution but no value for <KEY_VALUE> is provided."

Here are my files:

Project build.gradle:

plugins {
    id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false
}

Module build.gradle:

plugins {
    id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}

local.properties:

KEY_VALUE= MY_API_KEY

And my AndroidManifest.xml:

 <application>
        <meta-data
            android:name="API_KEY"
            android:value="${KEY_VALUE}"/>
</application>

Solution

  • So I was finally able to fix the issue. It seems like there's somewhat of a bug with the plugin. For it to work you have to add it after the android plugin so the ordering of the plugins within the grade file of your app module is actually important.