diff --git a/tools/android/set_up_android.py b/tools/android/set_up_android.py new file mode 100644 index 0000000000..a014b07ce9 --- /dev/null +++ b/tools/android/set_up_android.py @@ -0,0 +1,100 @@ +#!/usr/bin/python + +import os +import shutil + +def locate_sdk(): + sdkPath = raw_input('Enter Android SKD path: ').strip() + # check if directory is correct + androidPath = os.path.join(sdkPath, 'tools', 'android') + if os.path.exists(androidPath): + print 'ANDROID SDK path assigned: %s' % sdkPath + return sdkPath + else: + print 'Incorrect SDK path.' + exit(1) +### !locate_sdk + + +def locate_ndk(): + ndkPath = raw_input('Enter Anroid NDK path: ').strip() + # check if directory is correct + ndkBuildPath = os.path.join(ndkPath, 'ndk-build') + if os.path.exists(ndkBuildPath): + print 'ANDROID NDK path assigned: %s' % ndkPath + return ndkPath + else: + print 'Incorrect NDK path.' + exit(1) +### !locate_ndk + + +def update_assets(): + return os.system('./update_assets.sh') +### !update_assets + + +def replace_aapt(sdkDir, oldAaptName='aapt_backup'): + + aaptPath = os.path.join(sdkDir, 'platform-tools', 'aapt') + aaptOldPath = os.path.join(sdkDir, 'platform-tools', oldAaptName) + + # handle case of non-existing file + if os.path.exists(aaptPath): + os.rename(aaptPath, aaptOldPath) + else: + print 'aapt not found, skipping' + + # copy new hacked aapt version + curDir = os.getcwd() + hackedAaptPath = os.path.join(curDir, 'aapt') + print 'hacked path; %s' % hackedAaptPath + print 'copied: %s' % shutil.copy(hackedAaptPath, aaptPath) +### !replace_aapt + + +def write_local_properties(sdkDir, ndkDir): + + locPropsContent = ('# Autogenerated file\n' + + '# Do not add it to version control\n' + + 'sdk.dir=%s\n' % sdkDir + + 'ndk.dir=%s\n' % ndkDir) + + curDir = os.getcwd() + omimRoot = os.path.dirname(os.path.dirname(curDir)) + androidRoot = os.path.join(omimRoot, 'android') + locPropsOrigin = os.path.join(androidRoot, 'local.properties') + + file = open(locPropsOrigin, 'w') + file.write(locPropsContent) + file.close() + + # copy files to subfolders + subfolders = ['MapsWithMeLite', 'MapsWithMeLite.Samsung', 'MapsWithMePro'] + for folder in subfolders: + dst = os.path.join(androidRoot, folder, 'local.properties') + shutil.copy(locPropsOrigin, dst) + print dst +### !write_local_properties + + +def run(): + sdkDir = locate_sdk() + ndkDir = locate_ndk() + print '>>> Replacing aapt' + replace_aapt(sdkDir) + print '>>> Updating assets' + update_assets() + print '>>> Writing local.properties' + write_local_properties(sdkDir, ndkDir) + print '>>> Done!' +### !run + + +# RUN it!!! +run() + + + + +