Skip to content

Commit 2fc8990

Browse files
author
Dimitar Kerezov
committed
Improve Mac setup script Android bits
Changes include: * In case `ANDROID_HOME` environment variable is not set, try to determine the correct path to `android-sdk` - either use homebrew's symlink or through `android` executable's location * Use `android` executable relative to `android-sdk`, set in `ANDROID_HOME` environment variable, for sdk updates * Split android sdk updates into single command calls in order to avoid problems with license agreements
1 parent 0beb324 commit 2fc8990

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

setup/native-script.rb

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,42 @@ def install(program_name, message, script, run_as_root = false, show_all_option
8282
end
8383

8484
install("Java SE Development Kit", "Installing the Java SE Development Kit... This might take some time, please, be patient. (You will be prompted for your password)", 'brew cask install java', false, false)
85-
execute('echo "export JAVA_HOME=$(/usr/libexec/java_home)" >> ~/.profile', "Unable to set JAVA_HOME")
86-
8785
install("Android SDK", "Installing Android SDK", 'brew install android-sdk')
88-
execute('echo "export ANDROID_HOME=/usr/local/opt/android-sdk" >> ~/.profile', "Unable to set ANDROID_HOME")
86+
87+
unless ENV["ANDROID_HOME"]
88+
require 'pathname'
89+
# if android-sdk was installed through brew, there should be a symlink in /usr/local/opt/android-sdk pointing to the actual sdk
90+
android_home = "/usr/local/opt/android-sdk"
91+
unless Pathname.new(android_home).exist?
92+
require 'mkmf'
93+
# if there's no such symlink then try to find the `android-sdk` directory through the `android` executable
94+
android_executable_environment_path = find_executable('android')
95+
if android_executable_environment_path
96+
android_home_joined_path = File.join(android_executable_environment_path, "..", "..")
97+
android_home = Pathname.new(android_home_joined_path).realpath
98+
end
99+
end
100+
101+
ENV["ANDROID_HOME"] = android_home
102+
execute('echo "export ANDROID_HOME=%s" >> ~/.profile' % ENV["ANDROID_HOME"], "Unable to set ANDROID_HOME")
103+
end
104+
105+
unless ENV["JAVA_HOME"]
106+
execute('echo "export JAVA_HOME=$(/usr/libexec/java_home)" >> ~/.profile', "Unable to set JAVA_HOME")
107+
end
89108

90109
# the -p flag is set in order to ensure zero status code even if the directory exists
91110
execute("mkdir -p ~/.cocoapods", "There was a problem in creating ~/.cocoapods directory")
92111
install("CocoaPods", "Installing CocoaPods... This might take some time, please, be patient.", 'gem install cocoapods -V', true)
93112

94113
puts "Configuring your system for Android development... This might take some time, please, be patient."
95-
# Note that multiple license acceptances may be required, hence the multiple y answers
114+
# Note that multiple license acceptances may be required, hence the multiple commands
96115
# the android tool will introduce a --accept-license option in subsequent releases
97-
execute("(for i in {1..5}; do echo y; sleep 4; done) | /usr/local/opt/android-sdk/tools/android update sdk --filter tools,platform-tools,android-23,build-tools-23.0.2,extra-android-m2repository --all --no-ui",
98-
"There seem to be some problems with the Android configuration")
116+
android_executable = File.join(ENV["ANDROID_HOME"], "tools", "android")
117+
execute("echo y | #{android_executable} update sdk --filter tools --all --no-ui", "There seem to be some problems with the Android configuration")
118+
execute("echo y | #{android_executable} update sdk --filter platform-tools --all --no-ui", "There seem to be some problems with the Android configuration")
119+
execute("echo y | #{android_executable} update sdk --filter android-23 --all --no-ui", "There seem to be some problems with the Android configuration")
120+
execute("echo y | #{android_executable} update sdk --filter build-tools-23.0.2 --all --no-ui", "There seem to be some problems with the Android configuration")
121+
execute("echo y | #{android_executable} update sdk --filter extra-android-m2repository --all --no-ui", "There seem to be some problems with the Android configuration")
99122

100123
puts "The ANDROID_HOME and JAVA_HOME environment variables have been added to your .profile. Restart the terminal to use them."

0 commit comments

Comments
 (0)