Android 开发跨平台移动应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3369413/
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
Developing cross platform mobile application
提问by sohilv
More and more mobile platforms are being launched and sdk's are available to developers. There are various mobile platform are available: Android, iOS, Moblin, Windows mobile 7, RIM, symbian, bada, maemo etc.
越来越多的移动平台正在推出,开发人员可以使用 sdk。有各种移动平台可用:Android、iOS、Moblin、Windows mobile 7、RIM、symbian、bada、maemo 等。
And making of cross platform application is headache for developers. I am searching for common things across the platforms which will help to developers who want to port application to all platforms. Like what are the diff screen resolutions, input methods, open gl support etc. please share details that you know for the any of platform.
而跨平台应用的制作则是开发者头疼的问题。我正在寻找跨平台的通用内容,这将有助于希望将应用程序移植到所有平台的开发人员。像什么是不同的屏幕分辨率、输入法、open gl 支持等。请分享您所知道的任何平台的详细信息。
Or are there possibilities, by writing code in html (widget type of thing) and loading it into native application.
I know about the android, in which we can add the web view into application by calling setContentView(view)
或者是否有可能,通过在 html(小部件类型)中编写代码并将其加载到本机应用程序中。我知道 android,在其中我们可以通过调用将 web 视图添加到应用程序中setContentView(view)
Please share the class details where we can add the html view into native application of different type of platforms that you know.
请分享课程详细信息,我们可以将 html 视图添加到您知道的不同类型平台的本机应用程序中。
Purpose of this thread is share common details across developers. marking as community wiki.
此线程的目的是在开发人员之间共享公共细节。标记为社区维基。
Cross platform tools & library
跨平台工具和库
XMLVM, Codename Oneand iSpectrum (cross compile Java code from an Android app or creating one from scratch
Phone Gap(cross platform mobile apps)
Titanium (to build native mobile and desktop apps with web technologies)
Mono Touch ( C# for iphone )
rhomobile - http://rhomobile.com/samples are here: http://github.com/rhomobile/rhodes-system-api-samples
Sencha Touch - Sencha Touch is a HTML5 mobile app framework that allows you to develop web apps that look and feel native on Apple iOS and Google Android touchscreen devices. http://www.sencha.com/products/touch/
Corona - Iphone/Ipad / Android application cross platform library . Too awesome. http://anscamobile.com/corona/
A guide to port existing Android app to Windows Phone 7 http://windowsphone.interoperabilitybridges.com/articles/windows-phone-7-guide-for-iphone-application-developers
- Jquery MobileTouch-Optimized Web Framework for Smartphones & Tablets
XMLVM、Codename One和 iSpectrum(从 Android 应用程序交叉编译 Java 代码或从头开始创建一个
Phone Gap(跨平台移动应用程序)
Titanium(使用网络技术构建原生移动和桌面应用程序)
Mono Touch(iPhone 的 C#)
rhomobile - http://rhomobile.com/样本在这里:http: //github.com/rhomobile/rhodes-system-api-samples
Sencha Touch - Sencha Touch 是一个 HTML5 移动应用程序框架,允许您开发在 Apple iOS 和 Google Android 触摸屏设备上看起来和感觉原生的 Web 应用程序. http://www.sencha.com/products/touch/
Corona - Iphone/Ipad/Android 应用程序跨平台库。太厉害了 http://anscamobile.com/corona/
将现有 Android 应用程序移植到 Windows Phone 7 的指南 http://windowsphone.interoperabilitybridges.com/articles/windows-phone-7-guide-for-iphone-application-developers
- 用于智能手机和平板电脑的Jquery MobileTouch-Optimized Web 框架
采纳答案by TechZen
My answer here covers some of the technical limitations of cross-platfrom toolsbut let me expand a bit:
我在这里的回答涵盖了跨平台工具的一些技术限制,但让我扩展一下:
I think that cross-platform tools have historically always been also-rans because such tools have the wrong philosophical focus.
我认为跨平台工具在历史上也一直被忽视,因为这些工具的哲学重点是错误的。
All the selling points for cross-plaform tools are the benefits they bring to developers. They are sold on the idea that they allow the developersto write-once-run-anywhere. They are sold on the idea that they allow the developersto expand their market without learning new APIs. They are sold on the idea that they allow the developersto slash cost and time to market.
跨平台工具的所有卖点都是它们给开发者带来的好处。它们被认为允许开发人员在任何地方编写一次运行。他们被认为允许开发人员在不学习新 API 的情况下扩展他们的市场。它们被出售的想法是它们允许开发人员削减成本和上市时间。
What cross-plaform tool are NOTsold on is the benefit they bring to end users.
跨平台工具不出售的是它们给最终用户带来的好处。
Benefit to the end user is not a selling point because cross-platform development is seldom a benefit to the end user. The end user does not care how hard the developer had to work to bring the product to market. Nor do they care how many platforms the app can run on when they they don't use but one platform. They just care if the app does what they need it to on the hardware they need to run it on. Unless they have a specific need to run the app on many different platforms, the fact that it does brings them no value.
对最终用户的好处不是卖点,因为跨平台开发很少能给最终用户带来好处。最终用户并不关心开发人员为将产品推向市场付出了多少努力。当他们只使用一个平台时,他们也不关心应用程序可以在多少个平台上运行。他们只关心应用程序是否在他们需要运行的硬件上执行他们需要的操作。除非他们有在许多不同平台上运行应用程序的特定需求,否则它不会给他们带来任何价值。
Conversely, the inevitable compromises of making a cross-platform API mean that all the apps created by the API will be at best B-grade on every platform. They will never be the best tool to use on each platform.
相反,制作跨平台 API 不可避免的妥协意味着 API 创建的所有应用程序在每个平台上最多只能达到 B 级。它们永远不会成为在每个平台上使用的最佳工具。
All this means that in most use cases, cross-platform tools give the end user an inferior product compared to ones made with platform specific APIs. The end user will always have a better choice.
所有这一切都意味着,在大多数用例中,与使用特定于平台的 API 制造的产品相比,跨平台工具为最终用户提供了劣质产品。最终用户总会有更好的选择。
You make money in the long run by giving end users the most useful tools. If you don't philosophically concentrate on making the end user's life easier and more productive, you are pretty much doomed from the outset. End users have lots of choices and if your tool isn't one of the best you won't make it in the market.
从长远来看,您可以通过为最终用户提供最有用的工具来赚钱。如果您在哲学上不专注于使最终用户的生活更轻松、更高效,那么您从一开始就注定要失败。最终用户有很多选择,如果您的工具不是最好的工具之一,您将无法在市场上销售。
You should only use cross-platform tools if you think, "the users will really benefit from running this app on many different platforms." If you start out looking at cross-platform tools solely because they will make your (the developers) life easier, then you have picked them for the wrong reason and they will hurt you more than they will help.
如果您认为“用户将真正受益于在许多不同平台上运行此应用程序”,则您应该只使用跨平台工具。如果您开始考虑跨平台工具仅仅是因为它们会让您(开发人员)的生活更轻松,那么您选择它们的原因是错误的,它们对您的伤害大于帮助。
回答by Jla
There are several approaches to cross-platform development on mobile devices. Of course they all have limitations. No solution manages to take advantage of all the device's functionalities the way a native application can.
在移动设备上进行跨平台开发有多种方法。当然,它们都有局限性。没有任何解决方案能够像本机应用程序那样利用设备的所有功能。
Re-using code
重用代码
While all mobile OS don't use the same development language and API you can sometimes share some classes or logic tier code.
虽然所有移动操作系统不使用相同的开发语言和 API,但您有时可以共享一些类或逻辑层代码。
C++ for example can probably be re-used for an iOS application, for an Android app by using the NDK, for a Symbian app since they are developed in C++, etc.
例如,C++ 可能可以重新用于iOS 应用程序、使用NDK的 Android 应用程序、Symbian 应用程序,因为它们是用 C++ 开发的,等等。
Some solutions also offer the possibility to write the app in an other language than the one normally used by the device. The most famous (in fact the only one I know) are commercial and based on the Mono project(C# development):
一些解决方案还提供了使用设备通常使用的语言以外的其他语言编写应用程序的可能性。最著名的(实际上是我唯一知道的)是商业的并且基于Mono 项目(C# 开发):
- MonoTouchfor iPhone [ 1 ]
- MonoDroidfor Android (still in development)
- Similar project for BlackBerry(still in development)
- 适用于 iPhone 的MonoTouch[ 1 ]
- 适用于 Android 的MonoDroid(仍在开发中)
- BlackBerry 的类似项目(仍在开发中)
But I'm not sure we can really call this cross-platform development since the re-use of code is limited depending on the device :
但我不确定我们真的可以称之为跨平台开发,因为代码的重用是有限的,具体取决于设备:
- Windows Phone 7 will not allow native code development (maybe in further updates)
- AFAIK mono like project do not exist for all platforms (yet?) bada, webOS, maemo, etc.
- Windows Phone 7 将不允许本机代码开发(可能会在进一步更新中)
- AFAIK 单声道项目并不适用于所有平台(还?)bada、webOS、maemo 等。
And the UI part also stays specific to each device.
并且 UI 部分也特定于每个设备。
Web development
Web开发
A regular answer when asking about cross-platform development for mobiles is web development. We would then need a wrapper, that will use the mobile browser, to make it look and behave like a native application. That is how some of the cross-platform framework that we will see further on work.
当询问移动设备的跨平台开发时,通常的答案是 Web 开发。然后我们需要一个包装器,它将使用移动浏览器,使其看起来和行为像一个本机应用程序。这就是我们将在工作中进一步看到的一些跨平台框架的方式。
The rise of HTML5 brings to web development functionalities that could only be done with a native application like geolocation, off-line application, local storage.
HTML5 的兴起带来了 Web 开发功能,这些功能只能通过本地应用程序来完成,例如地理定位、离线应用程序、本地存储。
We can found more and more frameworks to develop web application for mobiles with a native look and feel by taking advantage of the latest web standards HTML5, CSS3, Js:
通过利用最新的 Web 标准 HTML5、CSS3、Js,我们可以找到越来越多的框架来开发具有原生外观和感觉的移动 Web 应用程序:
But HTML5 is still very young and implementation may vary from a browser to another. Most default mobile browsers use the WebKit engine (main exception being Windows mobile/phone using Internet Explorer) and even so they don't necessarily support the same functionalities. Local database is still awkward to work with and we can't be sure how it is going to implemented by the different browsers. Moreover, even with HTML5, web development is still very limited compared to a native app. You can't access contacts, camera, accelerometer, etc.
但是 HTML5 还很年轻,实现可能因浏览器而异。大多数默认移动浏览器使用 WebKit 引擎(主要的例外是使用 Internet Explorer 的 Windows 手机/手机),即使如此,它们也不一定支持相同的功能。本地数据库仍然难以使用,我们无法确定不同浏览器将如何实现它。此外,即使使用 HTML5,与本机应用程序相比,Web 开发仍然非常有限。您无法访问联系人、相机、加速度计等。
Edit: Earlier this month the W3C have delivered some warnings about the evolution of HTML5: Article from ZDNet
编辑:本月早些时候,W3C 发布了一些关于 HTML5 演变的警告:来自 ZDNet 的文章
So it will only suit a limited category of applications.
所以它只适合有限类别的应用程序。
Cross-platform frameworks
跨平台框架
And than we have the cross-platform mobile applications frameworks. With which you can presumably develop once and deploy on different platforms. These solutions usually focus on iOS and Android and rely on the WebKit engine. They offer more interaction with the phone functionalities while developing with web technologies. The most well-known are Nitobi PhoneGap, RhoMobile Rhodes, Appcelerator Titanium. But many others are out there and don't all use the same technique like MoSync which translate your code to it's own intermediate language before compiling it for the desired platform.
比我们有跨平台的移动应用程序框架。有了它,您大概可以开发一次并部署在不同的平台上。这些解决方案通常侧重于 iOS 和 Android,并依赖于 WebKit 引擎。在使用 Web 技术进行开发时,它们提供了更多与电话功能的交互。最著名的是 Nitobi PhoneGap、RhoMobile Rhodes、Appcelerator Titanium。但是还有很多其他的,并且并不都使用与 MoSync 相同的技术,该技术在为所需平台编译之前将您的代码转换为它自己的中间语言。
[ 1 ] Remember that Apple has a special policyabout apps written for their platform. They don't seem to be blocking these apps at this date but it is an information that should be taken into account.Edit: Apple has changed this policysince September 9.
[1]请记住,Apple对为其平台编写的应用程序有特殊政策。他们目前似乎没有阻止这些应用程序,但这是一个应该考虑的信息。编辑:自 9 月 9 日以来,Apple 已更改此政策。
回答by seand
You get some commonality when deploying as a webapp (html5 as mentioned above) but for rich native apps the APIs are completely different for the various smartphones.
部署为 web 应用程序(如上所述的 html5)时,您会获得一些共性,但对于丰富的本机应用程序,各种智能手机的 API 完全不同。
HTML5 may improve things somewhat but to do interesting things you need to go native.
HTML5 可能会有所改进,但要做有趣的事情,您需要原生。
There are 'cross platform' smartphone frameworks such as Phonegap but I've heard mostly bad things about using it for "real" work. (lots of overhead etc)
有“跨平台”智能手机框架,例如 Phonegap,但我听说将其用于“实际”工作的大多是坏事。(大量开销等)
回答by Mathias Conradt
Yes, html5 is getting some attention. You should also look at this consortium & platform to come in Q4. Not sure about the success of that project, as it sounds like a huge challenge, but here are the details:
是的,html5 受到了一些关注。你还应该看看这个财团和平台将在第四季度到来。不确定该项目是否成功,因为这听起来像是一个巨大的挑战,但以下是详细信息:
Website: http://www.wholesaleappcommunity.com/default.aspx
网站:http: //www.wholesaleappcommunity.com/default.aspx
新闻:http: //news.google.de/news/search?aq=f&pz=1&cf=all&ned=us&hl=en&q=%22Wholesale+Applications+Community%22
WAC aims to publish its initial specification and components of its SDK to developers in November. This specification will be based on W3C standards and create a strong platform for developing rich mobile web applications. WAC will also provide backwards compatibility for devices based upon the current JIL and BONDI specifications. (http://www.convergedigest.com/Bandwidth/newnetworksarticle.asp?ID=31021)
WAC 的目标是在 11 月向开发人员发布其 SDK 的初始规范和组件。该规范将基于 W3C 标准,并为开发丰富的移动 Web 应用程序创建一个强大的平台。WAC 还将为基于当前 JIL 和 BONDI 规范的设备提供向后兼容性。( http://www.convergedigest.com/Bandwidth/newnetworksarticle.asp?ID=31021)
.
.
It IS an international coalition of around 25 telecom companies that's aiming to create a platform open to all developers and selling to all mobile phone users. (http://www.downloadsquad.com/2010/02/15/atandt-wholesale-applications-community-is-a-platform-not-an-app/)
它是一个由大约 25 家电信公司组成的国际联盟,旨在创建一个向所有开发商开放并向所有手机用户销售的平台。(http://www.downloadsquad.com/2010/02/15/atandt-wholesale-applications-community-is-a-platform-not-an-app/)
回答by Fozi
As far as I know most of those devices are able to run this:
据我所知,这些设备中的大多数都能够运行:
Java ME - the Most Ubiquitous Application Platform for Mobile Devices
I think this can serve both as good and bad example.
我认为这既可以作为好的例子,也可以作为坏的例子。