Create | A powerful Android automation packaging script

This script is developed by me in the independent development process to improve the efficiency of Android application packaging and operation. The project address is,

github.com/Shouheng88/…

As shown by the language composition in the project, the script was developed entirely in Python.

1. How to use

It is very simple to use, first of all you need to prepare the following environment,

  • Prepare Python locale: Python3
  • Add the pyymal library:pip install pyyaml
  • Add the requests library:pip install requests
  • Add the requests_toolbelt library:pip install requests_toolbelt

Then, configure the script by editing the configuration file config.yml. for example,

build:
  gradlew: ../
  file: ../app/build.gradle
  ndk:
    abi_64: ndk {abiFilters 'arm64-v8a', 'x86_64'}
    abi_32: ndk {abiFilters 'armeabi-v7a', 'x86'}
  apk_output_dir: ../app/build/outputs/apk/prod/release
  # The mapping file location. 
  mapping_path: ../app/mapping.txt
dest:
  apk_dir: D:/codes/other/LeafNote-resources/apks
community:
  languages_dir: D:/codes/other/LeafNote-Community/languages/app
jiagu:
  exec_path: D:\360jiagubao_windows_64\jiagu\jiagu.jar
  account: xxxx
# ... 
复制代码

The YAML format is not new either, it was used in SpringBoot a few years ago. Compared with configuration files in json or properties format, it is more concise.

2. Main functions

1. Use the gradle command to automatically package to distinguish 32-bit and 64-bit : Because some application markets now clearly require the distinction between 32-bit and 64-bit, the packaging should be packaged separately.

2. After the package is complete, copy the APK to the specified directory : it is mainly used for local APK file backup, and the APK file copied here will be used for automatic reinforcement later.

3. Use diffuse to output the APK version difference report relative to the previous version : diffuse is a comparison tool for APK, AAB, AAR and JAR developed by JakeWharton. Here I use it to compare the APK information of the current version and the previous version to monitor the quality of the APK. The address of the diffuse project is github.com/JakeWharton…

3、拷贝多语言资源到指定的目录,并自动提交到 Github 仓库以便于协助翻译:对做国际化的应用的开发者而言,我们可以通过应用内的协助翻译功能借助社区的力量实现应用的多语言。这里我尽量将这个过程做得更加自动化。即在应用打包完成之后将应用内的多语言资源按照版本信息拷贝到指定的目录下。然后使用 Git 工具将其推送到 Github 等。具体的效果可以参考 github.com/Shouheng88/….

4、自动打 tag 并提交到远程仓库:该功能用来在打包完成之后使用为当前版本添加 Git tag,以便于后续根据版本回滚到指定的 Git 提交记录。

5、根据 Git 提交记录自动生成更新日志:上面做了为项目自动添加 Git tag 的功能之后,我们可以根据当前版本到上一版本之间的 Git 提交记录的 comment 信息自动生成版本更新日志。虽然,这个这样生成的更新日志并不能直接用作发布时的更新记录,但在至少可以让我们直观得看到这个版本修改了什么。

6、使用 360 加固 对上述 APK 进行加固并输出到指定的目录:加固操作其实非常简单,只需要一个 command 指令就可以完成了,

os.system("java -jar %s -login %s %s\
    && java -jar %s -jiagu %s %s -autosign -automulpkg"\
    % (config.jiagu_exec_path, config.jiagu_account, config.jiagu_password\
        , config.jiagu_exec_path, apk, out))
复制代码

不过在使用上述命令之前需要先通过 GUI 的形式修改你在 360 加固中的渠道和签名信息(直接手动改文件也可以)。

7、上传打包 APK 到蓝奏云:蓝奏云是现在很多开发者用来分享软件的一个云存储平台,100M 以下的文件可以免费存储,类似于百度云。上传蓝奏云之前需要先修改配置文件,

lanzou:
  ylogin: xxxx
  phpdisk_info: xxxx
复制代码

这里需要填入的 yloginphpdisk_info 可以在登录之后通过 Chrome 的开发工具查看 cookie 信息得到。目前能够做到自动化的一个方案就是使用上述两个信息。

8、通过 Telegram bot 将打包完成的渠道包和更新日志信息发送到 Telegram 群组:对海外的用户我们可以通过 Telegram 作为一个交流的渠道。Telegram 是一个非常好用的聊天软件。它提供了 bot 功能,即一个可以推送消息的机器人。我们可以通过这个功能来在群组中推送消息、图片和文件。Telegram 的 bot 有非常强大的自定义性。其实我们完全可以基于爬虫和 bot 维护一个社区,然后通过在社区内推送广告来获得一些利益。这也不失为一个赚钱的渠道。使用 Telegram bot 之前需要在配置文件中填入如下信息,

telegram:
  chat_id: xxxx
  token: xxxx
复制代码

这里的 token 是注册 bot 的时候得到的信息。chat_id 可以通过如下方式获取到:

  1. 首先把 Bot 添加到要推送的群组。然后在该群组里发送一条信息。
  2. 然后使用链接获取到,
https://api.telegram.org/bot<YourBOTToken>/getUpdates
复制代码

即将 token 信息填入到上述 <YourBOTToken> 处。在返回的 json 结果中可以获取到 chat id 信息。

向群组推送信息的方式非常简单,一个 http 请求即可完成,

url = TG_SEND_DOCUMENT_URL % (config.tg_token)
files = {
    'document': (name, open(path, 'rb'))
}
ret = requests.post(url, data={
    'chat_id': config.tg_chat_id,
    'caption': msg
}, files=files)
复制代码

更多的协议可以参考这个文档:core.telegram.org/bots/api#se…

9、完成上述操作之后使用邮件通知打包结果:最后就是在完成了最终的打包操作之后通过 Email 发送一封邮件,内部包含了本次打包的 diff 信息等给指定的用户。使用邮件功能需要在配置文件中填写,

mail:
  receivers:
    - xxxx
  user: xxxx
  password: xxxx
复制代码

Here we use QQ mailbox to send emails. The userand passwordfields that need to be filled in here are the email address and the password information provided by the system when the smtp service is activated, respectively. QQ mailbox can open the SMTP server and its official documents .

Summarize

The above are the main functions of the packaging script. I will add more features in the future. Due to limited time, some functions need to be modified before they can be used. However, I have encapsulated many functions into separate Python scripts, which can be slightly modified if needed. For this script, if you have better suggestions and ideas, you can communicate with me~

Guess you like

Origin juejin.im/post/7100218397937369102
Recommended