google / secrets-gradle-plugin

A Gradle plugin for providing your secrets to your Android project.
Apache License 2.0
1.14k stars 99 forks source link

How I can get the value inside an xml file ? #17

Closed Abdelsattar closed 3 years ago

Abdelsattar commented 3 years ago

I'm trying with google maps API key as following

in AndroidManifest.xml <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" />

and in google_maps_api.xml

`

"${*.*.*BuildConfig.GoogleMapsAPIKey}"

`

I tried to like this and as well like ${GoogleMapsAPIKey} and GoogleMapsAPIKey but always have the same error Ensure that the following Android Key exists: API Key: ${*.*.*.BuildConfig.GoogleMapsAPIKey} and it works fine if I put it in the value in AndroidManifest how to solve this?

arriolac commented 3 years ago

This plugin only exposes your keys through the AndroidManifest and through your BuildConfig so you won't be able to use the plugin in this way. One of the intentions of this plugin is to avoid putting your API key in string resources since those are readable by other apps via PackageManager. Curious why you choose this approach?

AliYusuf95 commented 3 years ago

@arriolac I think it'll be more convenient if the values added to the resources using resValue, so the values can be used inside XML files easily.

My case is I want to use Admob units ids inside layouts.

arriolac commented 3 years ago

It is a deliberate design decision to not inject keys to string resources as those values are accessible by any app. See PackageManager.getResourcesForApplication(String).