Created
November 13, 2016 13:34
-
-
Save emartynov/7391946ca89794909aa7e9105c164152 to your computer and use it in GitHub Desktop.
Define ANDROID_HOME if doesn't exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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