5

I am trying to port Android apps to Linux (don't laugh :) and I have come across a problem. When trying to execute an Android executable (app_process) after adding the executable permission with ./app_process it says it doesn't exist although cat ./app_process works.

Also in my file manager (Pantheon Files) the executable shows the shared library icon.

Is there any way to get these execute on Linux.

1 Answers1

10

Android and Linux are two different operating systems. You can't just take an executable from one and run it on the other.

The first hurdle is the kernel. Android and Linux are based on the same kernel, but they have a few different features. In particular, Android provides binders, which only exist in the mainstream kernel (the one found in Linux distributions) since version 3.19. A pure native-code application might not use binders but most Java apps do.

The second hurdle is the dynamic libraries. If you have a dynamically-linked executable, it invokes the dynamic linker. Android and Linux have different dynamic linkers, and if the dynamic linker is not present, you get the same error as if the executable itself was not present.

If you copy the dynamic linker, and the configuration files that it needs, and the native libraries, then you should be able to run most native programs. You'll need to copy most of /system, and the copy needs to be located at /system.

If you want to run Java apps, it's more complicated. You need the Java runtime environment (Dalvik/ART), and most apps require some Android daemons as well (some native-code apps also require those demons).

The upshot is that while the two systems can cohabit on one kernel, this needs to be a recent enough kernel, or an Android kernel (an Android kernel can run most Linux applications), and both operating systems need be installed — you can't just run an application from one on the other.

I'm not aware of any ready-made installer for Android on top of Linux. There are installers for the other way round, however, in particular LinuxonAndroid.

If the objective is to run an Android app on a Linux system, then the easiest way by far is to run it inside the emulator which is part of the Android development tools.

  • I copied everything in /system from a Android x86 ISO – Suici Doga May 21 '16 at 01:01
  • I have kernel 3.19.0-59-generic – Suici Doga May 21 '16 at 01:34
  • Running /lib/ld-linux.so.2 ./app_process32 gives me a segmentation fault – Suici Doga May 21 '16 at 01:35
  • @SuiciDoga /lib/ld-linux.so/2 is the Linux dynamic linker. You need to use the Android dynamic linker. On ARM that's /system/bin/linker, I don't know if x86 uses the same name. – Gilles 'SO- stop being evil' May 21 '16 at 13:45
  • How do I execute an executable with Android's linker. Android x86 has this file but it has the same library icon – Suici Doga May 24 '16 at 12:09
  • @SuiciDoga You just run /system/bin/linker ./app_process. Note that I'm not guaranteeing it'll work (in fact as I explain in my answer it probably won't), it'll just bring you to the next hurdle. – Gilles 'SO- stop being evil' May 24 '16 at 12:19
  • It gives me Segmentation fault (core dumped) – Suici Doga May 24 '16 at 13:05
  • Could it be the kernel.I could try adding the Android kernel code to the Linux kernel – Suici Doga May 27 '16 at 07:21
  • Can you reply to my comments – Suici Doga May 31 '16 at 02:05
  • @SuiciDoga I have nothing to add to my answer. There's a lot that can go wrong. If you decide to start from a Linux kernel, you're probably missing some features, and finding what you're missing is a big task. If you have a practical goal in mind, run an Android kernel. If you're doing this to understand how Linux and Android work, you're going to have to do some investigating. Start with using a debugger to find where the program crashes. – Gilles 'SO- stop being evil' May 31 '16 at 07:43
  • GDB says `Starting program: /system/bin/linker

    Program received signal SIGSEGV, Segmentation fault. 0x5655c540 in __dl___linker_init () `

    – Suici Doga May 31 '16 at 10:15
  • For some reason now when running ./app_process32 gives libc: Fatal signal 4 (SIGILL), code 2, fault addr 0xf745d23d in tid 12532 (app_process32) libc: Unable to open connection to debuggerd: Connection refused Illegal instruction (core dumped) – Suici Doga May 31 '16 at 10:22
  • I tried booting an Android kernel from my QEMU virtual machine (VirtualBox has a problem with Android kernels) and it gives me this error. Image Error.png – Suici Doga Jun 03 '16 at 08:20