@@ -47,6 +47,8 @@ def execute(script, warning_message, run_as_root = false)
47
47
unless result
48
48
STDERR . puts "WARNING: " + warning_message
49
49
end
50
+
51
+ return result
50
52
end
51
53
52
54
def install ( program_name , message , script , run_as_root = false , show_all_option = true )
@@ -73,16 +75,25 @@ def install(program_name, message, script, run_as_root = false, show_all_option
73
75
execute ( script , program_name + " not installed" , run_as_root )
74
76
end
75
77
78
+ def install_environment_variable ( name , value )
79
+ ENV [ name ] = value
80
+
81
+ execute ( "echo \" export #{ name } =#{ value } \" >> ~/.profile" , "Unable to set #{ name } " )
82
+
83
+ if File . exist? ( File . expand_path ( "~/.zshrc" ) )
84
+ execute ( "echo \" export #{ name } =#{ value } \" >> ~/.zprofile" , "Unable to set #{ name } " )
85
+ end
86
+ end
87
+
76
88
# Actually installing all other dependencies
77
89
install ( "Homebrew" , "Installing Homebrew..." , 'ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</dev/null' , false , false )
78
90
79
- if !( `brew --version` . include? "git revision" )
80
- puts "Homebrew is not installed or not configured properly. Download it from http://brew.sh/, install, set it up and run this script again."
91
+ if !( execute ( "brew --version" , "Homebrew is not installed or not configured properly. Download it from http://brew.sh/, install, set it up and run this script again." ) )
81
92
exit
82
93
end
83
94
84
95
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
- install ( "Android SDK" , "Installing Android SDK" , 'brew install android-sdk' )
96
+ install ( "Android SDK" , "Installing Android SDK" , 'brew install android-sdk' , false )
86
97
87
98
unless ENV [ "ANDROID_HOME" ]
88
99
require 'pathname'
@@ -98,18 +109,20 @@ def install(program_name, message, script, run_as_root = false, show_all_option
98
109
end
99
110
end
100
111
101
- ENV [ "ANDROID_HOME" ] = android_home
102
- execute ( 'echo "export ANDROID_HOME=%s" >> ~/.profile' % ENV [ "ANDROID_HOME" ] , "Unable to set ANDROID_HOME" )
112
+ install_environment_variable ( "ANDROID_HOME" , android_home )
103
113
end
104
114
105
115
unless ENV [ "JAVA_HOME" ]
106
- execute ( 'echo "export JAVA_HOME=$( /Library/Java/Home)" >> ~/.profile' , "Unable to set JAVA_HOME ")
116
+ install_environment_variable ( " JAVA_HOME" , " /Library/Java/Home")
107
117
end
108
118
109
119
# the -p flag is set in order to ensure zero status code even if the directory exists
110
120
execute ( "mkdir -p ~/.cocoapods" , "There was a problem in creating ~/.cocoapods directory" )
111
- install ( "xcodeproj" , "Installing xcodeproj... This might take some time, please, be patient." , 'gem install xcodeproj -V' , true )
121
+ # CocoaPods already has a dependency to xcodeproj and also has a dependency to a lower version of activesupport
122
+ # which works with Ruby 2.0 that comes as the macOS default, so these two installations should be in this order.
123
+ # For more information see: https://github.com/CocoaPods/Xcodeproj/pull/393#issuecomment-231055159
112
124
install ( "CocoaPods" , "Installing CocoaPods... This might take some time, please, be patient." , 'gem install cocoapods -V' , true )
125
+ install ( "xcodeproj" , "Installing xcodeproj... This might take some time, please, be patient." , 'gem install xcodeproj -V' , true )
113
126
114
127
puts "Configuring your system for Android development... This might take some time, please, be patient."
115
128
# Note that multiple license acceptances may be required, hence the multiple commands
@@ -129,17 +142,17 @@ def install(program_name, message, script, run_as_root = false, show_all_option
129
142
if gets . chomp . downcase == "y"
130
143
puts "Do you want to install HAXM (Hardware accelerated Android emulator)? (y/n)"
131
144
if gets . chomp . downcase == "y"
132
- execute ( "echo y | $ANDROID_HOME/tools/android update sdk --filter extra-intel-Hardware_Accelerated_Execution_Manager --all --no-ui" , error_msg )
145
+ execute ( "echo y | #{ android_executable } update sdk --filter extra-intel-Hardware_Accelerated_Execution_Manager --all --no-ui" , error_msg )
133
146
134
147
haxm_silent_installer = File . join ( ENV [ "ANDROID_HOME" ] , "extras" , "intel" , "Hardware_Accelerated_Execution_Manager" , "silent_install.sh" )
135
148
execute ( "#{ haxm_silent_installer } " , "There seem to be some problems with the Android configuration" )
136
149
137
- execute ( "echo y | $ANDROID_HOME/tools/android update sdk --filter sys-img-x86-android-23 --all --no-ui" , error_msg )
138
- execute ( "echo no | $ANDROID_HOME/tools/android create avd -n Emulator-Api23-Default -t android-23 --abi default/x86 -c 12M -f" , error_msg )
150
+ execute ( "echo y | #{ android_executable } update sdk --filter sys-img-x86-android-23 --all --no-ui" , error_msg )
151
+ execute ( "echo no | #{ android_executable } create avd -n Emulator-Api23-Default -t android-23 --abi default/x86 -c 12M -f" , error_msg )
139
152
else
140
- execute ( "echo y | $ANDROID_HOME/tools/android update sdk --filter sys-img-armeabi-v7a-android-23 --all --no-ui" , error_msg )
141
- execute ( "echo no | $ANDROID_HOME/tools/android create avd -n Emulator-Api23-Default -t android-23 --abi default/armeabi-v7a -c 12M -f" , error_msg )
153
+ execute ( "echo y | #{ android_executable } update sdk --filter sys-img-armeabi-v7a-android-23 --all --no-ui" , error_msg )
154
+ execute ( "echo no | #{ android_executable } create avd -n Emulator-Api23-Default -t android-23 --abi default/armeabi-v7a -c 12M -f" , error_msg )
142
155
end
143
156
end
144
157
145
- puts "The ANDROID_HOME and JAVA_HOME environment variables have been added to your .profile. Restart the terminal to use them."
158
+ puts "The ANDROID_HOME and JAVA_HOME environment variables have been added to your .profile/.zprofile . Restart the terminal to use them."
0 commit comments