1

I have a mono android project. I can use monodevelop to build the apk of my project. But I want to write a build file (like we do using ANT) with targets that can generate the .apk file.

Please point me to the right direction.

I have figured out the we need to use mandroid.exe to generate .apk from the .dll. the log shows that there is a target called _Manddroid that monodevelop's build tool runs. This target in turn runs following command

C:\Program Files\MSBuild\Novell\mandroid.exe -v --nosign --sdk-dir="C:\Android\android-sdk" --builddir="C:\Users\Sikha\Documents\Projects\helloShikha\helloShikha\obj\Debug\android" --framework-dir="C:\Program Files\Reference Assemblies\Microsoft\Framework\MonoAndroid\v2.2" --framework-dir="C:\Program Files\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0" -S="C:\Users\Sikha\Documents\Projects\helloShikha\helloShikha\obj\Debug\res" --package="helloShikha.helloShikha"   --nolink --abi="armeabi" --java-sdk-dir="C:\Program Files\Java\jdk1.6.0_30" --debug --sdk-platform="8" "C:\Users\Sikha\Documents\Projects\helloShikha\helloShikha\bin\Debug\helloShikha.dll" "C:\Program Files\Reference Assemblies\Microsoft\Framework\MonoAndroid\v2.2\Mono.Android.dll" "C:\Program Files\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\mscorlib.dll" "C:\Program Files\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Core.dll" "C:\Program Files\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.dll" "C:\Program Files\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Xml.dll"

When I try to copy paste the above command on cmd nothing happens. Any Idea what I am missing here?

vaibhav
  • 550
  • 5
  • 20

2 Answers2

4

I used following command and it generated the .apk file for me.

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe myproject.csproj /t:Package

I tried using .sln file but was receiving an error : target Package does not exist in the project. I opened the myproject.csproj file and figured out that this file imports Novell.MomoDroid.CSharp.Targets which in turn imports the Novell.MonoDroid.Common.Targets

The target "Package" is present in the file Novell.MonoDroid.Common.Targets.

vaibhav
  • 550
  • 5
  • 20
1

Why do you want to write alternative targets? The Mono for Android project files are MSBuild-based, and MSBuild is Microsoft's equivalent of ant. This means the csproj files are already fully extensible and customizable, and can be built using the commandline MSBuild tool:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe YourSolution.sln
Mikayla Hutchinson
  • 16,113
  • 2
  • 44
  • 50
  • Thankyou for you reply. I had tried it, but it produces .dll file only. I need to get .apk – vaibhav Mar 19 '12 at 05:26
  • I encountered another error while running the command mention in my question. this time I created an ant file and ran an exec passing all the required args. it says, monodroid:missing sdk-dir =DIRECTORY, can you help me with this? – vaibhav Mar 19 '12 at 12:31
  • MSBuild can produce apks just fine. How did you create the project? Is it a project you can build from within MD/VS? – Mikayla Hutchinson Mar 19 '12 at 14:40
  • Yes I can build the project using MonoDevelop and it gives me a .apk file. I created the projct using MD itself. – vaibhav Mar 20 '12 at 07:28
  • Maybe you're not invoking the correct target/configuration then? MD uses MSBuild to build the apk. – Mikayla Hutchinson Mar 20 '12 at 21:20
  • I have posted the command I am hitting in my question. Can you have a look at that and let me know what is wrong there? – vaibhav Mar 21 '12 at 04:54
  • also, can you help if to any document or online resource that can tell me more about how to use mandroid.exe? I need to know the syntaxes, expected output, where to look for the logs etc. Also, just started to wondering if it is possible to run mandroid.exe from cmd? – vaibhav Mar 21 '12 at 06:23