从命令行构建Android - 包似乎已损坏

【从命令行构建Android - 包似乎已损坏】炒沙作縻终不饱,缕冰文章费工巧。这篇文章主要讲述从命令行构建Android - 包似乎已损坏相关的知识,希望能为你提供帮助。
android Studio对我的电脑来说太慢了,所以我自己动手学习如何手动构建Android应用程序。我完成了这个脚本:

#!/usr/bin/env bash################################################################## #PREPARE ENVIRONMENT ################################################################## path=$(pwd) rm -rf bin rm -rf gen mkdir bin mkdir gen################################################################## #SET VARS ################################################################### Set your application name APP_NAME="mygame"# Define minimal Android revision ANDROID_REV="27.0.3" ANDROID_PLATFORM_REV="android-27"# Define java compiler command JAVAC="${JAVA_BIN}/javac -classpath ${ANDROID_SDK}/platforms/${ANDROID_PLATFORM_REV}/android.jar" JAVAC_BUILD="${JAVAC} -sourcepath src -sourcepath gen -d bin"################################################################## #PROCESS ################################################################### Generate R class and pack resources and assets into resources.ap_ file ${ANDROID_SDK}/build-tools/${ANDROID_REV}/aapt package -v -f -I ${ANDROID_SDK}/platforms/${ANDROID_PLATFORM_REV}/android.jar -M AndroidManifest.xml -A "assets" -S "res" -m -J "gen" -F bin/resources.ap_# Compile sources. All *.class files will be put into the bin folder ${JAVAC_BUILD} src/com/mycompany/mygame/*.java# Generate dex files with compiled Java classes ${ANDROID_SDK}/build-tools/${ANDROID_REV}/dx --dex --output=${path}/bin/classes.dex ${path}/bin# Recources file need to be copied. This is needed for signing. mv "${path}/bin/resources.ap_" "${path}/bin/${APP_NAME}.ap_"# Add generated classes.dex file into application package ${ANDROID_SDK}/build-tools/${ANDROID_REV}/aapt add ${path}/bin/${APP_NAME}.ap_ ${path}/bin/classes.dex${ANDROID_SDK}/build-tools/${ANDROID_REV}/zipalign -f -v 4 ${path}/bin/${APP_NAME}.ap_ ${path}/bin/${APP_NAME}_unsigned.ap_# Create signed Android application from *.ap_ file. ${ANDROID_SDK}/build-tools/${ANDROID_REV}/apksigner sign --ks ${path}/keystore/etamagotchi-release-key.keystore--ks-key-alias "mykeystore-alias" ${path}/bin/${APP_NAME}_unsigned.ap_# cp ${path}/bin/${APP_NAME}_unsigned.ap_ ${path}/bin/${APP_NAME}.apk# Delete temp file rm bin/*.ap_ rm bin/*.dex

它成功构建。如果我试图运行adb install mygame.apk它说:
[INSTALL_FAILED_INVALID_APK: Package couldn't be installed in /data/app/com.mycompany.mygame-1: Package /data/app/com.mycompany.mygame-1/base.apk code is missing]
如果我手动尝试安装它说“包看起来已损坏”。我的构建脚本有什么问题?
答案我将-source 1.7 -target 1.7 -bootclasspath "${JAVA_HOME}/jre/lib/rt.jar"添加到我的$JAVAC构建规则中

    推荐阅读