correctly update and download Android SDK with tools/platform-tools/build-tools if available. And install the API if necessary. closes #101, #21, #89.
This commit is contained in:
parent
6e03d04987
commit
d923c501d6
5 changed files with 1917 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,6 +2,7 @@
|
|||
|
||||
# Packages
|
||||
.*.swp
|
||||
.*.swo
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist
|
||||
|
|
|
@ -298,6 +298,30 @@ class Buildozer(object):
|
|||
ret_stderr = ''.join(ret_stderr)
|
||||
return (ret_stdout, ret_stderr, process.returncode)
|
||||
|
||||
def cmd_expect(self, command, **kwargs):
|
||||
from buildozer.libs.pexpect import spawn
|
||||
|
||||
# prepare the environ, based on the system + our own env
|
||||
env = copy(environ)
|
||||
env.update(self.environ)
|
||||
|
||||
# prepare the process
|
||||
kwargs.setdefault('env', env)
|
||||
kwargs.setdefault('show_output', self.log_level > 1)
|
||||
sensible = kwargs.pop('sensible', False)
|
||||
show_output = kwargs.pop('show_output')
|
||||
|
||||
if show_output:
|
||||
kwargs['logfile'] = stdout
|
||||
|
||||
if not sensible:
|
||||
self.debug('Run (expect) {0!r}'.format(command))
|
||||
else:
|
||||
self.debug('Run (expect) {0!r} ...'.format(command.split()[0]))
|
||||
|
||||
self.debug('Cwd {}'.format(kwargs.get('cwd')))
|
||||
return spawn(command, **kwargs)
|
||||
|
||||
def check_configuration_tokens(self):
|
||||
'''Ensure the spec file is 'correct'.
|
||||
'''
|
||||
|
|
0
buildozer/libs/__init__.py
Normal file
0
buildozer/libs/__init__.py
Normal file
1845
buildozer/libs/pexpect.py
Normal file
1845
buildozer/libs/pexpect.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -280,21 +280,58 @@ class TargetAndroid(Target):
|
|||
self.buildozer.info('Android NDK installation done.')
|
||||
return ndk_dir
|
||||
|
||||
def _android_list_sdk(self):
|
||||
available_packages = self.buildozer.cmd(
|
||||
'{} list sdk -u -e'.format(self.android_cmd),
|
||||
cwd=self.buildozer.global_platform_dir,
|
||||
get_stdout=True)[0]
|
||||
|
||||
# get only the line like -> id: 5 or "build-tools-19.0.1"
|
||||
# and extract the name part.
|
||||
return [x.split('"')[1] for x in
|
||||
available_packages.splitlines() if x.startswith('id: ')]
|
||||
|
||||
def _android_update_sdk(self, packages):
|
||||
from buildozer.libs.pexpect import EOF
|
||||
child = self.buildozer.cmd_expect('{} update sdk -u -a -t {}'.format(
|
||||
self.android_cmd, packages,
|
||||
cwd=self.buildozer.global_platform_dir))
|
||||
while True:
|
||||
index = child.expect([EOF, '[y/n]: '])
|
||||
if index == 0:
|
||||
break
|
||||
child.sendline('y')
|
||||
|
||||
def _install_android_packages(self):
|
||||
packages = []
|
||||
# 3 pass installation.
|
||||
need_refresh = False
|
||||
|
||||
# 1. update the tool and platform-tools if needed
|
||||
packages = self._android_list_sdk()
|
||||
if 'tools' in packages or 'platform-tools' in packages:
|
||||
self._android_update_sdk('tools,platform-tools')
|
||||
need_refresh = True
|
||||
|
||||
# 2. install the latest build tool
|
||||
if need_refresh:
|
||||
packages = self._android_list_sdk()
|
||||
build_tools = [x for x in packages if x.startswith('build-tools-')]
|
||||
if build_tools:
|
||||
build_tools.sort()
|
||||
self._android_update_sdk(build_tools[-1])
|
||||
need_refresh = True
|
||||
|
||||
# 3. finally, install the android for the current api
|
||||
android_platform = join(self.android_sdk_dir, 'platforms',
|
||||
'android-{0}'.format(self.android_api))
|
||||
if not self.buildozer.file_exists(android_platform):
|
||||
packages.append('android-{0}'.format(self.android_api))
|
||||
if not self.buildozer.file_exists(self.android_sdk_dir, 'platform-tools'):
|
||||
packages.append('platform-tools')
|
||||
if not packages:
|
||||
self.buildozer.info('Android packages already installed.')
|
||||
return
|
||||
if need_refresh:
|
||||
packages = self._android_list_sdk()
|
||||
android_package = 'android-{}'.format(self.android_api)
|
||||
if android_package in packages:
|
||||
self._android_update_sdk(android_package)
|
||||
|
||||
self.buildozer.cmd('chmod +x {}/tools/*'.format(self.android_sdk_dir))
|
||||
self.buildozer.cmd('{0} update sdk -u -a -t {1}'.format(
|
||||
self.android_cmd, ','.join(packages)),
|
||||
cwd=self.buildozer.global_platform_dir)
|
||||
self.buildozer.info('Android packages installation done.')
|
||||
|
||||
def install_platform(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue