Ram
Ram

Reputation: 46

Build and deploy Xamarin to an emulator through command line

I’m building a xamarin android app using visual studio community edition 2019 on windows. Inside visual studio gui I am able to build and deploy to android emulator. I’m willing to do this without using the gui, through command line . I understand msbuild can build. May I know the command to start the emulator and deploy the app?

Upvotes: 1

Views: 4437

Answers (2)

Saamer
Saamer

Reputation: 5109

Steps to Build & Deploy to Android through the command line (replace Sample with your project name):

  1. In your terminal/command line, run this msbuild Sample.Android/Sample.Android.csproj /verbosity:normal /t:Rebuild /t:PackageForAndroid /t:SignAndroidPackage /p:Configuration=Debug
  2. Then, change directory using cd Sample.Android/bin/Debug to find the the signed APK file,
  3. Using ADB(Android Debug Bridge), install it to your device/emulator with this command adb install com.tfp.sample-Signed.apk, explained here.

I have written a more detailed explanation over here.

Upvotes: 2

Ram
Ram

Reputation: 46

I'm a beginner batch scrip writer. So feel free to correct this:). This scripts work for me to build the xamarin visual studio project, start the emulator and deploy the apk. I have two batch files, the second one runs in parallel with the first one.

cmd.bat:

"C:\Program Files\Android\android-sdk\platform-tools\adb.exe" start-server
"C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" /p:Configuration=Debug /p:Platform="any cpu" /v:m "E:\App2\App2.sln"

@echo off

if %ERRORLEVEL%% == 0 (
start /min call "E:\App2\Build Commands\install.bat" ""
"C:\Program Files\Android\android-sdk\emulator\emulator.EXE" -no-boot-anim -avd lollypop -prop monodroid.avdname=lollypop
exit
) else (
pause
)

install.bat:

"C:\Program Files\Android\android-sdk\platform-tools\adb.exe" wait-for-device
"C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" -r /t:Install /v:m "E:\App2\App2.Android\App2.Android.csproj" /p:AdbTarget=-e
@echo off

if %ERRORLEVEL% == 0 exit else pause

Upvotes: 0

Related Questions