I need to test my application on multiple instances of the MonoForAndroid_API_10 emulator. I have made duplicate AVDs and can manually install and launch the app on each via the Visual Studio deploy action. I would like automate this process. When I make a change in the app I want to run a batch file to compile (I have this) and then deploy (and run if possible) on each AVD. The page http://docs.xamarin.com/guides/android/advanced_topics/build_process/ gives information on "build targets" but there is not enough detail. How do I specify the emulator that will receive the .apk? I am hoping I can make a batch file with msbuild commands, or a command lines to install an apk, on each designated emulator.
Can be done?
Hi Ryan
Its probably easier to just run a powershell script (or batch file) to use adb to deploy to the devices rather than try to use msbuild. It sounds like you already have a build process in place , so all you need to do it pass the .apk to a script and have it deploy to all attached devices.
I've attached a powershell script that does the job
You can just invoke it like so
powershell.exe ./deploytodevice.ps1 -apk test.apk
It will deploy to all the attached devices. You might need to add some error handling in there incase you can't install the .apk though.
If you also want to run the app, you'll need to look at the available adb shell commands and see if there is a way to start an activity from the command line (which I'm sure there is).
Dean
You need to check the AndroidManifest.xml in the obj/Debug directory not the one in Properties. There are some additional elements that are auto merged in.
Answers
Hi Ryan
Its probably easier to just run a powershell script (or batch file) to use adb to deploy to the devices rather than try to use msbuild. It sounds like you already have a build process in place , so all you need to do it pass the .apk to a script and have it deploy to all attached devices.
I've attached a powershell script that does the job
You can just invoke it like so
powershell.exe ./deploytodevice.ps1 -apk test.apk
It will deploy to all the attached devices. You might need to add some error handling in there incase you can't install the .apk though.
If you also want to run the app, you'll need to look at the available adb shell commands and see if there is a way to start an activity from the command line (which I'm sure there is).
Dean
Thanks, that works great. I had to add "-ExecutionPolicy ByPass" to the command line, but then it works perfectly.
I then tried using the adb shell commands to run the application, but I get the error "Permission Denial: starting Intent {...} from null (...) not exported from uid 10199. I tried adding android:exported="true" in the manifest, which allowed the activity to start, but the application failed with a popup message saying "Unfortunately, [app label] has stopped. The app does run when started manually.
Any ideas on this?
Ryan
Take a look at the AndroidManifest.xml in the obj/Debug/android folder and its the activity that has
<action android:name="android.intent.action.MAIN" />
on it that is the one you will want to run.
dellis:
My manifest file does not have an element. I looked in a couple of Android demo projects and none of them had an element in their manifest files.
I had added as a child inside of the element, which allowed
adb.exe -s [emulator] shell am start -n [package]/.main
to execute.
Should I be adding an element?
to
You need to check the AndroidManifest.xml in the obj/Debug directory not the one in Properties. There are some additional elements that are auto merged in.