secrets-gradle-plugin icon indicating copy to clipboard operation
secrets-gradle-plugin copied to clipboard

Plugin ignores custom file found in root directory

Open ClaudeHangui opened this issue 3 years ago • 12 comments

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

ClaudeHangui avatar Oct 18 '21 16:10 ClaudeHangui

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.

arriolac avatar Oct 18 '21 16:10 arriolac

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"

ClaudeHangui avatar Oct 18 '21 17:10 ClaudeHangui

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)

arriolac avatar Oct 18 '21 17:10 arriolac

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

ClaudeHangui avatar Oct 18 '21 17:10 ClaudeHangui

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?

arriolac avatar Oct 18 '21 17:10 arriolac

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 (<cert_fingerprint>;<package_name>): fingerPrint;packageName

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

ClaudeHangui avatar Oct 18 '21 17:10 ClaudeHangui

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)?

arriolac avatar Oct 18 '21 17:10 arriolac

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

ClaudeHangui avatar Oct 18 '21 17:10 ClaudeHangui

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

ClaudeHangui avatar Oct 18 '21 18:10 ClaudeHangui

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?

arriolac avatar Oct 18 '21 19:10 arriolac

I'll try that

ClaudeHangui avatar Oct 19 '21 13:10 ClaudeHangui

Any update on your issue?

arriolac avatar Oct 28 '21 16:10 arriolac