anadroid.build package

Submodules

anadroid.build.AbstractBuilder module

class anadroid.build.AbstractBuilder.AbstractBuilder(proj, device, resources_dir, instrumenter)[source]

Bases: ABC

An abstract class that defines the API for building apps using supported build systems.

android_home_dir

The path of the local Android home directory (value of $ANDROID_HOME).

Type:

str

proj

The project to build.

Type:

AndroidProject

device

The targeted device.

Type:

Device

resources_dir

The pyanadroid resources directory.

Type:

str

instrumenter

The instrumentation tool used.

Type:

AbstractInstrumenter

config

Build configurations.

abstract build()[source]

Abstract method for the complete build process of the app. Subclasses must provide an implementation for the full build process.

abstract build_apk()[source]

Abstract method for building the main APK of the app. Subclasses must provide an implementation for building the APK.

abstract build_tests_apk()[source]

Abstract method for building the test APKs of the app. Subclasses must provide an implementation for building test APKs.

get_config(key, default=None)[source]

Gets a configuration value identified by the given key. If no configuration is found, returns the specified default value.

Parameters:
  • key – The configuration key.

  • default – The default value to return if the key is not found.

Returns:

The value of the configuration key, or the default value.

Return type:

value (str)

anadroid.build.GracleBuildErrorSolver module

class anadroid.build.GracleBuildErrorSolver.KNOWN_ERROR(value)[source]

Bases: Enum

Enumerates the list of known gradle build errors that possibly can be fixed the framework.

BUILD_SDK_ERROR = 'The SDK Build Tools revision \\((.+)\\) is too low for project '
BUILD_TOOLS_CPU_ERROR = 'Bad CPU type in executable'
GOOGLE_REPO_ERROR = 'method google() for arguments'
LIBS_ERROR = 'No signature of method: java.util.ArrayList.call() is applicable for argument types'
MAYBE_MISSING_GOOGLE_REPO = 'Could not resolve all dependencies for configuration'
MIN_SDK_ERROR = 'uses-sdk:minSdkVersion (.+) cannot be smaller than version (.+) declared in'
NDK_BAD_CONFIG = "did not contain a valid NDK and couldn't be used"
NDK_TOOLCHAIN_ERROR = 'NDK toolchains folder'
NO_BUILD_TOOLS = 'failed to find Build Tools revision'
NO_GRADLEW_EXEC = 'gradlew: No such file or directory'
NO_TARGET_PLATFORM = 'failed to find target with hash string'
NO_WRAPPER = 'Could not find or load main class org.gradle.wrapper.GradleWrapperMain'
USER_HAS_TO_ACCEPT_INSTALL = 'INSTALL_FAILED_USER_RESTRICTED'
WRAPPER_ERROR = 'try editing the distributionUrl'
WRAPPER_MISMATCH_ERROR = 'Failed to notify project evaluation listener'
WRAPPER_PROP_ERROR = 'Wrapper properties file'
anadroid.build.GracleBuildErrorSolver.add_google_repo(main_grdl)[source]

Adds Google as repository to allprojects in main_grdl gradle file. :param main_grdl: path of build file.

anadroid.build.GracleBuildErrorSolver.add_google_repo_build_script(main_grdl)[source]

Adds Google as repository to buildscript block in main_grdl file. :param main_grdl: path of build file.

anadroid.build.GracleBuildErrorSolver.get_adequate_gradle_version(plugin_version)[source]

given the gradle plugin version, returns an adequate gradle version to match the plugin version.

Based on https://developer.android.com/studio/releases/gradle-plugin#updating-gradle table. :param plugin_version: Gradle-plugin version.

Returns:

adequate gradle version.

Return type:

version

anadroid.build.GracleBuildErrorSolver.get_gradle_plugin_version(gradle_file)[source]

returns gradle plugin version. gets value of com.android.tools.build contained in gradle_file.

Parameters:

gradle_fileU (str) – build.gradle filepath.

Returns:

plugin version.

Return type:

gradle_plugin_version (str)

anadroid.build.GracleBuildErrorSolver.is_known_error(output)[source]

Given the build output, checks if a known error occurred.

Returns:

KNOW_ERROR): the inferred error. If the error is not known, returns None.

Return type:

