How to run (not only install) an android application using .apk file?

前端 未结 7 1375
孤独总比滥情好
孤独总比滥情好 2020-11-29 18:04

Is there any command on cmd.exe that would allow me to start the main activity of a particular android application using the .apk file of that appl

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 18:45

    if you're looking for the equivalent of "adb run myapp.apk"

    you can use the script shown in this answer

    (linux and mac only - maybe with cygwin on windows)

    linux/mac users can also create a script to run an apk with something like the following:

    create a file named "adb-run.sh" with these 3 lines:

    pkg=$(aapt dump badging $1|awk -F" " '/package/ {print $2}'|awk -F"'" '/name=/ {print $2}')
    act=$(aapt dump badging $1|awk -F" " '/launchable-activity/ {print $2}'|awk -F"'" '/name=/ {print $2}')
    adb shell am start -n $pkg/$act
    

    then "chmod +x adb-run.sh" to make it executable.

    now you can simply:

    adb-run.sh myapp.apk

    The benefit here is that you don't need to know the package name or launchable activity name. Similarly, you can create "adb-uninstall.sh myapp.apk"

    Note: This requires that you have aapt in your path. You can find it under the new build tools folder in the SDK

提交回复
热议问题