Fix build error with scons-4.4.0 version which is based on python3
[platform/upstream/iotivity.git] / extlibs / android / sdk / SConscript
1 ##
2 # Script to install (if they do not exist) the Android SDK library (ie. Android JDK)
3 ##
4
5 import os, subprocess, struct
6 import urllib.request, urllib.error, urllib.parse, urllib.parse
7 import SCons.Errors
8 import shutil
9
10 Import('env')
11
12 target_os = env.get('TARGET_OS')
13 src_dir = env.get('SRC_DIR')
14
15 SConscript(src_dir + '/build_common/tools/UnpackAll.py')
16 SConscript(src_dir + '/build_common/external_libs.scons')
17
18 # Download
19 if target_os == 'android':
20         android_home = env.get('ANDROID_HOME')
21         if not android_home:
22                 print('Creating ANDROID_HOME for Android SDK')
23
24                 # older IoTivity versions expected the SDK at this position, this is left for backwards compatibility
25                 androidlib_dir      = src_dir + '/extlibs/android/sdk/android-sdk_r24.2'
26
27                 if not os.path.exists(androidlib_dir):
28                         from sys import platform as _platform
29                         if _platform == "linux" or _platform == "linux2":
30                                 androidlib_zip_file = src_dir + '/extlibs/android/android-sdk_r24.2-linux.tgz'
31                                 androidlib_url      = 'http://dl.google.com/android/android-sdk_r24.2-linux.tgz'
32                                 androidlib_dir      = src_dir + '/extlibs/android/sdk/android-sdk-linux'
33                         elif _platform == "darwin":
34                                 androidlib_zip_file = src_dir + '/extlibs/android/android-sdk_r24.2-macosx.zip'
35                                 androidlib_url      = 'http://dl.google.com/android/android-sdk_r24.2-macosx.zip'
36                                 androidlib_dir      = src_dir + '/extlibs/android/sdk/android-sdk-macosx'
37                         elif _platform == "win32":
38                                 androidlib_zip_file = src_dir + '/extlibs/android/android-sdk_r24.2-windows.zip'
39                                 androidlib_url      = 'http://dl.google.com/android/android-sdk_r24.2-windows.zip'
40                                 androidlib_dir      = src_dir + '/extlibs/android/sdk/android-sdk-windows'
41
42                 if not os.path.exists(androidlib_dir):
43                         # If the zip file is not already present, download it
44                         if not os.path.exists(androidlib_zip_file):
45                                 androidlib_zip = env.Download(androidlib_zip_file, androidlib_url)
46                         else:
47                                 androidlib_zip = androidlib_zip_file
48
49                         # Unzip the lib
50                         print('Unzipping android lib...')
51                         env.UnpackAll(androidlib_dir, androidlib_zip)
52                         print('Unzipping android lib complete')
53
54                         # Remove downloaded file
55 #                       os.remove(androidlib_zip_file)
56         else:
57                 androidlib_dir = env.get('ANDROID_HOME')
58
59 # Set the ANDROID_HOME
60 env.Replace(ANDROID_HOME = androidlib_dir)
61 print('ANDROID_HOME = ' + env.get('ANDROID_HOME'))
62
63