Ejemplo n.º 1
0
def run(project_path, strings_file=None, logo_file=None, google_services_file=None, asset_paths_list=None, clear_old_assets=False):
    """
    Will inject files into an android project.

    Args:
       project_path: your android's app path
       strings_file: the path to the new strings.xml file
       logo_file: the path to the new logo file
       google_services_file: the path to the new Firebase json file
       asset_paths_list: an array of all of the assets you want to inject to the app
       clear_old_assets: toggle to true to remove old assets from your project
    """

    logger = lh.Logger(__file__)

    # copy all of the stuff
    if strings_file is not None:
        bp.inject_strings(project_path, strings_file)
        logger.info('strings.xml injected')

    if google_services_file is not None:
        bp.inject_google_services(project_path, google_services_file)
        logger.info('google_services.json injected')

    if logo_file is not None:
        bp.inject_logo(project_path, logo_file)
        logger.info('logo injected')

    if clear_old_assets is True:
        bp.clear_old_assets(project_path)
        logger.info('old assets cleared')

    if asset_paths_list is not None:
        bp.inject_assets(project_path, asset_paths_list)
        logger.info('all ' + str(len(asset_paths_list)) + ' assets injected')
Ejemplo n.º 2
0
def _build(project_path, output_dir, key_store_properties: KeyStoreProperties, version_properties: VersionProperties, gradle_path, binary_type, remove_older_binaries):
    logger = lh.Logger(name='[APK Builder]')  # build the logger

    # will prepare any resources according to the binary type
    if binary_type == _res.APK:
        release_command = _res.COMMAND_APK_GRADLE_RELEASE
        binary_release_path = _res.get_apk_output_path(project_path)
        binary_ext = _res.EXT_APK
    elif binary_type == _res.APP_BUNDLE:
        release_command = _res.COMMAND_APP_BUNDLE_GRADLE_RELEASE
        binary_release_path = _res.get_app_bundle_output_path(project_path)
        binary_ext = _res.EXT_APP_BUNDLE
    else:
        raise NotImplementedError(f"Unrecognized '{binary_type}' binary type")

    # check if 'signingConfig signingConfigs.release' exists in the build.gradle file
    is_release_enabled = _build_gradle_utils.check_if_release_enabled(project_path)

    if not is_release_enabled:
        logger.warning('*** NOTICE: build.gradle file has the line: "signingConfig signingConfigs.release". If you want to use KeyStoreProperties, remove this line from your build.gradle')

    logger.info('Preparing build.gradle file for automated release...')
    _build_gradle_utils.prepare_build_gradle_for_release(project_path, key_store_properties, version_properties, is_release_enabled)

    # clear latest binary file
    logger.info(f'Clearing latest {binary_ext} file from project...')
    fh.remove_file(binary_release_path)

    # create the binary
    logger.info(f'Building the {binary_type}...')
    _general_utils.release_binary(release_command, project_path, gradle_path)

    # if the apk creation failed, throw an exception
    if not fh.is_file_exists(binary_release_path):
        raise Exception(f"ERROR: Failed to create {binary_type} file")

    if remove_older_binaries:
        logger.info(f'Gradle finished! removing older {binary_ext} files from {output_dir} dir...')
        # remove previous apks from the directory
        fh.remove_all_files_with_extension(binary_release_path, binary_ext)

    logger.info(f'Copying the new {binary_ext} file...')
    # copy the binary to the user desired location (with the file name as the version code)

    # obtain the version code
    version_code = _build_gradle_utils.obtain_version_code(project_path)
    binary_dst_path = os.path.join(output_dir, f'{version_code}{binary_ext}')
    fh.copy_file(binary_release_path, binary_dst_path)

    logger.info('Sanitizing build.gradle file...')
    # revert the build.gradle file to it's previous form
    _build_gradle_utils.remove_sign_in_config_from_gradle(project_path)

    logger.info(f'{binary_type} file built successfully in:\n {binary_dst_path}')
 def __init__(self, custom_android_project_path,
              launcher_obj_list: list[LauncherObj],
              shortcut_keys_to_open_image_asset, launcher_resize_percent,
              launcher_background_color_hex, skip_if_output_dir_exists):
     self.logger = lh.Logger(name=self.LOGGER_TAG)  # build the logger
     self.custom_android_project_path = custom_android_project_path
     self.launcher_obj_list = launcher_obj_list
     self.shortcut_keys_to_open_image_asset = shortcut_keys_to_open_image_asset
     self.launcher_resize_percent = launcher_resize_percent
     self.launcher_background_color_hex = launcher_background_color_hex
     self.main_path = os.path.join(custom_android_project_path,
                                   self.STATIC_MAIN_RELATIVE_PATH)
     self.skip_if_output_dir_exists = skip_if_output_dir_exists
def change_package_name(project_path, new_package_name):
    # setup the logger
    logger = lh.Logger(__file__)

    # get the old package name
    old_package_name = get_package_name(project_path)

    logger.info("checking write permission in directory")
    # check if write permission granted
    bp.check_write_permission(project_path)

    logger.info("changing package name")
    # change the package name
    bp.change_package_name(project_path, old_package_name, new_package_name)

    logger.info("changing 3 inner dirs (inside src/main)")
    # change the 3 inner folders inside the src/main (/GeneralRemote/app/src/main/java/com/first/second)
    bp.change_inner_folders_names(project_path, old_package_name, new_package_name)

    logger.info("changing settings.gradle rootProject.name")
    # change the 3 inner folders inside the src/main (/GeneralRemote/app/src/main/java/com/first/second)
    bp.change_settings_gradle_file(project_path, new_package_name)

    logger.info("done!")