Linux 应用程序可以在 Android 中运行吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1636901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 17:50:27  来源:igfitidea点击:

Can Linux apps be run in Android?

androidlinux

提问by Prabhu R

Android is based on Linux; can native Linux applications be run on Android?

安卓基于Linux;原生 Linux 应用程序可以在 Android 上运行吗?

采纳答案by Kristopher Johnson

In general, no. Android apps generally run in a sandboxed Java-like virtual machine, so have to be written in Java or some language that compiles to virtual-machine bytecode that use the Android API.

一般来说,没有。Android 应用程序通常在沙盒类 Java 虚拟机中运行,因此必须用 Java 或某种语言编写,这些语言可编译为使用 Android API 的虚拟机字节码。

However, the virtual machine does run on top of the underlying Linux OS, and there are ways to call native code. See https://developer.android.com/tools/sdk/ndk/index.html

但是,虚拟机确实运行在底层 Linux 操作系统之上,并且有调用本机代码的方法。见https://developer.android.com/tools/sdk/ndk/index.html

So, while it is technically possible to run native Linux programs, as there is a Linux kernel running beneath everything, most users would not be able to install such applications or use them. (If you have root access or are building your own firmware, then you can do whatever you want.)

因此,虽然在技术上可以运行本机 Linux 程序,但由于在一切之下都有一个 Linux 内核在运行,大多数用户将无法安装或使用此类应用程序。(如果您有 root 访问权限或正在构建自己的固件,那么您可以随心所欲。)

回答by ZacharyP

Android does not run X Windows, nor does it have many of the standard GNU libraries. So, since most native linux applications require one or both of these, most will not run.

Android 不运行 X Windows,也没有许多标准的 GNU 库。因此,由于大多数本机 linux 应用程序需要其中之一或两者,因此大多数将无法运行。

In addition, even Java programs can be limited, because the version of Java that Android applications are written in is a subset of the standard Java library.

此外,甚至 Java 程序也可能受到限制,因为编写 Android 应用程序的 Java 版本是标准 Java 库的子集。

回答by ZacharyP

Not directly, no. Android's C runtime library, bionic, is not binary compatible with the GNU libc, which most Linux distributions use.

不直接,不。Android 的 C 运行时库 bionic 与大多数 Linux 发行版使用的 GNU libc 二进制不兼容。

You can always try to recompile your binaries for Android and pray.

您可以随时尝试为 Android 重新编译二进制文件并祈祷。

回答by Will

Yes they can if they're compiled under an arm linux first or using a cross compiler. Debian arm versatile works, there's also arm-eabi for compiling under x86 linux to arm linux.

是的,如果它们首先在 arm linux 下编译或使用交叉编译器,则可以。Debian arm 通用的作品,还有 arm-eabi 用于在 x86 linux 下编译到 arm linux。

回答by JimR

You can get an ARM cross compiler that runs on Linux here. You can also download the Android NDK and compile some command line apps. I do not have any personal experience with using C++ with either solution, but I have compiled a few simple things with both. It is my understanding that the NDK is not a full C++ compiler as there have been complaints that it will not compile some common C++ code.

您可以在此处获得在 Linux 上运行的 ARM 交叉编译器。您还可以下载 Android NDK 并编译一些命令行应用程序。我没有将 C++ 与这两种解决方案一起使用的任何个人经验,但我已经用这两种解决方案编译了一些简单的东西。我的理解是 NDK 不是一个完整的 C++ 编译器,因为有人抱怨它不会编译一些常见的 C++ 代码。

Note that since I am a new user, I cannot post the NDK link... :/

请注意,由于我是新用户,因此无法发布 NDK 链接...:/

回答by sherif

yes you can ;-)

是的你可以 ;-)

the simplest way is using this ->http://www.androidfanatic.com/community-forums.html?func=view&catid=9&id=2248

最简单的方法是使用这个 -> http://www.androidfanatic.com/community-forums.html?func=view&catid=9&id=2248

The old link is dead it was for a Debian install script There is an app for that in the android market but you will need root

旧链接已失效,它用于 Debian 安装脚本 在 android 市场上有一个应用程序,但您需要 root

回答by dongjk

