Skip to content
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

Adding more assets #2132

Merged
merged 6 commits into from
Apr 29, 2020
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: 14 additions & 7 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ def get_bootstrap_name():
join(curdir, 'templates')))


def try_unlink(fn):
if exists(fn):
os.unlink(fn)


def ensure_dir(path):
if not exists(path):
makedirs(path)
Expand Down Expand Up @@ -239,8 +234,7 @@ def make_package(args):
assets_dir = "src/main/assets"

# Delete the old assets.
try_unlink(join(assets_dir, 'public.mp3'))
try_unlink(join(assets_dir, 'private.mp3'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like try_unlink isn't used any more, could you delete it?

shutil.rmtree(assets_dir, ignore_errors=True)
ensure_dir(assets_dir)

# Add extra environment variable file into tar-able directory:
Expand Down Expand Up @@ -304,6 +298,15 @@ def make_package(args):
tar_dirs.append(python_bundle_dir)
if get_bootstrap_name() == "webview":
tar_dirs.append('webview_includes')

for asset in args.assets:
asset_src, asset_dest = asset.split(":")
if isfile(realpath(asset_src)):
ensure_dir(dirname(join(assets_dir, asset_dest)))
shutil.copy(realpath(asset_src), join(assets_dir, asset_dest))
else:
shutil.copytree(realpath(asset_src), join(assets_dir, asset_dest))

if args.private or args.launcher:
make_tar(
join(assets_dir, 'private.mp3'), tar_dirs, args.ignore_path,
Expand Down Expand Up @@ -599,6 +602,10 @@ def parse_args_and_make_package(args=None):
help='Custom key=value to add in application metadata')
ap.add_argument('--uses-library', dest='android_used_libs', action='append', default=[],
help='Used shared libraries included using <uses-library> tag in AndroidManifest.xml')
ap.add_argument('--asset', dest='assets',
action="append", default=[],
metavar="/path/to/source:dest",
help='Put this in the assets folder at assets/dest')
ap.add_argument('--icon', dest='icon',
help=('A png file to use as the icon for '
'the application.'))
Expand Down
12 changes: 12 additions & 0 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ def add_parser(subparsers, *args, **kwargs):
# However, it is also needed before the distribution is finally
# assembled for locating the setup.py / other build systems, which
# is why we also add it here:
parser_packaging.add_argument(
'--add-asset', dest='assets',
action="append", default=[],
help='Put this in the assets folder in the apk.')
parser_packaging.add_argument(
'--private', dest='private',
help='the directory with the app source code files' +
Expand Down Expand Up @@ -949,6 +953,14 @@ def _fix_args(args):
fix_args = ('--dir', '--private', '--add-jar', '--add-source',
'--whitelist', '--blacklist', '--presplash', '--icon')
unknown_args = args.unknown_args

for asset in args.assets:
if ":" in asset:
asset_src, asset_dest = asset.split(":")
else:
asset_src = asset_dest = asset
# take abspath now, because build.py will be run in bootstrap dir
unknown_args += ["--asset", os.path.abspath(asset_src)+":"+asset_dest]
for i, arg in enumerate(unknown_args):
argx = arg.split('=')
if argx[0] in fix_args:
Expand Down