Merge pull request #2492 from jason-simmons/gradle_flutter_jar
Build a Flutter.jar output for use by Android projects built without …
This commit is contained in:
56
engine/src/flutter/build/android/gyp/create_flutter_jar.py
Normal file
56
engine/src/flutter/build/android/gyp/create_flutter_jar.py
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
"""Create a JAR incorporating all the components required to build a Flutter application"""
|
||||
|
||||
import optparse
|
||||
import os
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
from util import build_utils
|
||||
|
||||
def main(args):
|
||||
args = build_utils.ExpandFileArgs(args)
|
||||
parser = optparse.OptionParser()
|
||||
build_utils.AddDepfileOption(parser)
|
||||
parser.add_option('--output', help='Path to output jar.')
|
||||
parser.add_option('--dist_jar', help='Flutter shell Java code jar.')
|
||||
parser.add_option('--native_lib', action='append', help='Native code library.')
|
||||
parser.add_option('--android_abi', help='Native code ABI.')
|
||||
parser.add_option('--asset_dir', help='Path to assets.')
|
||||
options, _ = parser.parse_args(args)
|
||||
build_utils.CheckOptions(options, parser, [
|
||||
'output', 'dist_jar', 'native_lib', 'android_abi', 'asset_dir'
|
||||
])
|
||||
|
||||
input_deps = []
|
||||
|
||||
with zipfile.ZipFile(options.output, 'w') as out_zip:
|
||||
input_deps.append(options.dist_jar)
|
||||
with zipfile.ZipFile(options.dist_jar, 'r') as dist_zip:
|
||||
for dist_file in dist_zip.infolist():
|
||||
if dist_file.filename.endswith('.class'):
|
||||
out_zip.writestr(dist_file.filename, dist_zip.read(dist_file.filename))
|
||||
|
||||
for native_lib in options.native_lib:
|
||||
input_deps.append(native_lib)
|
||||
out_zip.write(native_lib,
|
||||
'lib/%s/%s' % (options.android_abi, os.path.basename(native_lib)))
|
||||
|
||||
for asset_file in os.listdir(options.asset_dir):
|
||||
input_deps.append(asset_file)
|
||||
out_zip.write(os.path.join(options.asset_dir, asset_file),
|
||||
'assets/%s' % asset_file)
|
||||
|
||||
if options.depfile:
|
||||
build_utils.WriteDepfile(
|
||||
options.depfile,
|
||||
input_deps + build_utils.GetPythonDependencies())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -1753,6 +1753,47 @@ template("android_apk") {
|
||||
}
|
||||
}
|
||||
|
||||
if (defined(invoker.flutter_dist_jar)) {
|
||||
flutter_jar_target = "${_template_name}__create_flutter_jar"
|
||||
final_deps += [ ":$flutter_jar_target" ]
|
||||
|
||||
action(flutter_jar_target) {
|
||||
script = "//build/android/gyp/create_flutter_jar.py"
|
||||
depfile = "$target_gen_dir/$target_name.d"
|
||||
inputs = [
|
||||
_dist_jar_path,
|
||||
]
|
||||
outputs = [
|
||||
invoker.flutter_dist_jar,
|
||||
]
|
||||
args = [
|
||||
"--depfile",
|
||||
rebase_path(depfile, root_build_dir),
|
||||
"--output",
|
||||
rebase_path(invoker.flutter_dist_jar, root_build_dir),
|
||||
"--dist_jar",
|
||||
rebase_path(_dist_jar_path, root_build_dir),
|
||||
"--android_abi",
|
||||
"$android_app_abi",
|
||||
"--asset_dir",
|
||||
rebase_path(invoker.asset_location, root_build_dir),
|
||||
]
|
||||
foreach(native_lib, rebase_path(_native_libs, root_build_dir)) {
|
||||
args += [
|
||||
"--native_lib",
|
||||
native_lib,
|
||||
]
|
||||
}
|
||||
deps = [
|
||||
":$create_dist_target",
|
||||
":${_template_name}__prepare_native"
|
||||
]
|
||||
if (defined(invoker.deps)) {
|
||||
deps += invoker.deps
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group(target_name) {
|
||||
deps = final_deps
|
||||
if (defined(invoker.data_deps)) {
|
||||
|
||||
Reference in New Issue
Block a user