您可以使用
python
,还要确保在执行此操作之前已经安装了python。
在根项目中创建python文件。
build.py
import subprocess
import shutil
import os
import sys
# Call this function to build the apk via gradle.
def build_cmd():
# This will build your debug apk.
buildProject = "gradlew.bat clean --profile --recompile-scripts --offline --rerun-tasks assembleDebug";
# If you want to build a release apk use this instead.
# buildProject = "gradlew.bat clean --profile --recompile-scripts --offline --rerun-tasks assembleRelease -Pandroid.injected.signing.store.file=" + os.path.abspath("store_key.jks") + " -Pandroid.injected.signing.store.password=pass123 -Pandroid.injected.signing.key.alias=key_alias -Pandroid.injected.signing.key.password=pass123"
# As of Python 3 use run() instead of call() function
# https://docs.python.org/3/library/subprocess.html#older-high-level-api
subprocess.run(buildProject, shell=True)
# Call this function to move the builded apk to your desire directory.
def moveDir():
# Get the generated apk
apk_path = "./app/build/outputs/apk/debug/app-debug.apk"
# apk will rename and move to asset directory
shutil.move(apk_path, "./app/src/main/assets/app-debug.apk")
if __name__ == '__main__':
build_cmd()
moveDir()
然后运行
建筑py公司
在终端中
python build.py
等待gradle任务完成。
编辑:
因为
某些成员在此项目上没有python环境
不要在python中使用脚本,而是尝试添加一些
任务
在您的
应用程序/内部版本。格拉德尔
android {
// Some stuffs of yours....
task copyAPKtoAsset(type: Copy) {
from "/build/outputs/apk/debug/app-debug.apk", "/build/outputs/apk/release/app-release.apk"
into "/src/main/assets/"
}
afterEvaluate {
packageDebug.finalizedBy(copyAPKtoAsset)
}
}
构建项目并检查
资产
之后的目录。