20

I'm trying to perform substitution within the AndroidManifest.xml file from the build.gradle android extension but am getting this error:

AndroidManifest.xml:89:16 Error:
    Attribute uses-library#com.company.platform.${encoding}@name at AndroidManifest.xml:89:16 requires a placeholder substitution but no value for <encoding> is provided.
/Users/Company/Desktop/Checkout/android/Project/app/src/main/AndroidManifest.xml:0:0 Error:
    Validation failed, exiting
:app:processDebugManifest FAILED

This is a snippet of the manifest file:

...
     </receiver>
   <uses-library android:name="com.company.platform.${encoding}" />
</application>
...

And this is a snipped of the build.gradle:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId "com.company.app"
        minSdkVersion 23
        targetSdkVersion 23
        versionName cityVersion
        setProperty("archivesBaseName", "City_$versionName")
        manifestPlaceholders = [encoding: "some value"]
        manifestPlaceholders = [version: cityVersion]
    }

I've also tried adding the manifestPlaceholders in the buildTypes i.e.

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        manifestPlaceholders = [encoding: deviceEncoding]
        manifestPlaceholders = [version: cityIDVersion]
   }
    debug {
        manifestPlaceholders = [encoding: deviceEncoding]
        manifestPlaceholders = [version: cityIDVersion]
    }

}

But I still get the same error.

Why is there an error about it requiring a placeholder substitution when one is provided for in the manifestPlaceholders?

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378

7 Answers7

50

You need to just add to the array. You are replacing it. Do this:

manifestPlaceholders = [encoding: "some value", version: cityVersion]

By declaring manifestPlaceholders twice for the same flavor/build type, your are replacing the previous one. After the previous one got replaced, your build failed because the property no longer exists.

jesobremonte
  • 3,198
  • 2
  • 22
  • 30
  • 1
    Thank you so much! – Thomas Mohr Sep 04 '17 at 12:52
  • @jesobremonte: sir which section we have put above line? – Kapil Soni May 23 '19 at 11:18
  • Either in defaultConfig {..} or in the individual productFlavors { flavorName{ .. } } depending on your needs. – jesobremonte May 23 '19 at 11:25
  • @jesobremonte: what value we have to put sir inside the encoding and version variable sir please tell me ? – Kapil Soni May 24 '19 at 08:31
  • 1
    It really depends on whatever values you need in your build, I can't answer that. The above is just an example, you need to apply what you need to set instead. See this documentation on how to use it: https://developer.android.com/studio/build/manifest-build-variables – jesobremonte May 24 '19 at 09:04
  • @jesobremonte ok sir i tried but not worked for me, tell me 1 thing sir its related to the cordova-plugin-goolemaps plugin issue or any another issue? – Kapil Soni May 25 '19 at 06:10
4

this

 manifestPlaceholders = [encoding: "some value"]
 manifestPlaceholders = [version: cityVersion]

should be like this

 manifestPlaceholders = [encoding: "some value"]
 manifestPlaceholders += [version: cityVersion]
2

For those of you running into manifest merger / manifest injection issues due to manifestPlaceholders defined in your libraries manifest, the issue is coming from the fact that you need to define a value for the manifestPlaceholders in your libraries manifest. That value is not getting overridden when you inject your real value in the consuming application. To get around this, you should only define those manifestPlaceholders values for debug builds in your library.

Like so:

android.buildTypes.debug.manifestPlaceholders = [
    authScheme: 'clientAppReplaces', authHost: 'clientAppReplaces'
]

By doing this you will be able to build your library. While also letting the client application supply the correct values for the manifestPlaceholders. Allowing your library to do all that heavy lifting it should. This is possible because libraries build as release builds (unless defined otherwise).

Client app build.gradle example:

defaultConfig {
    applicationId "com.app.manifestPlaceholders"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode project.ext.versionCode
    versionName project.ext.versionName

    manifestPlaceholders = [authScheme: 'customSchemeValue', authHost: 'hostValue']
}
Sakiboy
  • 7,252
  • 7
  • 52
  • 69
  • man I am hoping this worked, `android` decided to go to its next error. – Daniel Jul 01 '19 at 02:23
  • I tried it and I think it worked, not sure why you were downvoted either. I got a lot more issues to resolve though. – Daniel Jul 01 '19 at 03:49
0

I had left the ${} symbols around my value:

<meta-data android:name="net.example" android:value="${XXXX}" />
Alberto M
  • 1,608
  • 1
  • 18
  • 42
0

Notice the += operation is applied on manifestPlaceholders instead of =. This is intentional and required as newer versions of the Flutter SDK has made some changes underneath the hood to deal with multidex. Using = instead of += can lead to errors like the following:

Attribute application@name at AndroidManifest.xml:5:9-42 requires a placeholder substitution but no value for <applicationName> is provided.

If you see this error then update your build.gradle to use += instead.

M Karimi
  • 1,991
  • 1
  • 17
  • 34
0

If your application uses Google maps

Before you run your application, you need a Google Maps API key.

         To get one, follow the directions here:

            https://developers.google.com/maps/documentation/android-sdk/get-api-key

         Once you have your API key (it starts with "AIza"), define a new property in your
         project's local.properties file (e.g. MAPS_API_KEY=Aiza...), and replace the
         "YOUR_API_KEY" string in this file with "${MAPS_API_KEY}".
    -->
  
Priyanthi
  • 1,715
  • 2
  • 10
  • 7
-1

You need to add the applicationId placeholder to the application gradle. This happens with the integration of Firebase, after updating to Gradle 2.2.0-alpha1

android {
    ...
    defaultConfig {
        applicationId "com.example.my.app"
        ...
    }
}

See: Unable to get provider com.google.firebase.provider.FirebaseInitProvider

Community
  • 1
  • 1
Wessel du Plooy
  • 505
  • 5
  • 18
  • Ah, indeed, sorry... I have stared myself blind at this problem. I did not have it, which solved the error message, but I am still not getting any APK out of Android Studio... only, now also no errors/warnings – Wessel du Plooy May 23 '16 at 16:25