def MakeApk(options, app_info, manifest): CheckSystemRequirements() Customize(options, app_info, manifest) name = app_info.android_name app_dir = GetBuildDir(name) packaged_archs = [] if options.mode == 'shared': MakeSharedApk(options, app_info, app_dir) else: # default MakeEmbeddedApk(options, app_info, app_dir, packaged_archs) # if project_dir, save build directory if options.project_dir: print ('\nCreating project directory') save_dir = os.path.join(options.project_dir, name) if CreateAndCopyDir(app_dir, save_dir, True): print (' A project directory was created successfully in:\n %s' % os.path.abspath(save_dir)) print (' To manually generate an APK, run the following in that ' 'directory:') print (' ant release -f build.xml') print (' For more information, see:\n' ' http://developer.android.com/tools/building/' 'building-cmdline.html') else: print ('Error: Unable to create a project directory during the build. ' 'Please check the directory passed in --project-dir, ' 'available disk space, and write permission.') if not options.project_only: PrintPackageInfo(options, name, packaged_archs)
def MakeApk(options, app_info, manifest): CheckSystemRequirements() Customize(options, app_info, manifest) name = app_info.android_name app_dir = GetBuildDir(name) packaged_archs = [] if options.mode == 'shared': # Copy xwalk_shared_library into app folder target_library_path = os.path.join(app_dir, SHARED_LIBRARY) shutil.copytree(os.path.join(xwalk_dir, SHARED_LIBRARY), target_library_path) Execution(options, app_info) elif options.mode == 'embedded': # Copy xwalk_core_library into app folder and move the native libraries # out. # When making apk for specified CPU arch, will only include the # corresponding native library by copying it back into xwalk_core_library. target_library_path = os.path.join(app_dir, EMBEDDED_LIBRARY) shutil.copytree(os.path.join(xwalk_dir, EMBEDDED_LIBRARY), target_library_path) library_lib_path = os.path.join(target_library_path, 'libs') native_lib_path = os.path.join(app_dir, 'native_libs') os.makedirs(native_lib_path) available_archs = [] for dir_name in os.listdir(library_lib_path): lib_dir = os.path.join(library_lib_path, dir_name) if ContainsNativeLibrary(lib_dir): shutil.move(lib_dir, os.path.join(native_lib_path, dir_name)) available_archs.append(dir_name) if options.arch: Execution(options, app_info) packaged_archs.append(options.arch) else: # If the arch option is unspecified, all of available platform APKs # will be generated. for arch in AllArchitectures(): if ConvertArchNameToArchFolder(arch) in available_archs: options.arch = arch Execution(options, app_info) packaged_archs.append(options.arch) else: print('Warning: failed to create package for arch "%s" ' 'due to missing native library' % arch) if len(packaged_archs) == 0: print('No packages created, aborting') sys.exit(13) # if project_dir, save build directory if options.project_dir: print('\nCreating project directory') save_dir = os.path.join(options.project_dir, name) if CreateAndCopyDir(app_dir, save_dir, True): print(' A project directory was created successfully in:\n %s' % os.path.abspath(save_dir)) print(' To manually generate an APK, run the following in that ' 'directory:') print(' ant release -f build.xml') print(' For more information, see:\n' ' http://developer.android.com/tools/building/' 'building-cmdline.html') else: print( 'Error: Unable to create a project directory during the build. ' 'Please check the directory passed in --project-dir, ' 'available disk space, and write permission.') if not options.project_only: PrintPackageInfo(options, name, packaged_archs)
def main(): parser = optparse.OptionParser() info = ('The package name. Such as: ' '--package=com.example.YourPackage') parser.add_option('--package', help=info) info = ('The apk name. Such as: --name="Your Application Name"') parser.add_option('--name', help=info) info = ('The version of the app. Such as: --app-version=TheVersionNumber') parser.add_option('--app-version', help=info) info = ('The versionCode of the app. Such as: --app-versionCode=24') parser.add_option('--app-versionCode', type='int', help=info) info = ('The application description. Such as:' '--description=YourApplicationdDescription') parser.add_option('--description', help=info) info = ('The permission list. Such as: --permissions="geolocation"' 'For more permissions, such as:' '--permissions="geolocation:permission2"') parser.add_option('--permissions', help=info) info = ('The url of application. ' 'This flag allows to package website as apk. Such as: ' '--app-url=http://www.intel.com') parser.add_option('--app-url', help=info) info = ('The root path of the web app. ' 'This flag allows to package local web app as apk. Such as: ' '--app-root=/root/path/of/the/web/app') parser.add_option('--app-root', help=info) info = ('The reletive path of entry file based on |app_root|. ' 'This flag should work with "--app-root" together. ' 'Such as: --app-local-path=/reletive/path/of/entry/file') parser.add_option('--app-local-path', help=info) parser.add_option('--enable-remote-debugging', action='store_true', dest='enable_remote_debugging', default=False, help='Enable remote debugging.') parser.add_option('--use-animatable-view', action='store_true', dest='use_animatable_view', default=False, help='Enable using animatable view (TextureView).') parser.add_option('-f', '--fullscreen', action='store_true', dest='fullscreen', default=False, help='Make application fullscreen.') parser.add_option('--keep-screen-on', action='store_true', default=False, help='Support keeping screen on') info = ('The path list for external extensions separated by os separator.' 'On Linux and Mac, the separator is ":". On Windows, it is ";".' 'Such as: --extensions="/path/to/extension1:/path/to/extension2"') parser.add_option('--extensions', help=info) info = ( 'The orientation of the web app\'s display on the device. ' 'Such as: --orientation=landscape. The default value is "unspecified"' 'The value options are the same as those on the Android: ' 'http://developer.android.com/guide/topics/manifest/' 'activity-element.html#screen') parser.add_option('--orientation', help=info) parser.add_option('--manifest', help='The manifest path') info = ( 'Use command lines.' 'Crosswalk is powered by Chromium and supports Chromium command line.' 'For example, ' '--xwalk-command-line=\'--chromium-command-1 --xwalk-command-2\'') info = ('Create an Android project directory at this location. ') parser.add_option('--project-dir', help=info) parser.add_option('--xwalk-command-line', default='', help=info) info = ('Minify and obfuscate javascript and css.' '--compressor: compress javascript and css.' '--compressor=js: compress javascript.' '--compressor=css: compress css.') parser.add_option('--compressor', dest='compressor', action='callback', callback=ParseParameterForCompressor, type='string', nargs=0, help=info) options, _ = parser.parse_args() try: icon_dict = { 144: 'icons/icon_144.png', 72: 'icons/icon_72.png', 96: 'icons/icon_96.png', 48: 'icons/icon_48.png' } app_info = AppInfo() if options.name is not None: app_info.android_name = options.name if options.app_root is None: app_info.app_root = os.path.join(xwalk_dir, 'test_data', 'manifest') else: app_info.app_root = options.app_root if options.package is not None: app_info.package = options.package if options.orientation is not None: app_info.orientation = options.orientation if options.app_version is not None: app_info.app_version = options.app_version if options.enable_remote_debugging is not None: app_info.remote_debugging = options.enable_remote_debugging if options.fullscreen is not None: app_info.fullscreen_flag = options.fullscreen app_info.icon = os.path.join('test_data', 'manifest', 'icons', 'icon_96.png') CustomizeAll(app_info, options.description, icon_dict, options.permissions, options.app_url, options.app_local_path, options.keep_screen_on, options.extensions, None, options.xwalk_command_line, options.compressor) # build project is now in /tmp/<name>. Copy to project_dir if options.project_dir: src_dir = GetBuildDir(app_info.android_name) dest_dir = os.path.join(options.project_dir, app_info.android_name) CreateAndCopyDir(src_dir, dest_dir, True) except SystemExit as ec: print('Exiting with error code: %d' % ec.code) return ec.code finally: CleanDir(GetBuildDir(app_info.android_name)) return 0
def MakeApk(options, app_info, manifest): CheckSystemRequirements() Customize(options, app_info, manifest) name = app_info.android_name app_dir = os.path.join(tempfile.gettempdir(), name) packaged_archs = [] if options.mode == 'shared': # For shared mode, it's not necessary to use the whole xwalk core library, # use xwalk_core_library_java_app_part.jar from it is enough. java_app_part_jar = os.path.join( xwalk_dir, 'xwalk_core_library', 'libs', 'xwalk_core_library_java_app_part.jar') shutil.copy(java_app_part_jar, os.path.join(app_dir, 'libs')) Execution(options, name) elif options.mode == 'embedded': # Copy xwalk_core_library into app folder and move the native libraries # out. # When making apk for specified CPU arch, will only include the # corresponding native library by copying it back into xwalk_core_library. target_library_path = os.path.join(app_dir, 'xwalk_core_library') shutil.copytree(os.path.join(xwalk_dir, 'xwalk_core_library'), target_library_path) library_lib_path = os.path.join(target_library_path, 'libs') native_lib_path = os.path.join(app_dir, 'native_libs') os.makedirs(native_lib_path) available_archs = [] for dir_name in os.listdir(library_lib_path): lib_dir = os.path.join(library_lib_path, dir_name) if ContainsNativeLibrary(lib_dir): shutil.move(lib_dir, os.path.join(native_lib_path, dir_name)) available_archs.append(dir_name) if options.arch: Execution(options, name) packaged_archs.append(options.arch) else: # If the arch option is unspecified, all of available platform APKs # will be generated. valid_archs = ['x86', 'armeabi-v7a'] for arch in valid_archs: if arch in available_archs: if arch.find('x86') != -1: options.arch = 'x86' elif arch.find('arm') != -1: options.arch = 'arm' Execution(options, name) packaged_archs.append(options.arch) else: print('Warning: failed to create package for arch "%s" ' 'due to missing native library' % arch) if len(packaged_archs) == 0: print('No packages created, aborting') sys.exit(13) # if project_dir, save build directory if options.project_dir: print('\nCreating project directory') save_dir = os.path.join(options.project_dir, name) if CreateAndCopyDir(app_dir, save_dir, True): print(' A project directory was created successfully in:\n %s' % os.path.abspath(save_dir)) print(' To manually generate an APK, run the following in that ' 'directory:') print(' ant release -f build.xml') print(' For more information, see:\n' ' http://developer.android.com/tools/building/' 'building-cmdline.html') else: print( 'Error: Unable to create a project directory during the build. ' 'Please check the directory passed in --project-dir, ' 'available disk space, and write permission.') if not options.project_only: PrintPackageInfo(options, name, packaged_archs)