google / secrets-gradle-plugin

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

Plugin ignores custom file found in root directory #44

Open ClaudeHangui opened 2 years ago

ClaudeHangui commented 2 years ago

I created a custom file named service.properties at the root of my project and I stored my google api key in it as such: key_name="value" In my module's build.gradle file I have this configuration: secrets { propertiesFileName 'service.properties' } When I run the project I get the error message saying telling me to check if the api key exist. It does already exists as I originally set my key in the strings.xml file and I read directly from there, before attempting this plugin I am using v1.3.0 of the plugin

arriolac commented 2 years ago

Hi @ClaudeHangui, can you try with the latest version of this library (2.0.0)? Also, just to confirm, are you able to get the plugin to work when it reads from local.properties and not from a custom file? If there are any other error/warning log statements you can share that would be helpful.

ClaudeHangui commented 2 years ago

Yes I am able to have it working from the local.properties file. We didn't want to upgrade to v2.0.0 as that requires us to move our AGP to v7.x.x The error logs that we have are as usual i.e when the api key is nor configured or can't be accessed on the project: Ensure that the "Google Maps Android API v2" is enabled. Ensure that the following Android Key exists: API Key: "my key"

arriolac commented 2 years ago

Are you getting a compilation error? Or is the error related to the map not showing (i.e. the plugin is able to fetch the key, but the key does not have the correct APIs enabled)? Based on the message you pasted, it seems that it might be the latter (see Enabling APIs)

ClaudeHangui commented 2 years ago

The plugin isn't able to fetch the key. Like I said, I initially set up my key in the strings.xml file, read it in the AndroidManifest.xml and I had no issue in displaying my location on the map. I tried the plugin with a custom configuration/ file and I have the error above

arriolac commented 2 years ago

The error message that you shared in https://github.com/google/secrets-gradle-plugin/issues/44#issuecomment-945976394 does not match the error you are describing of the plugin not being able to fetch the key.

You should see something like this error for BuildConfig.GOOGLE_MAPS_KEY references:

Application.kt: (32, 45): Unresolved reference: GOOGLE_MAPS_KEY

Or, the following error if the plugin is not able to fetch your key in the AndroidManifest.xml file:

Attribute meta-data#com.google.android.geo.API_KEY@value at AndroidManifest.xml:32:13-44 requires a placeholder substitution but no value for <GOOGLE_MAPS_KEY> is provided.

Can you share more information from your logs?

ClaudeHangui commented 2 years ago

Here :

Google Maps Android API: Authorization failure. Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map. Google Maps Android API: In the Google Developer Console (https://console.developers.google.com) Ensure that the "Google Maps Android API v2" is enabled. Ensure that the following Android Key exists: API Key: "my api key" Android Application (;): fingerPrint;packageName

Again setting up my key in local.properties or strings..xml works absoluetely fine

arriolac commented 2 years ago

Yep, that error message indicates that API key restrictions are incorrectly applied and does not have anything to do with the plugin's functionality. Is it possible that you have 2 separate keys that might be interfering with each other (or different build variants with separate package names)?

ClaudeHangui commented 2 years ago

As a matter of fact we do have multiple build variants. But right now I am in debug mode

ClaudeHangui commented 2 years ago

@arriolac Any ideas on how I should go about in this case ?

arriolac commented 2 years ago

If you can share a demo project that reproduces this issue for me to look into further that would be helpful.

Another thing you can test to verify that this issue is for sure with the plugin and not with a restricted API key, can you create a new unrestricted Google Maps API key and use that instead?

ClaudeHangui commented 2 years ago

I'll try that

arriolac commented 2 years ago

Any update on your issue?