Tuesday, February 28, 2012

Mono for Android Console finnaly compiled

Yesterday I got it. Here you have the mono.tar.gz. (Edit: Now a working 2.10.9 version including the most important assemblies from the GAC compiled without FPU support. Use the runmono script, or it will search the gac somewhere else than in the same path. The pagacke has about 7, the extracted content about 18 megabytes)
Inside the tar.gz is a single binary called mono. It's the whole unmanaged part of the runtime. In theory you should be able to just place it and all required assemblies into your project output directory and run "./monorun myproject.exe"

The build script will come in a few hours.

So, what was the problem? The -static flag got just removed by libtool.
What was the solution?
make LDFLAGS="$LDFLAGS -all-static"

Let me explain. Because different architectures have different needs and abilities, there is a script called libtool which abstracts the platform specific flags, tools and whatever. It's design is, that make calls libtool instead of gcc, libtool modifies the arguments given and calls gcc by itself. So the -static flag was removed from the LDFLAGS. Why I can only guess, maybe because some architectures like solaris have a real problem with -static. Doesn't really matter, -all-static tells libtool to add the -static flag everywhere.
So why give the modded LDFLAGS to make instead of configure? The configure script tries out gcc's ability to build running binaries. But that without libtool, so gcc throws an "I do not know that flag" error. And why only the LDFLAGS? Libtool throws the same error if the argument -mode=link is not set.

When the build script is posted, you will see a bit frickling with -l and -pthread flags. Yep, that was a bit try & fail. In a static build, you need to add all used libraries and their dependecies with -l to the linker flags. But here you need to take care, it can happen that you get multiple definitions. My example here was a function existing in libc and libpthread. So I had to remove -lc and -lpthread and use the gcc implementation -pthread which resolves this problem by itself.
If you want to know which libraries are needed here, just go somewhere where you have the dynamic linked binaries and type "ldd mybinary", it will list the linked libs. the ld-linux.so you need not to and also cannot add, thats the loader which is not more needed when you link statically.

I will now try if Core Droid is working with this mono binary, and if yes go further with Disk Droid and App Droid.

Ralph

Edit: Tried Core Droid, it throws a few exceptions, because of that first I'll pack a mono-dev.tar.gz containing everything needed for remote debugging.

6 comments:

  1. Hi, I am very interested in this project and willing to help it.

    I want to have a Mono Runtime for Android.
    How are you going with getting Mono Run in Android?

    Are you compiling under ARM or Cross Compiling?
    I can help you with debugging and fixing code. My primary development platform is Windows.

    Also I can generate Android bindings so we can use Android from Mono thru JNI.

    So let me know if you would like some help in those two areas, as I see you already did the investment to fix the Build System.

    ReplyDelete
    Replies
    1. Hi,

      You misunderstand the target of this a bit. It's not a replacement for http://xamarin.com/monoforandroid
      Sure, with a bit an effort it would be, many things are already done in the mono sources and just need to be compiled(I think even the JNI bindings).

      This was primary meant as as runtime for http://code.google.com/p/coredroidservice/ which is meant to be a mono bridge(rpc) between android and the underlying linux os. It's useful for building system apps, because there is no other way to run code in an app which accesses the linux base except the very unstable and slow Exec() of the Java Runtime.

      Take a look here http://code.google.com/p/coredroidservice/source/browse/trunk/CoreDroid/build
      That's the build script I used to compile mono.
      If you download the mono sources and run a "./configure --help" (sorry, but you need linux for such games) you will see there is a mono for android part you can enable on compile time.

      For building I used a Motorola Xoom (rooted) with my http://forum.xda-developers.com/showthread.php?t=987740 Ubuntu chroot environment. So you avoid cross compiling (cross compiling mono is hell, and the Tegra 2 in the Xoom is powerful enough to build mono in less than half of an hour).

      I hoped this helps you a bit. But if you just want to have a Mono runtime for Android itself, just use "Mono for Android". The 400 Dollars are not much compared to what you get for.

      Ralph

      Delete
    2. Hi, thanks for the explanation. I don't want to replace or compete with the Xamarin team, I just have some itches that I want to scratch. Do you plan to make available the debug and release versions of the ARM mono .so? That would be wonderful for developers needing some advanced features not possible in MonoDroid.

      I bought a few months ago the MonoDroid product but I find it lacking for some advanced uses:
      1. You have to recompile your assemblies for MonoDroid to match that version. While I understand the Business reason for this, technically it is a burden specially when you program in different languages like Boo, VFP for .NET, like I do.
      2. It is missing some components like Mono.Cairo and System.Drawing, that can be made available easily in Android (Cairo is already ported to Android).
      3. The ADO.NET stack in particular sqlite is not working, this could be easily fixed but it has been open for several months now.
      4. System.Dynamic assembly is not included, that is a must for the dynamic languages I work with.
      5. There are bugs in the Mono Runtime for Android that I could fix if I had a debug version of the native mono, I was stuck with such a bug by the end of last year.
      6. There is a need to have a binding generator to use any jar in your project.
      7. I expect NACL (native client from Google) to be eventually available in Android thru Chrome. I don't want to recompile the assemblies to yet another runtime. I am lazy, I just want to copy the assemblies there.
      I hope the Xamarin team succeeds as an Android Tool Vendor, and I already expect to renew my Xamarin Suscription by year's end when it expires. I just wish it was easier to have the Full Mono stack there and reap the benefits of Open Source software.

      Delete
    3. the android runtime is included in the sources. you can fix and build your own monodroid. then you can yust take what you made and merge it into your mono for android installation. i will upload on weekend the whole target of my mono build. but i think you will have a problem with the ui. that build includes the libc and there are flags to set when it should run for android which are not set. its just a build for linux.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Thank you for making this. I have many mono unix tools that I have made over the years that I would like to use on my android.

    I have made some modifications to the monorun script to allow it to be linked to /system/bin for access anywhere on the system. Is there a repository when I can submit these? I would also like to start contributing to this project to get complete functionality.

    ReplyDelete