Skip to content

Instantly share code, notes, and snippets.

@emartynov
Created November 13, 2016 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emartynov/7391946ca89794909aa7e9105c164152 to your computer and use it in GitHub Desktop.
Save emartynov/7391946ca89794909aa7e9105c164152 to your computer and use it in GitHub Desktop.
Define ANDROID_HOME if doesn't exist
afterEvaluate {
def sdkPath = prepareAndroidHome()
}
private String prepareAndroidHome()
{
def localProperties = new File( project.rootDir, 'local.properties' )
def properties = new Properties()
if ( localProperties.exists() )
{
localProperties.withInputStream { properties.load it }
}
def sdkDirProperty = 'sdk.dir'
def sdkDirPath = properties.getProperty sdkDirProperty
if ( sdkDirPath == null )
{
sdkDirPath = System.getenv( 'ANDROID_HOME' )
}
if ( sdkDirPath == null )
{
def androidSdkPath = "${System.getProperty( 'user.home' )}/.android"
if ( localProperties.exists() )
{
localProperties.withWriterAppend( 'UTF-8' ) {
it.write "$sdkDirProperty=$androidSdkPath\n" as String
}
}
else
{
localProperties.withWriter( 'UTF-8' ) {
it.write "# DO NOT check this file into source control.\n"
it.write "$sdkDirProperty=$androidSdkPath\n" as String
}
}
sdkDirPath = androidSdkPath
}
return sdkDirPath
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment