@@ -181,37 +181,95 @@ def remove_c_libs(self, libs_dir):
181
181
ext = os .path .splitext (lib_file )[1 ]
182
182
if ext == ".a" or ext == ".so" :
183
183
os .remove (lib_file )
184
-
184
+
185
+ def _get_android_sdk_tools_ver (self , sdk_tools_path ):
186
+ cfg_file = os .path .join (sdk_tools_path , 'source.properties' )
187
+
188
+ if os .path .isfile (cfg_file ):
189
+ f = open (cfg_file )
190
+ lines = f .readlines ()
191
+ pattern = r'^Pkg\.Revision=(\d+)\.(\d+)'
192
+ for l in lines :
193
+ match = re .match (pattern , l .strip ())
194
+ if match :
195
+ return ((int )(match .group (1 )), (int )(match .group (2 )))
196
+
197
+ raise cocos .CCPluginError (MultiLanguage .get_string ('COMPILE_ERROR_UNKNOWN_ANDROID_SDK_TOOLS_VERSION' ),
198
+ cocos .CCPluginError .ERROR_PATH_NOT_FOUND )
199
+
200
+ def _update_project_properties (self , folder_path , target_str ):
201
+ props_path = os .path .join (folder_path , 'project.properties' )
202
+ f = open (props_path )
203
+ lines = f .readlines ()
204
+ f .close ()
205
+
206
+ pattern = r'^target=(.*)$'
207
+ matched = False
208
+ new_line = 'target=%s\n ' % target_str
209
+ for i in range (0 , len (lines )):
210
+ l = lines [i ]
211
+ match = re .match (pattern , l .strip ())
212
+ if match :
213
+ lines [i ] = new_line
214
+ matched = True
215
+
216
+ if not matched :
217
+ lines .append ('\n ' )
218
+ lines .append (new_line )
219
+
220
+ f = open (props_path , 'w' )
221
+ f .writelines (lines )
222
+ f .close ()
223
+
224
+ def _write_local_properties (self , folder_path ):
225
+ local_porps_path = os .path .join (folder_path , 'local.properties' )
226
+ lines = [
227
+ 'sdk.dir=%s\n ' % self .sdk_root ,
228
+ 'ndk.dir=%s\n ' % cocos .check_environment_variable ('NDK_ROOT' )
229
+ ]
230
+ f = open (local_porps_path , 'w' )
231
+ f .writelines (lines )
232
+ f .close ()
233
+
185
234
def update_project (self , android_platform ):
186
235
if self .gradle_support_ndk :
187
236
# If gradle supports ndk build, should write local.properties manually
188
- local_porps_path = os .path .join (self .app_android_root , 'local.properties' )
189
- lines = [
190
- 'sdk.dir=%s\n ' % self .sdk_root ,
191
- 'ndk.dir=%s\n ' % cocos .check_environment_variable ('NDK_ROOT' )
192
- ]
193
- f = open (local_porps_path , 'w' )
194
- f .writelines (lines )
195
- f .close ()
237
+ self ._write_local_properties (self .app_android_root )
196
238
return
197
239
240
+ # Android SDK removed android command & ant support from SDK tools 25.3.0
241
+ # So, we should check the Android SDK tools version
242
+ sdk_tools_folder = os .path .join (self .sdk_root , 'tools' )
243
+ main_ver , minor_ver = self ._get_android_sdk_tools_ver (sdk_tools_folder )
244
+ no_ant = False
245
+ if main_ver > 25 or (main_ver == 25 and minor_ver >= 3 ):
246
+ no_ant = True
247
+
248
+ if not self .use_studio and no_ant :
249
+ # Tip the message that ant is not supported from Android SDK tools 25.3.0
250
+ raise cocos .CCPluginError (MultiLanguage .get_string ('COMPILE_ERROR_ANT_NOT_SUPPORTED' ),
251
+ cocos .CCPluginError .ERROR_OTHERS )
252
+
198
253
if self .use_studio :
199
254
manifest_path = os .path .join (self .app_android_root , 'app' )
200
255
else :
201
256
manifest_path = self .app_android_root
202
257
203
- sdk_tool_path = os .path .join (self .sdk_root , "tools" , "android" )
204
-
205
258
# check the android platform
206
259
target_str = self .check_android_platform (self .sdk_root , android_platform , manifest_path )
207
260
208
- # update project
209
- command = "%s update project -t %s -p %s" % (cocos .CMDRunner .convert_path_to_cmd (sdk_tool_path ), target_str , manifest_path )
210
- self ._run_cmd (command )
261
+ if no_ant :
262
+ # should manually update the project
263
+ self ._write_local_properties (manifest_path )
264
+ self ._update_project_properties (manifest_path , target_str )
265
+ else :
266
+ # update project
267
+ sdk_tool_path = os .path .join (sdk_tools_folder , "android" )
268
+ command = "%s update project -t %s -p %s" % (cocos .CMDRunner .convert_path_to_cmd (sdk_tool_path ), target_str , manifest_path )
269
+ self ._run_cmd (command )
211
270
212
- # update lib-projects
213
- property_path = manifest_path
214
- self .update_lib_projects (self .sdk_root , sdk_tool_path , android_platform , property_path )
271
+ # update lib-projects
272
+ self .update_lib_projects (self .sdk_root , sdk_tool_path , android_platform , manifest_path )
215
273
216
274
if self .use_studio :
217
275
# copy the local.properties to the app_android_root
0 commit comments