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