5

I have a Xamarin project am looking to build a Android apk using mdtool, and the command line. Here is the setup :

I have a mac mini - Xamarin Studio installed on it, I have the solution which build no problem. Now from the command line this is what I an trying to do

#REM Traverse to the folder which holds the .sln file
cd One/Xamarin/Android/OneAndroid 

#REM start the build using mdtool
'/Applications/Xamarin Studio.app/Contents/MacOS/mdtool' -v build OneAndroid.sln

The above completes the build for me , however I do not get an apk file. Could someone share with me which option needs to be added onto mdtool to generate an apk file?

Thanks Rajesh

I understand I maybe missing some parameters for mdtool

Alexandre Marcondes
  • 5,859
  • 2
  • 25
  • 31
Raj
  • 77
  • 2
  • 10

2 Answers2

6

Use XBuild to compile the APK, for example:

xbuild MyXamarinAndroidApplication.csproj /p:Configuration=Release /t:SignAndroidPackage

This will compile the project in release mode and generate a signed and unsigned APK. If you just want an unsigned APK:

xbuild MyXamarinAndroidApplication.csproj /p:Configuration=Release /t:PackageForAndroid

It's worth noting that you have to specify a .csproj, not a .sln. If you give it a solution file, you'll get an error complaining that it can't find the "SignAndroidPackage" target.

TarkaDaal
  • 18,798
  • 7
  • 34
  • 51
Tom Opgenorth
  • 1,511
  • 1
  • 12
  • 19
  • Hello Tom where can I install xbuild from? It is not part of Xamarin do I get from Mono? – Raj Feb 01 '14 at 15:02
  • 1
    It's a part of Mono, which is installed by Xamarin. On my Mac, it can be found at `/usr/bin/xbuild`. Not to sure where it is on Windows - but on Windows you can use MSBuild. – Tom Opgenorth Feb 03 '14 at 14:39
  • Thank you for this .. I am going to try and this now. – Raj Feb 04 '14 at 14:29
  • Hello Tom, I receive the following error : In short it cannot find CompileAndroidProject (/t:CompileAndroidProject) - if I remove the project does build "/Users/admin/Downloads/TeamCity/buildAgent/work/d0a702727a6205ae/NESTouch/Xamarin/Android/NESTouchAndroid/NESTouchAndroid.sln" (CompileAndroidPackage target(s)): [15:58:42][Step 3/3] Target ValidateSolutionConfiguration: [15:58:42][Step 3/3] Building solution configuration – Raj Feb 05 '14 at 12:22
  • "Debug|Any CPU". [15:58:42][Step 3/3] /Users/admin/Downloads/TeamCity/buildAgent/work/d0a702727a6205ae/NESTouch/Xamarin/Android/NESTouchAndroid/NESTouchAndroid.sln: error : Target named 'CompileAndroidPackage' not found in the project. [15:58:42][Step 3/3] Done building project "/Users/admin/Downloads/TeamCity/buildAgent/work/d0a702727a6205ae/NESTouch/Xamarin/Android/NESTouchAndroid/NESTouchAndroid.sln".-- – Raj Feb 05 '14 at 12:23
  • FAILED [15:58:42][Step 3/3] [15:58:42][Step 3/3] Build FAILED. [15:58:42][Step 3/3] Errors: [15:58:42][Step 3/3] [15:58:42][Step 3/3] /Users/admin/Downloads/TeamCity/buildAgent/work/d0a702727a6205ae/NESTouch/Xamarin/Android/NESTouchAndroid/NESTouchAndroid.sln (CompileAndroidPackage) -> [15:58:42][Step 3/3] [15:58:42][Step 3/3] /Users/admin/Downloads/TeamCity/buildAgent/work/d0a702727a6205ae/NESTouch/Xamarin/Android/NESTouchAndroid/NESTouchAndroid.sln: error : Target named 'CompileAndroidPackage' not found in the project [15:58:42][Step 3/3] 0 Warning(s) [15:58:42][Step 3/3] 1 Error(s) – Raj Feb 05 '14 at 12:24
  • Sorry, my bad. If you just want to create an unsigned APK, then you need to use `xbuild MyXamarinAndroidApplication.csproj /p:Configuration=Release /t:PackageForAndroid`. Updated the answer to reflect this. – Tom Opgenorth Feb 05 '14 at 15:02
  • Hello Tom, nope the build fails - it comes back with Target named 'PackageForAndroid' not found in the project. It does build through Xamarin Studio. – Raj Feb 05 '14 at 17:41
  • Hmm, what version of Xamarin.Android do you have installed? I have the latest version (4.10.1) and it works. Alternately, you could use the `/t:SignAndroidPackage` target. That will generate an unzigned APK and a signed APK. – Tom Opgenorth Feb 05 '14 at 18:07
  • @TomOpgenorth can you use .sln or any other variation to create the apk using Xbuild because I have a solution that has many projects linked together and it doesn't work for the .sln because of the reasons you stated, but also for the csproj because I need to use more than one .csproj and they are in separate folders giving me the error Assemblies not found. Or could you do multiple csproj's at once? – Ciaran Donoghue Jan 04 '17 at 17:40
  • @GuinnessIsLife I believe now that you should be able to use the solution file: `msbuild myproject.sln`. However that will not install or sign the APK for you. – Tom Opgenorth Jan 04 '17 at 19:53
  • @TomOpgenorth and can you use xbuild when you are using a mac? – Ciaran Donoghue Jan 05 '17 at 09:33
  • Because I am using Bamboo to create an IPA file and a APK file, the IPA file works but when I try to do this: `/p:Configuration=Release CustomerApp.sln` it doesn't work and I don't know why it gives the error `PCL Reference Assemblies not installed` this should not happen as it builds fine in xamarin and the IPA file had no problems creating the IPA file when using mdtool, any idea's what's wrong? Thanks – Ciaran Donoghue Jan 05 '17 at 10:25
  • Even if I do it in the terminal xbuild /p:Confiuration=Release Customer.sln I get the same error – Ciaran Donoghue Jan 05 '17 at 10:49
1

Check out the build process documentation from Xamarin: http://docs.xamarin.com/guides/android/advanced_topics/build_process/offline.pdf

Jon Douglas
  • 13,006
  • 4
  • 38
  • 51