Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android gradle build System.getEnv("RELEASE_PASSWORD") returns null

I'm having an issues where System.getenv() is returning null for the environment variable. My password is stored in the RELEASE_PASSWORD environment variable. When I do:

$ echo $RELEASE_PASSWORD

it prints out the correct value, so I know the variable is set.

I was originally setting the signingConfig signingConfigs.release in the release buildType and everything was working fine, but I need different signing configs for different product flavors. If I hardcode the password, it works just like it is suppose to. Things only get wonky when I try to read the password from an environment variable.

Is it some sort of scope issue?

This is what I currently have in my build.gradle.

android {    ...    signingConfigs {     release {       storeFile ...;       keyAlias ...;       storePassword System.getenv("RELEASE_PASSWORD");       keyPassword System.getenv("RELEASE_PASSWORD");     }      unsigned {       keyAlias "";       storePassword "";       keyPassword "";     }   }    buildTypes {     debug {       versionNameSuffix = "-DEBUG"     }      release {     }   }    flavorGroups "storeFront"    productFlavors {     def googleVariable = signingConfigs.release     def amazonVariable = signingConfigs.unsigned      google {         flavorGroup "storeFront"         signingConfig googleVariable     }      amazon {         flavorGroup "storeFront"         signingConfig amazonVariable     }   } } 
like image 616
HMCFletch Avatar asked May 22 '14 22:05

HMCFletch


People also ask

Why would Getenv return null?

If the varname is not found, getenv() returns a NULL pointer. The returned value is NULL if the given variable is not currently defined.

Can system Getenv return null?

Return Value This method returns the string value of the variable, or null if the variable is not defined in the system environment.


1 Answers

You can run Android Studio from the command-line to get the environment variables passed into the IDE. In Mac OS you can run it from a terminal by running /Applications/Android\ Studio.app/Contents/MacOS/studio

like image 140
Xavi Rigau Avatar answered Sep 16 '22 18:09

Xavi Rigau