使用CrossWalk的python快速构建打包apk

Crosswalk快速构建打包app

这个一般是用于本身内容是web构建的,只需要用android来包个壳的app,官方提供了两种方式:

命令行打包

使用指定的命令参数来构建、打包app

  • --arch=arm 只打包出arm/x86的,不填默认打包出两种架构的
  • -f 全屏
  • --orientation==landscape 横屏
  • --use-animatable-view 使用动画效果进入
  • --name=应用名称
  • -package=应用的包名
  • --icon=图标
  • --app-url=加载网络的地址
  • --manifest=manifest.json文件地址
  • --target-dir=生成apk包的地址
  • --project-dir=生成android项目的地址
  • --project-only 对应只生成项目不编译

demo

  1. 只生成arm架构的apk包,全屏,使用启动动画效果,指定生成apk的位置

    1. python make_apk.py --arch=arm -f --use-animatable-view --name=Demo --package=com.act262.demo --app-url=http://www.baidu.com --target-dir=d:\demo
  2. 指定只生成demo的项目,不打包(可以定制一些其他UI)

    1. python make_apk.py -f --use-animatable-view --name=Demo --package=com.act262.demo --app-url=http://www.baidu.com --project-dir=d:\demo --project-only

使用manifest.json文件格式

如果不想在命令行中如此复杂的配置,那么可以使用manifest.json文件来配置这个项目的属性。 然后只需在命令行中指定需要使用的manifeset文件即可。
旧版本格式

  1. {
  2. "name": "pandakun2e",
  3. "manifest_version": 1,
  4. "version": "1",
  5. "app": {
  6. "launch":{
  7. "local_path": "index.html"
  8. }
  9. }
  10. }

新版本格式

  1. {
  2. "name": "simple",
  3. "xwalk_version": "0.0.0.1",
  4. "start_url": "index.html",
  5. "icons": [
  6. {
  7. "src": "icon.png",
  8. "sizes": "128x128",
  9. "type": "image/png",
  10. "density": "4.0"
  11. }
  12. ]
  13. }

出错问题:

  • 在命令行中,使用python打包出现错误
    1. File "D:\share\dev\crosswalk-12.41.296.9\util.py", line 47, in RunCommand
    2. return output.decode("utf-8")
    3. File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
    4. return codecs.utf_8_decode(input, errors, True)
    5. UnicodeDecodeError: 'utf8' codec can't decode byte 0xb3 in position 136: invalid
    6. start byte
    意思大概是编码转换问题,查看了源码下是utf-8格式的,我们一般国内的话应该是gb2312的编码,应该是根据当前系统的信息来用的。 只需要把这里的utf-8改成gb2312即可继续跑了。
    1. def RunCommand(command, verbose=False, shell=False):
    2. """Runs the command list, print the output, and propagate its result."""
    3. proc = subprocess.Popen(command, stdout=subprocess.PIPE,
    4. stderr=subprocess.STDOUT, shell=shell)
    5. if not shell:
    6. output = proc.communicate()[0]
    7. result = proc.returncode
    8. if verbose:
    9. print(output.decode("utf-8").strip())
    10. if result != 0:
    11. print ('Command "%s" exited with non-zero exit code %d'
    12. % (' '.join(command), result))
    13. sys.exit(result)
    14. return output.decode("utf-8")
    15. else:
    16. return None
    -->
    1. def RunCommand(command, verbose=False, shell=False):
    2. """Runs the command list, print the output, and propagate its result."""
    3. proc = subprocess.Popen(command, stdout=subprocess.PIPE,
    4. stderr=subprocess.STDOUT, shell=shell)
    5. if not shell:
    6. output = proc.communicate()[0]
    7. result = proc.returncode
    8. if verbose:
    9. print(output.decode("gb2312").strip())
    10. if result != 0:
    11. print ('Command "%s" exited with non-zero exit code %d'
    12. % (' '.join(command), result))
    13. sys.exit(result)
    14. return output.decode("gb2312")
    15. else:
    16. return None




posted @ 2015-05-08 09:16  act262  阅读(1434)  评论(0编辑  收藏  举报