1#!/usr/bin/python 2# 3# Copyright 2017 Google Inc. 4# 5# Use of this source code is governed by a BSD-style license that can be 6# found in the LICENSE file. 7 8import argparse 9import os 10import re 11import shutil 12import subprocess 13import sys 14 15parser = argparse.ArgumentParser(description='builds skia android apps') 16parser.add_argument('-C', '--output_dir', help='ninja out dir') 17parser.add_argument('--no-daemon', default=False, action='store_true', help='disable gradle daemon') 18parser.add_argument('app_name') 19 20args = parser.parse_args() 21 22target_cpu = "arm64" 23android_buildtype = "debug" 24 25if args.output_dir == None: 26 sys.exit("unknown out directory") 27 28args_gn_path = os.path.join(args.output_dir, "args.gn") 29if os.path.exists(args_gn_path): 30 for line in open(args_gn_path): 31 m = re.match('target_cpu *= *"(.*)"', line.strip()) 32 if m: 33 target_cpu = m.group(1) 34 35# build the apk using gradle 36cmd = ['./apps/gradlew', 37 ':' + args.app_name + ':assemble' + target_cpu + android_buildtype, 38 '-papps/' + args.app_name, 39 '-P' + target_cpu + '.out.dir=' + os.path.abspath(args.output_dir)] 40if not args.no_daemon: 41 cmd += ['--daemon'] 42try: 43 subprocess.check_call(cmd, cwd=os.path.join(os.path.dirname(__file__), "..")) 44except subprocess.CalledProcessError as error: 45 print error 46 sys.exit("gradle build failed") 47 48# copy apk back into the main out directory 49current_dir = os.path.dirname(__file__) 50apk_src = os.path.join(current_dir, "..", "apps", args.app_name, "build", "outputs", "apk", 51 target_cpu, android_buildtype, 52 args.app_name + "-" + target_cpu + "-" + android_buildtype + ".apk") 53apk_dst = os.path.join(args.output_dir, args.app_name + ".apk") 54shutil.copyfile(apk_src, apk_dst) 55