Android Studio:构建多个目标

时间:2016-08-23 21:05:00

标签: android android-studio gradle wear-os

我正在为Android Wear和Android手机设备开发应用。这两个应用都在Android Studio的常见项目中。实际上,该应用程序使用三个与单个电话一起工作的磨损设备。因此,当我重新编译应用程序测试时,我需要在一部手机上构建和安装应用程序,每次都需要三个佩戴设备。有没有办法用一个命令自动构建和安装到所有这四个设备?我想可以在Android Studio中从终端运行脚本,但我不知道从哪里开始。感谢。

1 个答案:

答案 0 :(得分:0)

按照上面cricket_007的建议,我开始挖掘Android Studio,看它是否会报告安装命令。我找到了命令,将它们放在一个shell脚本文件中,现在我可以将apk安装到四个磨损设备上。 首先,在Android Studio中,我转到:Build |建立APK。生成穿戴apk文件。然后我使用以下命令执行shell脚本:

echo "Installing 422E..."
adb -s G6NZCJ00401422E push /Users/fred/abcdec/apps/myWearApp/wear/build/outputs/apk/wear-debug.apk /data/local/tmp/com.xyz.myWearApp
adb -s G6NZCJ00401422E shell pm install -r "/data/local/tmp/com.xyz.myWearApp"
echo "Starting 422E..."
adb -s G6NZCJ00401422E shell am start -n "com.xyz.myWearApp/com.xyz.myWearApp.MainWearActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER


echo "Installing 6227..."
adb -s G6NZCJ004076227 push /Users/fred/abcdec/apps/myWearApp/wear/build/outputs/apk/wear-debug.apk /data/local/tmp/com.xyz.myWearApp
adb -s G6NZCJ004076227 shell pm install -r "/data/local/tmp/com.xyz.myWearApp"
echo "Starting 6227..."
adb -s G6NZCJ004076227 shell am start -n "com.xyz.myWearApp/com.xyz.myWearApp.MainWearActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER


echo "Installing 922a..."
adb -s G5NZCJ02746922A push /Users/fred/abcdec/apps/myWearApp/wear/build/outputs/apk/wear-debug.apk /data/local/tmp/com.xyz.myWearApp
adb -s G5NZCJ02746922A shell pm install -r "/data/local/tmp/com.xyz.myWearApp"
echo "Starting 922A..."
adb -s G5NZCJ02746922A shell am start -n "com.xyz.myWearApp/com.xyz.myWearApp.MainWearActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
echo "Done."

echo "Installing Moto…”
adb -s localhost:4444 push /Users/fred/abcdec/apps/myWearApp/wear/build/outputs/apk/wear-debug.apk /data/local/tmp/com.xyz.myWearApp
adb -s localhost:4444 shell pm install -r "/data/local/tmp/com.xyz.myWearApp"
echo "Starting Moto…”
adb -s localhost:4444 shell am start -n "com.xyz.myWearApp/com.xyz.myWearApp.MainWearActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
echo "Done."

当然,这也可以扩展到安装移动应用程序。我确信我可以找到gradle命令来实际编译.apk文件作为脚本的一部分。如果我发现了,我也会发布它。