1

I have an Android app that uses Google Maps SDK. I have my API key stored in my ~/.gradle/gradle.properties file, as follows:

GOOGLE_MAPS_DEV_API_KEY=<MY_API_KEY>

I'm trying to add this to the build process in gradle, but I keep getting null.

I'm trying to compile from the command line. When I compile with Android Studio, it works fine and can find the API key. When I use the command line, gradle can't find the property.

The following all work within Android Studio:

    println(project.findProperty("GOOGLE_MAPS_DEV_API_KEY"))
    println(project.getProperties().GOOGLE_MAPS_DEV_API_KEY)
    println(project.GOOGLE_MAPS_DEV_API_KEY)

However, on command line, I get the following:

null
null

and for the 3rd one:

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not get unknown property 'GOOGLE_MAPS_DEV_API_KEY' for project ':app' of type org.gradle.api.Project.

So it must be an environment issue. I'm using Ubuntu. My gradle user home is ~/.gradle but my gradle home is on my scratch drive. See this from my .bashrc:

export DOTNET_ROOT=/snap/dotnet-sdk/current
export ANDROID_HVPROTO=ddm
export ANDROID_BASE_DIR="$HOME/Android"
export ANDROID_HOME="$ANDROID_BASE_DIR/Sdk"
export ANDROID_USER_HOME="$HOME/.android"
export GRADLE_HOME="/media/eoinzy/SCRATCH/Android/.gradle"
export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$GRADLE_HOME:$PATH"

I don't know what Android Studio is doing differently to pick up these properties, but it must be some configuration I'm missing. The app compiles from the command line and everything else works except the Map, so the Android Home, and JAVA_HOME is configured correctly. It just won't read from the global gradle.properties.

Thanks

eoinzy
  • 2,152
  • 4
  • 36
  • 67
  • Does this help you in any way? https://stackoverflow.com/questions/39444581/where-is-gradle-properties-file-located-in-gradle-project – Lawrence Gimenez May 24 '23 at 12:48
  • @LawrenceGimenez Kinda. I just realised the gradle.properties is in `GRADLE_HOME` and not `GRADLE_USER_HOME`. Silly me. – eoinzy May 24 '23 at 13:52
  • But I still can't read it. Maybe gradle command line struggles when GRADLE_HOME is on another hard drive. Android Studio works fine, howecer... – eoinzy May 24 '23 at 17:02
  • Yeah, I would start looking at your directory paths. – Lawrence Gimenez May 25 '23 at 00:47

0 Answers0