def _ensure_correct_java_version(): default_java_version = AndroidEnhanced._get_default_java_version() if default_java_version is None: print_error_and_exit( 'Java is not installed. Install Java for Android via %s' % _JAVA8_INSTALL_COMMAND_FOR_MAC) if default_java_version != _JAVA_VERSION_FOR_ANDROID: all_java_versions = AndroidEnhanced._get_all_java_versions() if _JAVA_VERSION_FOR_ANDROID in all_java_versions: print_error_and_exit( 'Java version %s is installed but default is set to Java %s.\n' 'Set the correct java version via "%s"' % (_JAVA_VERSION_FOR_ANDROID, default_java_version, _SET_JAVA8_AS_DEFAULT_ON_MAC)) else: print_error_and_exit( 'Java version is %s, Android needs Java %s.\n' 'On Mac install it with "%s"\nAnd then set default version' 'via "%s"' % (default_java_version, _JAVA_VERSION_FOR_ANDROID, _JAVA8_INSTALL_COMMAND_FOR_MAC, _SET_JAVA8_AS_DEFAULT_ON_MAC)) else: print_message('Correct Java version %s is installed' % default_java_version)
def _accept_all_licenses(self): cmd = 'yes | %s --licenses' % self._get_sdk_manager_path() return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd) if return_code != 0: print_error_and_exit('Failed to accept licenses, return code: %d' % return_code) license_regex = '([0-9]*) of ([0-9]*) SDK package licenses not accepted' result = re.search(license_regex, stdout) if result is None: print_message('All licenses accepted') else: print_message('%d of %d licenses accepted' % (int(result.group(1)), int(result.group(2))))
def start_avd(self, avd_name, headless_mode, verbose_mode): # cmd = '%s -avd %s -no-boot-anim -no-skin' % (self._get_emulator_path(), avd_name) cmd = '%s -avd %s -no-boot-anim' % ('./emulator', avd_name) if headless_mode: cmd = '%s -no-window' % cmd.strip() if verbose_mode: cmd = '%s -verbose' % cmd.strip() return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd, cwd=os.path.dirname(self._get_emulator_path())) if return_code != 0: print_error('Failed to start emulator\nstdout:\n' + stdout + '\n\nstderr:\n' + stderr) print_message('List of valid virtual devices') self.list_avds()
def _ensure_basic_packages_are_installed(self) -> bool: success = True installed_packages = self._get_installed_packages() basic_packages = self._get_basic_packages() num_packages = len(basic_packages) for i in range(0, num_packages): basic_package = basic_packages[i] if basic_package not in installed_packages: print_error('Basic packages \"%s\" is not installed' % basic_package) success = False else: print_message('Package %d/%d: \"%s\" is installed' % (i + 1, num_packages, basic_package)) return success
def _install_sdk_packages(self, package_names) -> bool: for package_name in package_names: exists = self._does_package_exist(package_name) if not exists: print_message('Package \"%s\" not found' % package_name) return False print_message('Installing packages [%s]...' % ', '.join(package_names)) package_names_str = '\"' + '\" \"'.join(package_names) + '\"' cmd = 'yes | %s --verbose %s' % (self._get_sdk_manager_path(), package_names_str) return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd) if return_code != 0: print_error('Failed to install packages \"%s\"' % ' '.join(package_names)) print_error('Stderr is \n%s' % stderr) return False return True
def update_all(self): cmd = '%s --update' % self._get_sdk_manager_path() return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd) if return_code != 0: print_error_and_exit('Failed to update, return code: %d' % return_code) count = 0 if stdout: for line in stdout.split('\r'): if line.find('Fetch remote repository'): continue else: count += 1 if count == 0: print_message('No packages to update') self._accept_all_licenses() else: print_message(stdout)
def create_avd(self, avd_name, api_version, arch, api_type): if api_type is None: api_type = 'google_apis' # Preferred if arch is None: if PlatformHelper.is_64bit_architecture(): arch = 'x86_64' else: arch = 'x86' package_name = AndroidEnhanced._get_system_images_package(api_version, arch, api_type) print_verbose('Package is %s' % package_name) self.install_api_version(api_version, arch=arch, api_type=api_type) # Say no to custom hardware profile. print_message('Creating AVD "%s" of type "%s" ' % (avd_name, package_name)) create_cmd = 'echo no | %s --verbose create avd --name %s --package "%s"' % ( self._get_avd_manager_path(), avd_name, package_name) return_code, stdout, stderr = PlatformHelper.execute_cmd(create_cmd) if return_code != 0: print_error('Failed to create AVD') print_error('stdout: %s' % stdout) print_error_and_exit('stderr: %s' % stderr) print_message('AVD \"%s\" created successfully' % avd_name)
def _ensure_basic_packages_are_installed(self) -> bool: success = True installed_packages = self._get_installed_packages() print_verbose('Installed packages are %s' % installed_packages) basic_packages = self._get_basic_packages() num_packages = len(basic_packages) for i in range(0, num_packages): basic_package = basic_packages[i] if basic_package == 'tools': print_message('Skipping over obsolete package \"%s\"' % basic_package) continue if basic_package not in installed_packages: print_error('Basic packages \"%s\" is not installed' % basic_package) success = False else: print_message('Package %d/%d: \"%s\" is installed' % (i + 1, num_packages, basic_package)) return success
def run_doctor(self) -> None: print_message('Checking java version...') self._ensure_correct_java_version() print_message('Checking SDK manager is installed...') self._ensure_sdkmanager_is_installed() print_message('Checking that basic Android packages are installed...') if not self._ensure_basic_packages_are_installed(): print_error_and_exit('Not all basic packages are installed')
def print_state_change_info(state_name, old_state, new_state): if old_state != new_state: print_message('\"%s\" state changed from "%s" -> "%s"' % (state_name, old_state, new_state)) else: print_message('\"%s\" state unchanged (%s)' % (state_name, old_state))