Create an android container that works as an engine to run android apps

Hi Im currently working on a school project and what we are trying to do is to create a tool similar to anbox
but we couldn’t know how to get an android container we didn’t find any images or templates and our knowledge is a little bit limited on lxc .
So i hope that anyone could help us

https://build.anbox.io/android-images/2018/07/19/

Hi @stgraber we tried using anbox but we could not put it in a container .
So we tried to create our own android container but we did not find any good documentation or information to help us (we tried to follow your your instructions from your forum (so far the most useful infos we found about lxc ) yet we could not succeed )
can you help us or give us any information that could guide us toward our goal an thank you for advance

Update:
It seems it is possible to use containers to run Android on Linux.
The anbox project https://github.com/anbox/anbox does exactly this.
A new (sucessor) project is called waydroid: https://github.com/waydroid/waydroid
See also the Arch Wiki for more details: Waydroid - ArchWiki

It also seems possible to run LXC on Android.

So I was wrong :sweat_smile: , nonetheless the below methods can also be used :smiley:.


;tldr: Containers are not the best method for this, use Virtual machines combined with a x86-variant of android instead.

Other methods are to use either a virtualisation software or run a x86-version of android directly on your computer.
A second problem is that Android uses a different architecture (arm) than normal computers (x86) by default, so you also need to use a x86-variant of android for both methods.

You have 3 options:

  1. Use an Emulator (like Android Studio: 在 Android 模拟器上运行应用  |  Android 开发者  |  Android Developers )
  2. Use a version of Android that is compiled for x86, like Android x86: Download | Android-x86 , which can run in a virtualisation software like virtualbox (howto) or qemu; or directly on your computer.
    A list of more x86-variants of android is in the german wikipedia (the english version seems to not include it, but just search for the names and you will find something).
  3. Compile Android yourself for x86 (imo complicated): see for example project celadon (intel)

Regarding LXD in this scenario:
LXD now also supports virtual machines, so you can in theory also use LXD (but for now it is headless, so you won’t have a graphical interface; but it is planned to be included in the future).

You can also run the virtualisation software inside a container (mostly pointless (at least for private users)).

1 Like

@toby63 first of all Thank you guys a lot for your help
second the main reason we thought of working with containers that we have limited resources and we need to be able to connect at least a 50 person in the same time
right now we are working with anbox but we could not optimize our solution to meet the request in hand

@Riadh_Amami Sry for the misinformation :sweat_smile:.
I really thought it was not easily possible to use containers for running Android on Linux, but it is, as Anbox proves.

I don’t know how anbox works in detail.
It says something about using containers, but I am not sure, whether there is virtualization in use on top of it, or not.

:bulb: It seems that anbox is really using LXC to run android without virtualization involved.

In the end Android is (to some extend) “Linux-based” (not like a distribution, but more like a fork) (afaik),
but I don’t know if Android is capable to run on a linux kernel
Update: It seems the answer is yes, Android can run on a linux kernel, like anbox shows.

and if the Android kernel is capable of running LXD :thinking:
Update: See answer from stgraber below.

In case you find a good solution, tell us :slight_smile:, so other users will know about it.

@stgraber Could you tell us something about this?

  • Is it still possible to use LXC on Android?
  • Is it possible to use LXD (for running Android in a Container on a Linux Host)? (without any virtualization involved)
    • If yes, are complicated steps (like a custom kernel etc.) necessary?
  • Is it possible to run LXD on Android?
  1. Yes, LXC can be built on Android and we actually build test it regularly
  1. Yes, you can run Android as a container on LXC or LXD without needing a VM. That’s what Anbox does.
  2. I don’t think anyone tried or managed to get LXD fully built using musl-libc, but there are no real technical blockers, likely just a bunch of patches needed for anything that musl doesn’t lik (kinda like what we had to do for liblxc).
2 Likes

So now that I understand the possibilities correctly, maybe a better answer from me:

I don’t know about your capabilities, but as far as I see, anbox is using LXC, a kernel module and some (if not a lot) of other stuff.
So I assume it is not easily possible to replicate this in original LXD.
But you could take a look at the anbox github repo: https://github.com/anbox/anbox
And try to modify or replicate that for your specific usecase(s).

Take a look at this for example: https://github.com/anbox/anbox/issues/406

@stgraber Hello Sir, hope you doing great. I have setup anbox on a separate machine. I am developing android code on separate machine. I am accessing anbox via SSH locally . But how can i scale anbox against multiple requests from multiple machines. Actually i want share anbox containers(instances) on LAN.

I guess you might ask the question on anbox github repo:

But maybe stgraber also has an idea :smile:.

@morphis knows best :slight_smile:

Hi.
Try this.

I have replace android-28 with android-25

@toby63
Any usage scenario to run LXC or LXD on Android?