def Execution(options, app_info): # Now we've got correct app_version and correct ABI value, # start to generate suitable versionCode app_info.app_versionCode = MakeVersionCode(options, app_info.app_version) # Write generated versionCode into AndroidManifest.xml. # Later if we have other customization, # we can put them together into CustomizeManifest func. CustomizeManifest(app_info) name = app_info.android_name arch_string = (' (' + options.arch + ')' if options.arch else '') print('\nStarting application build' + arch_string) app_dir = GetBuildDir(name) android_path = Which('android') api_level = GetAndroidApiLevel(android_path) target_string = 'android-%d' % api_level print(' * Checking keystore for signing') if options.keystore_path: key_store = os.path.expanduser(options.keystore_path) if options.keystore_alias: key_alias = options.keystore_alias else: print('Please provide an alias name of the developer key.') sys.exit(6) if options.keystore_passcode: key_code = options.keystore_passcode else: key_code = None if options.keystore_alias_passcode: key_alias_code = options.keystore_alias_passcode else: key_alias_code = None else: print(' No keystore provided for signing. Using xwalk\'s keystore ' 'for debugging.\n Please use a valid keystore when ' 'distributing to the app market.') key_store = os.path.join(xwalk_dir, 'xwalk-debug.keystore') key_alias = 'xwalkdebugkey' key_code = 'xwalkdebug' key_alias_code = 'xwalkdebug' # Update android project for app and xwalk_core_library. update_project_cmd = [ android_path, 'update', 'project', '--path', app_dir, '--target', target_string, '--name', name ] if options.mode == 'embedded': print(' * Updating project with xwalk_core_library') RunCommand([ android_path, 'update', 'lib-project', '--path', os.path.join(app_dir, EMBEDDED_LIBRARY), '--target', target_string ]) update_project_cmd.extend(['-l', EMBEDDED_LIBRARY]) elif options.mode == 'shared': print(' * Updating project with xwalk_shared_library') RunCommand([ android_path, 'update', 'lib-project', '--path', os.path.join(app_dir, SHARED_LIBRARY), '--target', target_string ]) update_project_cmd.extend(['-l', SHARED_LIBRARY]) else: print(' * Updating project') RunCommand(update_project_cmd) # Check whether external extensions are included. print(' * Checking for external extensions') extensions_string = 'xwalk-extensions' extensions_dir = os.path.join(app_dir, extensions_string) external_extension_jars = FindExtensionJars(extensions_dir) for external_extension_jar in external_extension_jars: shutil.copyfile( external_extension_jar, os.path.join(app_dir, 'libs', os.path.basename(external_extension_jar))) if options.mode == 'embedded': print(' * Copying native libraries for %s' % options.arch) # Remove existing native libraries in xwalk_core_library, they are probably # for the last execution to make apk for another CPU arch. # And then copy the native libraries for the specified arch into # xwalk_core_library. arch = ConvertArchNameToArchFolder(options.arch) if not arch: print('Invalid CPU arch: %s.' % arch) sys.exit(10) library_lib_path = os.path.join(app_dir, EMBEDDED_LIBRARY, 'libs') for dir_name in os.listdir(library_lib_path): lib_dir = os.path.join(library_lib_path, dir_name) if ContainsNativeLibrary(lib_dir): shutil.rmtree(lib_dir) native_lib_path = os.path.join(app_dir, 'native_libs', arch) if ContainsNativeLibrary(native_lib_path): shutil.copytree(native_lib_path, os.path.join(library_lib_path, arch)) else: print( 'No %s native library has been found for creating a Crosswalk ' 'embedded APK.' % arch) sys.exit(10) if options.project_only: print(' (Skipping apk package creation)') return # Build the APK if options.mode == 'embedded': print(' * Building Android apk package with Crosswalk embedded' + arch_string) else: print(' * Building Android apk package') ant_path = Which('ant') ant_cmd = [ant_path, 'release', '-f', os.path.join(app_dir, 'build.xml')] ant_cmd.extend(['-Dkey.store=%s' % os.path.abspath(key_store)]) ant_cmd.extend(['-Dkey.alias=%s' % key_alias]) if key_code: ant_cmd.extend(['-Dkey.store.password=%s' % key_code]) if key_alias_code: ant_cmd.extend(['-Dkey.alias.password=%s' % key_alias_code]) cmd_display = ' '.join([str(item) for item in ant_cmd]) if options.verbose: print('Executing:\n %s\n' % cmd_display) else: ant_cmd.extend(['-quiet']) ant_result = subprocess.call(ant_cmd) if ant_result != 0: print('Command "%s" exited with non-zero exit code %d' % (cmd_display, ant_result)) sys.exit(ant_result) src_file = os.path.join(app_dir, 'bin', '%s-release.apk' % name) package_name = name if options.app_version: package_name += ('_' + options.app_version) if options.mode == 'shared': dst_file = os.path.join(options.target_dir, '%s.apk' % package_name) elif options.mode == 'embedded': dst_file = os.path.join(options.target_dir, '%s_%s.apk' % (package_name, options.arch)) shutil.copyfile(src_file, dst_file) print(' (Location: %s)' % dst_file)
def Execution(options, app_info): # Now we've got correct app_version and correct ABI value, # start to generate suitable versionCode app_info.app_versionCode = MakeVersionCode(options, app_info.app_version) # Write generated versionCode into AndroidManifest.xml. # Later if we have other customization, # we can put them together into CustomizeManifest func. CustomizeManifest(app_info) name = app_info.android_name arch_string = (' ('+options.arch+')' if options.arch else '') print('\nStarting application build' + arch_string) app_dir = GetBuildDir(name) android_path = Which('android') api_level = GetAndroidApiLevel(android_path) target_string = 'android-%d' % api_level print (' * Checking keystore for signing') if options.keystore_path: key_store = os.path.expanduser(options.keystore_path) if options.keystore_alias: key_alias = options.keystore_alias else: print('Please provide an alias name of the developer key.') sys.exit(6) if options.keystore_passcode: key_code = options.keystore_passcode else: key_code = None if options.keystore_alias_passcode: key_alias_code = options.keystore_alias_passcode else: key_alias_code = None else: print(' No keystore provided for signing. Using xwalk\'s keystore ' 'for debugging.\n Please use a valid keystore when ' 'distributing to the app market.') key_store = os.path.join(xwalk_dir, 'xwalk-debug.keystore') key_alias = 'xwalkdebugkey' key_code = 'xwalkdebug' key_alias_code = 'xwalkdebug' # Update android project for app and xwalk_core_library. update_project_cmd = [android_path, 'update', 'project', '--path', app_dir, '--target', target_string, '--name', name] if options.mode == 'embedded': print(' * Updating project with xwalk_core_library') RunCommand([android_path, 'update', 'lib-project', '--path', os.path.join(app_dir, EMBEDDED_LIBRARY), '--target', target_string]) update_project_cmd.extend(['-l', EMBEDDED_LIBRARY]) elif options.mode == 'shared': print(' * Updating project with xwalk_shared_library') RunCommand([android_path, 'update', 'lib-project', '--path', os.path.join(app_dir, SHARED_LIBRARY), '--target', target_string]) update_project_cmd.extend(['-l', SHARED_LIBRARY]) else: print(' * Updating project') RunCommand(update_project_cmd) # Enable proguard if options.mode == 'embedded' and options.enable_proguard: print(' * Enabling proguard config files') # Enable proguard in project.properies. if not os.path.exists(os.path.join(app_dir, 'project.properties')): print('Error, project.properties file not found!') sys.exit(14) file_prop = file(os.path.join(app_dir, 'project.properties'), 'a') file_prop.write('proguard.config=${sdk.dir}/tools/proguard/' 'proguard-android.txt:proguard-xwalk.txt') file_prop.close() # Add proguard cfg file. if not os.path.exists(os.path.join(app_dir, 'proguard-xwalk.txt')): print('Error, proguard config file for Crosswalk not found!') sys.exit(14) # Check whether external extensions are included. print(' * Checking for external extensions') extensions_string = 'xwalk-extensions' extensions_dir = os.path.join(app_dir, extensions_string) external_extension_jars = FindExtensionJars(extensions_dir) for external_extension_jar in external_extension_jars: shutil.copyfile(external_extension_jar, os.path.join(app_dir, 'libs', os.path.basename(external_extension_jar))) if options.mode == 'embedded': print (' * Copying native libraries for %s' % options.arch) # Remove existing native libraries in xwalk_core_library, they are probably # for the last execution to make apk for another CPU arch. # And then copy the native libraries for the specified arch into # xwalk_core_library. arch = ConvertArchNameToArchFolder(options.arch) if not arch: print ('Invalid CPU arch: %s.' % arch) sys.exit(10) native_path = os.path.join(app_dir, 'native_libs', arch) library_path = os.path.join(app_dir, EMBEDDED_LIBRARY, 'libs') raw_path = os.path.join(app_dir, EMBEDDED_LIBRARY, 'res', 'raw') if options.enable_lzma: contains_library = ContainsCompressedLibrary clean_library = CleanCompressedLibrary copy_library = CopyCompressedLibrary else: contains_library = ContainsNativeLibrary clean_library = CleanNativeLibrary copy_library = CopyNativeLibrary # cleanup previous build's library first. for dir_name in os.listdir(library_path): clean_library(library_path, dir_name) if options.native_extensions: CheckValidationOfExpectedLibraryArch(options.native_extensions, options.arch) CopyNativeExtensionFile('.so', os.path.join(options.native_extensions, arch), native_path) if contains_library(native_path): copy_library(native_path, library_path, raw_path, arch) else: print('No %s native library has been found for creating a Crosswalk ' 'embedded APK.' % arch) sys.exit(10) else: if options.native_extensions: for arch_name in ALL_ARCHITECTURES: arch = ConvertArchNameToArchFolder(arch_name) extension_path = os.path.join(app_dir, SHARED_LIBRARY, 'libs', arch) library_path = os.path.join(options.native_extensions, arch) CheckValidationOfExpectedLibraryArch(library_path, arch_name) os.mkdir(extension_path) CopyNativeExtensionFile('.so', os.path.join(options.native_extensions, arch), extension_path) if options.project_only: print (' (Skipping apk package creation)') return # Build the APK if options.mode == 'embedded': print(' * Building Android apk package with Crosswalk embedded' + arch_string) else: print(' * Building Android apk package') ant_path = Which('ant') ant_cmd = [ant_path, 'release', '-f', os.path.join(app_dir, 'build.xml')] ant_cmd.extend(['-Dkey.store=%s' % os.path.abspath(key_store)]) ant_cmd.extend(['-Dkey.alias=%s' % key_alias]) if key_code: ant_cmd.extend(['-Dkey.store.password=%s' % key_code]) if key_alias_code: ant_cmd.extend(['-Dkey.alias.password=%s' % key_alias_code]) ignore_properties = "!.svn:!.git:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~" ant_cmd.extend(['-Daapt.ignore.assets=%s' % ignore_properties]) cmd_display = ' '.join([str(item) for item in ant_cmd]) if options.verbose: print('Executing:\n %s\n' % cmd_display) else: ant_cmd.extend(['-quiet']) ant_result = subprocess.call(ant_cmd) if ant_result != 0: print('Command "%s" exited with non-zero exit code %d' % (cmd_display, ant_result)) sys.exit(ant_result) src_file = os.path.join(app_dir, 'bin', '%s-release.apk' % name) package_name = name if options.app_version: package_name += ('_' + options.app_version) if options.mode == 'shared': dst_file = os.path.join(options.target_dir, '%s.apk' % package_name) elif options.mode == 'embedded': dst_file = os.path.join(options.target_dir, '%s_%s.apk' % (package_name, options.arch)) shutil.copyfile(src_file, dst_file) print(' (Location: %s)' % dst_file) #Copy proguard dumping files if options.mode == 'embedded' and options.enable_proguard \ and not options.project_dir: proguard_dir = os.path.join(app_dir, 'bin/proguard/') if os.path.exists(proguard_dir): for afile in os.listdir(proguard_dir): if afile.endswith('.txt'): shutil.copy(os.path.join(proguard_dir,afile), xwalk_dir) else: print('Warning:Cannot find proguard dumping directory!')