object (obJ

anadroid.build.GracleBuildErrorSolver.replace_build_tools_version(bld_file, old_bld_version, new_bld_version)[source]

replace build tools version on bld_file gradle file. :param bld_file: path of build file. :param old_bld_version: old version. :param new_bld_version: new version.

anadroid.build.GracleBuildErrorSolver.replace_gradle_plugin_version(bld_file, old_v, new_v)[source]

replace gradle plugin version on bld_file gradle file. :param bld_file: path of build file. :param old_v: old version. :param new_v: new version.

anadroid.build.GracleBuildErrorSolver.solve_known_error(proj, error, error_msg, **kwargs)[source]

Tries to fix known build error. :param proj(obj: AndroidProject): project that raised the error. :param error(obj: KNOWN_ERROR): :param error_msg: build output containing the error. :type error_msg: str

anadroid.build.GracleBuildErrorSolver.update_gradle_wrapper_version(gradle_wrap_prop_filepath, new_v)[source]

updates gradle wrapper version in properties file. :param gradle_wrap_prop_filepath: properties file path. :param new_v: new version.

anadroid.build.GracleBuildErrorSolver.upgrade_version_from_version_list(version_list, upgradable_candidate, opt='max')[source]

anadroid.build.GradleBuilder module

class anadroid.build.GradleBuilder.GradleBuilder(proj, device, resources_dir, instrumenter)[source]

Bases: AbstractBuilder

Class that extends AbstractBuilder functionality in order to build Gradle projects. .. attribute:: build_flags

build flags.

type:

dict

change_history

list of changes performed to project.

Type:

list

gradle_plg_version

Gradle plugin version for proj.

Type:

str

build_tools_version

Gradle version for proj.

Type:

str

adapt_target_sdk_upgrade(gradle_file)[source]

Adapts target sdk upgrade to connected device if needed. :param gradle_file: gradle file.

build(rebuild=False)[source]

builds project if project is not build yet or rebuild is True. :param rebuild: True if the project has to be rebuilt.

Returns:

True if success, False otherwise.

Return type:

bool

build_apk(build_type=BUILD_TYPE.DEBUG)[source]

Build apk of build_type. :param build_type: build type.

Returns:

True if success, False otherwise.

Return type:

bool

build_local_properties_file()[source]

builds local.properties file content. :returns: file content. :rtype: str

build_proj_and_apk(build_type=BUILD_TYPE.DEBUG, build_tests_apk=False, rebuild=False)[source]

builds project and generates apk of build type. It can optionally build the tests apk and/or rebuild the current project in case it was already built. :param build_type: type of build to perform. :type build_type: BUILD_TYPE :param build_tests_apk: True if the tests’ apk has to be generated, False otherwise. :type build_tests_apk: bool :param rebuild: True if the current build has to be cleaned and rebuilt, False otherwise. :type rebuild: bool

Returns:

build results.

Return type:

bool

build_tests_apk()[source]

builds tests apk. :returns: True if success, False otherwise. :rtype: bool

build_with_gradlew(tries=5, target_task='build', skip_lint=False)[source]

performs build task with gradle. :param tries: number max of tries to fix build errors. :param target_task: task to perform.

Returns:

True if success, False otherwise.

Return type:

bool

create_app_from_installed_apk(gradle_output, build_type)[source]

create App object from installed apk on device. :param gradle_output: build output. :param build_type: build type.

Returns:

created app.

Return type:

app(App)

install_apks(build_type=BUILD_TYPE.DEBUG, install_apk_test=False)[source]

install apk of build_type and optionally de tests apk. :param build_type: build type. :type build_type: BUILD_TYPE :param install_apk_test: True if the tests’ apk has to be installed, False otherwise. :type install_apk_test: bool

Returns:

list of installed apks.

Return type:

apps_list(list)

needs_external_lib_dependency()[source]

needs build dependencies from instrumenter. :returns: True if needs, False otherwise. :rtype: bool

needs_min_sdk_upgrade(gradle_file)[source]

infers if module needs min sdk upgrade in order to the app be installed on the current device. :param gradle_file: gradle file.

needs_rebuild()[source]

checks if project needs rebuild. :returns: True if needs, False otherwise. :rtype: bool

regist_error_build(task='build')[source]

record successful build in file. :param task: build task name.

regist_successful_build(task='build')[source]

record successful build in file. :param task: build task name.

sign_apks(build_type=BUILD_TYPE.DEBUG)[source]

Sign project apks of build_type. :param build_type: build type.

Returns:

True if success, False otherwise.

Return type:

bool

uninstall_all_apks()[source]

uninstall all project apks.

was_attempted_to_build_before()[source]

checks if there was a build attempt before. :returns: True if yes, False otherwise. :rtype: bool

was_last_build_successful(task='build')[source]

checks if last build attempt was successful. inspects BUILD_RESULTS_FILE file and checks build result. :returns: True if build was successful, False otherwise. :rtype: bool

anadroid.build.GradleBuilder.gen_dependency_string(dependency)[source]

generates dependency format to be inserted in gradle files. :param dependency(obj: BuildDependency): dependency.

Returns:

dependency format as string.

Return type:

dependency_string(str)

anadroid.build.GradleBuilder.is_library_gradle(bld_file)[source]

checks if bld_file is a build file from a library. :returns: True if is a library, False otherwise. :rtype: bool

anadroid.build.GradleBuilder.set_transitive_names(gradle_plugin_version)[source]

Given the gradle-plugin version, sets the most adequate nomenclature to use in dependencies definition. :param gradle_plugin_version: gradle-plugin version.

anadroid.build.SdkManagerWrapper module

class anadroid.build.SdkManagerWrapper.SDKManager[source]

Bases: object

Abstract calls to sdkmanager binary. Provides methods to enumerate and install platform-tools or build-tools.

download_build_tools_version(version)[source]

downloads a given build tools version. :param version: build tools version.

download_platform(plat_version)[source]

downloads a given platforms version. :param plat_version: platforms version.

download_platform_tools_version(version)[source]

downloads a given platform-tools version. :param version: platform-tools version.

get_list_of_available_build_tools()[source]

lists the available build_tools. :returns: list of versions. :rtype: version_list(list of DefaultSemanticVersion)

is_build_tools_installed(build_tools_version)[source]

Checks if a given build tools version is installed. :param build_tools_version: build tools version to check.

Returns:

True if installed, False otherwise.

Return type:

bool

is_platform_tools_installed(plat_tools_version)[source]

Checks if a given build platform-tools version is installed. :param plat_tools_version: platform-tools version to check.

Returns:

True if installed, False otherwise.

Return type:

bool

is_platforms_installed(plat_version)[source]

Checks if a given build platforms version is installed. :param plat_version: platforms version to check.

Returns:

True if installed, False otherwise.

Return type:

bool

list()[source]

lists all available and downloadable resources through sdkmanager. :returns: list of resources. :rtype: str

anadroid.build.versionUpgrader module

class anadroid.build.versionUpgrader.DefaultSemanticVersion(full_version_id)[source]

Bases: object

Class to represent and compare sw versions labeled according to semver format.

anadroid.build.versionUpgrader.can_be_semantic_version(candidate)[source]

Module contents