Skip to content

add release builds and apk signing #680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pythonforandroid/bootstraps/pygame/build/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked in Version Control Systems, as it is
# integral to the build system of your project.

# This file is only used by the Ant script.

# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.

# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

key.store=${env.P4A_RELEASE_KEYSTORE}
key.alias=${env.P4A_RELEASE_KEYALIAS}
key.store.password=${env.P4A_RELEASE_KEYSTORE_PASSWD}
key.alias.password=${env.P4A_RELEASE_KEYALIAS_PASSWD}
3 changes: 3 additions & 0 deletions pythonforandroid/bootstraps/pygame/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,8 @@ def parse_args(args=None):

make_package(args)

return args


if __name__ == '__main__':
parse_args()
3 changes: 3 additions & 0 deletions pythonforandroid/bootstraps/pygame/build/templates/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<property file="ant.properties" />
<loadproperties srcFile="project.properties" />

<property environment="env" />
<property file="build.properties" />

<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
unless="sdk.dir"
Expand Down
4 changes: 4 additions & 0 deletions pythonforandroid/bootstraps/sdl2/build/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

key.store=${env.P4A_RELEASE_KEYSTORE}
key.alias=${env.P4A_RELEASE_KEYALIAS}
key.store.password=${env.P4A_RELEASE_KEYSTORE_PASSWD}
key.alias.password=${env.P4A_RELEASE_KEYALIAS_PASSWD}
3 changes: 3 additions & 0 deletions pythonforandroid/bootstraps/sdl2/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ def parse_args(args=None):

make_package(args)

return args


if __name__ == "__main__":

parse_args()
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<isset property="env.ANDROID_HOME" />
</condition>

<property file="build.properties" />

<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.

Expand Down
66 changes: 51 additions & 15 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,21 @@ def _dist(self):
def apk(self, args):
'''Create an APK using the given distribution.'''

# AND: Need to add a parser here for any extra options
# parser = argparse.ArgumentParser(
# description='Build an APK')
# args = parser.parse_args(args)
ap = argparse.ArgumentParser(
description='Build an APK')
ap.add_argument('--release', dest='build_mode', action='store_const',
const='release', default='debug',
help='Build the APK in Release mode')
ap.add_argument('--keystore', dest='keystore', action='store', default=None,
help=('Keystore for JAR signing key, will use jarsigner '
'default if not specified (release build only)'))
ap.add_argument('--signkey', dest='signkey', action='store', default=None,
help='Key alias to sign APK with (release build only)')
ap.add_argument('--keystorepw', dest='keystorepw', action='store', default=None,
help='Password for keystore')
ap.add_argument('--signkeypw', dest='signkeypw', action='store', default=None,
help='Password for key alias')
apk_args, args = ap.parse_known_args(args)

ctx = self.ctx
dist = self._dist
Expand All @@ -550,21 +561,46 @@ def apk(self, args):
else:
args[i+1] = realpath(expanduser(args[i+1]))

env = os.environ.copy()
if apk_args.build_mode == 'release':
if apk_args.keystore:
env['P4A_RELEASE_KEYSTORE'] = realpath(expanduser(apk_args.keystore))
if apk_args.signkey:
env['P4A_RELEASE_KEYALIAS'] = apk_args.signkey
if apk_args.keystorepw:
env['P4A_RELEASE_KEYSTORE_PASSWD'] = apk_args.keystorepw
if apk_args.signkeypw:
env['P4A_RELEASE_KEYALIAS_PASSWD'] = apk_args.signkeypw
elif apk_args.keystorepw and 'P4A_RELEASE_KEYALIAS_PASSWD' not in env:
env['P4A_RELEASE_KEYALIAS_PASSWD'] = apk_args.keystorepw

build = imp.load_source('build', join(dist.dist_dir, 'build.py'))
with current_directory(dist.dist_dir):
build.parse_args(args)
shprint(sh.ant, 'debug', _tail=20, _critical=True)
build_args = build.parse_args(args)
output = shprint(sh.ant, apk_args.build_mode, _tail=20, _critical=True, _env=env)

# AND: This is very crude, needs improving. Also only works
# for debug for now.
info_main('# Copying APK to current directory')
apks = glob.glob(join(dist.dist_dir, 'bin', '*-*-debug.apk'))
if len(apks) == 0:
raise ValueError('Couldn\'t find the built APK')
if len(apks) > 1:
info('More than one built APK found...guessing you '
'just built {}'.format(apks[-1]))
shprint(sh.cp, apks[-1], './')

apk_re = re.compile(r'.*Package: (.*\.apk)$')
apk_file = None
for line in reversed(output.splitlines()):
m = apk_re.match(line)
if m:
apk_file = m.groups()[0]
break

if not apk_file:
info_main('# APK filename not found in build output, trying to guess')
apks = glob.glob(join(dist.dist_dir, 'bin', '*-*-{}.apk'.format(apk_args.build_mode)))
if len(apks) == 0:
raise ValueError('Couldn\'t find the built APK')
if len(apks) > 1:
info('More than one built APK found...guessing you '
'just built {}'.format(apks[-1]))
apk_file = apks[-1]

info_main('# Found APK file: {}'.format(apk_file))
shprint(sh.cp, apk_file, './')

@require_prebuilt_dist
def create(self, args):
Expand Down