android only use linux kernel, that means the GNU tool chain like gcc as are not implemented in android, so if you want run a linux app in android, you need recompile it with google's tool chain( NDK ).

android只使用linux内核,这意味着gcc这样的GNU工具链在android中没有实现,所以如果你想在android中运行linux应用程序,你需要用google的工具链(NDK)重新编译它。

回答by Chris de Vries

Yes you can. I have installed a complete Debian distribution in a chroot-jail enviroment using debootstrap. (You need a rooted device) I am now running ssh, apache, mysql, php and even a samba server under android on my htc-desire with no problems. It is possible to run x applications using a remote x server via ssh. It even runs openoffice.org and firefox. You can use this: http://code.google.com/p/android-xserver/to run X-application on localhost but my HTC-desire has a to small screen to be productive :-) But it might be usefull on a Eee Pad Transformer or something like that.

是的你可以。我已经使用 debootstrap 在 chroot-jail 环境中安装了一个完整的 Debian 发行版。(你需要一个有 root 权限的设备)我现在在我的 htc-desire 上运行 ssh、apache、mysql、php 甚至是 android 下的 samba 服务器,没有任何问题。可以通过 ssh 使用远程 x 服务器运行 x 应用程序。它甚至运行 openoffice.org 和 firefox。您可以使用它:http: //code.google.com/p/android-xserver/在本地主机上运行 X-application 但我的 HTC-desire 有一个小屏幕以提高生产力:-) 但它可能对Eee Pad Transformer 或类似的东西。

回答by jhunter_d

Yes, they can. If you do not have a rooted phone/tablet, then you could download c4droid hereto compile your apps. Then, you could download Kevin Boone's KBOX hereto run the program.

是的他们可以。如果你没有root手机/平板电脑,那么你可以在这里下载c4droid来编译你的应用程序。然后,您可以在此处下载 Kevin Boone 的 KBOX来运行该程序。

回答by ern0

Hell, of course yes, with several limitations.

地狱,当然是的,有几个限制。

Android is a kinda special Linux distribution, with no usual suff like X11, and you can't install Apache2 with apt-get. But if you have ARM cross-compiler, you can copy your ELF files to the device, and run it from a terminal app or if you have installed some SSHD app, you can even use SSH from your desktop/notebook to access the Android device.

Android 是一种特殊的 Linux 发行版,没有 X11 之类的常见功能,并且您无法使用 apt-get 安装 Apache2。但是如果你有 ARM 交叉编译器,你可以将你的 ELF 文件复制到设备上,然后从终端应用程序运行它或者如果你已经安装了一些 SSHD 应用程序,你甚至可以从桌面/笔记本使用 SSH 访问 Android 设备.

To copy and launch a native Linux executable, you have not root your device. That's the point, where I am, I've compiled my own tiny webserver to Android (and also for webOS), it runs, hallelujah.

要复制和启动本机 Linux 可执行文件,您还没有对您的设备进行 root 操作。这就是重点,我已经将自己的小型网络服务器编译到 Android(也适用于 webOS),它可以运行,哈利路亚。

There comes the issues, which I can't answer:

问题来了,我无法回答:

  1. My tiny webserver use only stdlib and pthreads. I have no idea how to use the (native Linux) libraries comes with Android, there are useful ones, altough, I can live without them.

  2. Now I can launch my app from a terminal app by hand. But I don't know, what's the best way of deploying such native apps to Android. I think I should be write a small Android app, which launches the server and not letting automatically stopped by the system (say, as like music players never killed). Also, if its a service, it should somehow started on boot. I'm not familiar with Android.

  1. 我的小型网络服务器仅使用 stdlib 和 pthreads。我不知道如何使用 Android 自带的(原生 Linux)库,虽然有一些有用的库,但没有它们我也能活。

  2. 现在我可以手动从终端应用程序启动我的应用程序。但我不知道,将此类本机应用程序部署到 Android 的最佳方式是什么。我想我应该写一个小的 Android 应用程序,它启动服务器而不是让系统自动停止(比如说,就像音乐播放器从未被杀死一样)。此外,如果它是一项服务,它应该以某种方式在启动时启动。我对安卓不熟悉。