我尝试着将一款游戏移植到Android上,但它是基于C语言,而Android也支持Java,但我相信一定有一种方法能够将C应用带到Android上,有人知道如何实现这一目标吗?


当前回答

谷歌已经在http://www.youtube.com/watch?v=5yorhsSPFG4上发布了谷歌I/O 2011:将C和c++游戏引入Android会议

这有助于理解NDK在c和c++中编写应用程序的使用。

如果你只是想交叉编译任何基于主机的原生游戏,并在android上运行它们,那么本文将展示3种方法。

1:使用独立工具链的静态编译

2:使用Android NDK的工具链进行交叉编译

3:交叉编译使用AOSP源代码

其他回答

从这一点来看,似乎是有可能的:

http://openhandsetmagazine.com/2007/11/running-c-native-applications-on-android-the-final-point/(现在只能通过WayBack Machine购买)

"the fact is only Java language is supported doesn’t mean that you cannot develop applications in other languages. This have been proved by many developers, hackers and experts in application development for mobile. The guys at Elements Interactive B.V., the company behind Edgelib library, succeeded to run native C++ applications on the Android platform, even that at this time there is still many issues on display and sound … etc. This include the S-Tris2 game and a 3D animation demo of Edgelib."

Android NDK是一个工具集,允许您使用C和c++等语言在本地代码中实现应用程序的部分内容。对于某些类型的应用程序,这可以帮助您重用用这些语言编写的代码库。

有关如何开始本地开发的更多信息,请点击此链接。

示例应用程序可以在这里找到。

我不确定NDK是否提供了官方Java API的全部覆盖。

来自http://developer.android.com/sdk/ndk/index.html#overview:

请注意,NDK没有 允许您只开发本机 应用程序。Android的主 运行时仍然是Dalvik虚拟的 机器。

这篇博客文章可能是一个好的开始:http://benno.id.au/blog/2007/11/13/android-native-apps 不幸的是,很多重要的东西都“留给读者做练习”。

通常情况下,你必须:

安装谷歌Android NDK。它 包含库,头文件,makfile 示例和GCC工具链 从您的C代码构建一个可执行文件 对于ARM,优化和链接它 如果需要,提供了库 使用提供的连接到电话 Adb接口和测试您的 可执行的

如果你想要销售一款应用:

用你的C代码构建一个库 创建简单的Java代码 使用这个库 将这个库嵌入应用程序 包文件 测试你的应用 免费出售或分发