android有没有像ios一样可以判断ios android全球手机号是否合法的类库

博客分类:
var isMobile = {
Android: function() {
return /Android/i.test(navigator.userAgent);
BlackBerry: function() {
return /BlackBerry/i.test(navigator.userAgent);
iOS: function() {
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
Windows: function() {
return /IEMobile/i.test(navigator.userAgent);
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
// Nodejs版本
var ua = request.headers['user-agent'],
if (/mobile/i.test(ua))
$.Mobile =
if (/like Mac OS X/.test(ua)) {
$.iOS = /CPU( iPhone)? OS ([0-9\._]+) like Mac OS X/.exec(ua)[2].replace(/_/g, '.');
$.iPhone = /iPhone/.test(ua);
$.iPad = /iPad/.test(ua);
if (/Android/.test(ua))
$.Android = /Android ([0-9\.]+)[\);]/.exec(ua)[1];
if (/webOS\//.test(ua))
$.webOS = /webOS\/([0-9\.]+)[\);]/.exec(ua)[1];
if (/(Intel|PPC) Mac OS X/.test(ua))
$.Mac = /(Intel|PPC) Mac OS X ?([0-9\._]*)[\)\;]/.exec(ua)[2].replace(/_/g, '.') ||
if (/Windows NT/.test(ua))
$.Windows = /Windows NT ([0-9\._]+)[\);]/.exec(ua)[1];
浏览: 2865347 次
来自: 上海
dddddddddddddddd
88350bcf69dcfbda7f8a76a589d9054 ...
这个结论有木有权威的依据?
sxx, bucunzai kuaibukuaile, jia ...
这不是邮编,这是区号
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'o 换工作是一件经过深思熟虑的严肃事情
o 频繁换工作是 loser 做的事情
o 公司应该提供给员工尽可能好的条件
o 这里不欢迎苦大仇深的公司
o 原则上这里不欢迎猎头发帖,除非是懂技术的猎头
o 如果你自己从来没有从期权上赚过钱,就不要在招聘时强调期权
o 招聘时请尽量给出薪酬范围
o 求职时请附上自己的薪酬要求
o 说话前经过足够的思考是好习惯
o 上传一个有意义的头像会更体现你们公司的品牌和诚意
o 请不要在 1 天的时间内在酷工作节点发布超过 3 个主题
o 在不同节点下发布内容相同的主题这种行为不科学
[上海]支付宝上分求贤若渴,ios,android,java,C++,前端 及 测试 职位总有一个适合你 [待遇你懂的!]
11:17:14 +08:00 · 4722 次点击
阿里快上市,赶在上市前入职,是个明智的选择,前段时间支付宝的股权结构分配的消息,相信你早有听说,这么好的机会还犹豫什么呢,好机会真的不等人。来了,你做的不是平平凡凡的普通工作,而是担负真正要改变世界,促进生产力发展和人类进步的重任。只要你够牛,钱永远不是问题。简历投递通道 yi.han [at] (鉴于 目前职位缺口依然存在,在v2ex收到的简历质量普遍较高,所以重发一贴,广招英才,给更多的寻求工作的同仁们更多机会~)职位信息如下:招聘官网链接:http://job.alibaba.com/zhaopin/jobDetail.php?refNo=PY002938职位名称:高级Android开发工程师(国内事业群.技术)招聘人数:不限部门:小微金服-国内事业群-技术部工作地点:上海发布日期:招聘类型:社会招聘职能类别:技术类失效日期:工作年限:3年以上学历要求:本科岗位要求:1. 至少1年相关工作经验;2. 有扎实的C++和Java语言基础;3. 熟悉Android开发技术,包括UI. 网络等方面;4. 熟悉Android开发工具和相关开发测试工具的使用;5. 学习能力强,有创造性思维能力;6. 有较强分析和解决问题的能力;7. 具有较强逻辑思维能力和表达能力;8. 对移动产品有浓厚兴趣。岗位描述:1. 根据支付宝业务产品需求开发相关的移动产品;2. 学习和研究新技术以满足产品的需求;3. 根据开发过程中的体验对产品提出改进建议。特殊说明:---------------------------------------------------------招聘官网链接:http://job.alibaba.com/zhaopin/jobDetail.php?refNo=PY002940职位名称:高级Java开发工程师(国内事业群.技术)招聘人数:不限部门:小微金服-国内事业群-技术部工作地点:上海发布日期:招聘类型:社会招聘职能类别:技术类失效日期:工作年限:3年以上学历要求:本科岗位要求:1.计算机相关专业,本科及以上学历; 2.三年以上java及WEB应用软件开发经验,一年以上系统设计经验,并熟知软件开发流程;3. 精通jsp,servlet,java bean,JMS,EJB,Jdbc,Flex开发,或者对相关的工具. 类库以及框架非常熟悉,如 Velocity,Spring,Hibernate,iBatis,OSGI等,对SOA的模式有较深的理解,对虚拟机. 以及Linux下的开发环境有 较深厚的开发经验;4.熟练使用oracle. sqlserver. mysql等常用的数据库系统,对数据库有较强的设计能力,同时对数据库连接池的使用,线程池技术等较为熟悉者优先考虑;5.熟悉maven项目配置管理工具,熟悉tomcat. jboss等应用服务器,同时对在高并发处理情况下的负载调优有相关经验者优先考虑;6.精通面向对象分析和设计技术,包括设计模式. UML建模等;7.熟悉网络编程,具有设计和开发对外API接口经验和能力,同时具备跨平台的API规范设计以及API高效调用设计能力者优先考虑;8.具有良好的沟通. 团队协作. 计划和创新的能力;9.具有电子商务. 金融行业. 银行业. 航空业经验背景的人优先。 岗位描述:工作地点:上海、杭州1.独立完成小型项目的系统分析. 设计,并主导完成详细设计和编码的任务,确保项目的进度和质量;2.能够在团队中完成Code Review的任务,确保相关代码的有效性和正确性,并能够通过Code Review提供相关性能以及安全的建议;3.独立完成部分较小规模系统的系统分析文档和详细设计文档的撰写;4.能够有效地对新人或普通开发工程师进行辅导,帮助其快速成长;5.维护和升级现有软件产品和系统,快速定位并修复现有软件缺陷。 特殊说明:工作地点:上海、杭州---------------------------------------------------------招聘官网链接:http://job.alibaba.com/zhaopin/jobDetail.php?refNo=PY003023职位名称:高级前端工程师(国内事业群.技术)招聘人数:不限部门:小微金服-国内事业群-技术部-前端技术部工作地点:上海发布日期:招聘类型:社会招聘职能类别:技术类失效日期:工作年限:不限学历要求:不限岗位要求:1. 了解典型的Server/Client/Browser架构;2. 精通Javascript、AJAX、HTML、CSS等技术;3. 成功开发过中大型Web应用程序,良好的UI交互实现能力;4.了解一门服务器编程语言如Java等;5. 善于学习及了解新技术如HTML5,Mobile App等;6. 熟悉面向对象开发概念,具有学习和掌握新技术能力;7. 熟悉各种浏览器平台的特性,能够很好地解决兼容问题;8. 3年以上Web应用开发经验。具备NativeAPP研发经验者优先。岗位描述:1. 与设计师、产品工程师紧密工作在一起,负责产出高质量的产品前端层;2. 参与多种平台的应用开发,包括Web及Mobile等产品,负责前端交互的实现;3. 组织团队学习研究新的技术,并能迅速转化到潜在项目中;4. 能充分理解项目需求和设计需求,具有一定研发精神,能解决各种未知问题;5. 与团队成员分享经验和新技术,帮助团队成长。特殊说明:---------------------------------------------------------招聘官网链接:http://job.alibaba.com/zhaopin/jobDetail.php?refNo=PY003050职位名称:高级IOS开发工程师(国内事业群.技术)招聘人数:不限部门:小微金服-国内事业群-技术部工作地点:上海发布日期:招聘类型:社会招聘职能类别:技术类失效日期:工作年限:3年以上学历要求:本科岗位要求:1. 本科或以上学历,计算机软件、通讯相关专业优先,至少1年以上的iOS项目开发经验; 2. 熟练掌握Objective-C语言,C/C++ 语言;3. 熟悉Cocoa开发框架,包括UI、网络等方面; 4. 熟悉IOS开发工具和相关开发测试工具的使用; 5. 掌握常用的数据结构与常用算法; 6. 较好的逻辑思维分析和表达和沟通能力,要有一定的自学能力,较强的团队协作意识。岗位描述:1. 负责基于IOS移动平台开发,包括iPad和iPhone,iPod touch;2. 参与团队技术研究和创新。特殊说明:---------------------------------------------------------招聘官网链接:http://job.alibaba.com/zhaopin/jobDetail.php?refNo=PY003051职位名称:高级测试工程师(国内事业群.技术)招聘人数:不限部门:小微金服-国内事业群-技术部工作地点:上海发布日期:招聘类型:社会招聘职能类别:技术类失效日期:工作年限:3年以上学历要求:本科岗位要求:1. 良好的计算机专业基础(数据结构, 算法, 编程语言, 数据库等);2. 熟悉软件工程,熟悉软件测试一般方法和流程;3. 性格开朗乐观,责任心强,积极主动,善于沟通,具有团队精神;4. 具有较强的文档编写能力、较强的学习能力和沟通能力;5. 逻辑能力强、思维活跃,接受新事物能力强;6. 具有WEB应用测试经验,熟悉常用的测试工具和Bug管理跟踪软件,版本控制软件;7. 熟悉Linux环境和操作和熟悉数据库Oracle或者Mysql操作;8. 有一定开发经验优先考虑,有自动化测试经验优先;9. 至少2年以上软件开发和测试工作经验。岗位描述:1. 参与软件项目的需求分析,关注项目需求的可测性和设计的合理性;2. 根据需求进行测试设计及测试用例的编写;3. 执行测试用例并进行bug的跟踪;4. 根据测试结果完成测试报告;5. 深入理解系统内部的工作原理,从测试的角度提供优化意见;6. 开发工作中需要的测试工具;7. 根据产品需求和产品设计, 编写功能测试设计和用例, 开发自动化测试用例脚本;8. 根据产品需求和设计, 编写性能测试设计和用例,开发性能测试脚本,并执行性能测试。特殊说明:---------------------------------------------------------招聘官网链接:http://job.alibaba.com/zhaopin/jobDetail.php?refNo=PY003087职位名称:测试专家招聘人数:1部门:小微金服-国内事业群-技术部工作地点:上海发布日期:招聘类型:社会招聘职能类别:技术类失效日期:工作年限:5年以上学历要求:本科岗位要求:1. 计算机相关专业,良好的专业基础(数据结构, 算法, 编程语言, 数据库等);对软件工程理论和实践均有深刻理解;2. 5年以上软件开发和测试工作经验;3. 具备丰富的大型复杂系统软件开发和测试经验;4. 有较强的分析设计能力,测试框架研发和方案整合能力;5. 精通性能测试. 自动化测试. 安全测试及白盒测试领域之一;6. 熟悉开源工具框架及相关扩展应用;7. 熟悉Linux操作系统,熟悉Oracle或者Mysql等;熟悉网络协议和网络环境的应用;8. 逻辑能力强. 思维活跃,接受新事物能力强;9. 责任心强,积极主动,善于沟通,良好的团队合作能力。岗位描述:1. 全面把握产品的功能及非功能需求,设计有效的测试策略;2. 参与全站系统架构改造升级建设,进行风险评估,解决可测性问题及保障系统稳定性;3. 规划和设计符合产品特点的测试平台,优化产品研发测试过程;4. 负责研发特定的测试技术,提升整体测试效率和质量;5. 领导公司测试技术发展方向, 提高测试团队的技术影响力;6. 测试领域新技术. 方法的研究. 应用与推广, 提升行业影响力。特殊说明:---------------------------------------------------------招聘官网链接:http://job.alibaba.com/zhaopin/jobDetail.php?refNo=PY003172职位名称:C++ 高级开发工程师招聘人数:2部门:小微金服-国内事业群-技术部工作地点:上海发布日期:招聘类型:社会招聘职能类别:技术类失效日期:工作年限:3年以上学历要求:本科岗位要求:1. 计算机或相近专业, 大学本科及以上学历, 三年以上计算机相关工作经验;2. 精通C/C++语言编程, 熟悉多线程模型编程,高性能网络编程;3. 掌握各类常用数据结构和相关算法;4. 良好的学习和沟通能力,责任心强,能在压力下独立解决问题;5. 有钻研精神,对技术、大数据充满热情,有团队合作精神。岗位描述:1. 设计高可靠、高性能的现场收单产品;2. 负责现场收单Windows SDK程序设计和开发。特殊说明:---------------------------------------------------------
第 1 条附言 &·&
10:45:58 +08:00
感谢 几位 应届生的简历投递,但14年毕业的应届生,不在此次范围内,也无法进行安排招聘流程,请应届生童鞋走 阿里集团的 应届生招聘,此次招聘是面向社招。
28 回复 &| &直到
08:00:00 +08:00
& & 11:21:49 +08:00
现在进去还给期权?
不给期权上市对员工有毛意义~
& & 11:28:52 +08:00
@ p6及以上入职都有!年奖继续有!
& & 11:38:34 +08:00
iOS 的3年工作年限是必须的?
& & 11:50:21 +08:00
看来LZ裂变了个HR出来了
& & 11:58:31 +08:00
貌似支付宝不打包进上市公司的,啊里上不上市,跟支付宝有个毛关系?难度上市了,就会一点股权给不是上市公司的人?
& & 12:11:21 +08:00
我想来吐槽如果有人被招进去了也要 100 好友么... 2333333
& & 12:28:26 +08:00
@ 不一定,看能力和经验
& & 12:29:46 +08:00
@ 股权都是集团共享的,不在上市内也是一视同仁的
& & 12:30:00 +08:00
@ 必需! XD
& & 13:00:33 +08:00
真是丧心病狂啊...
& & 13:02:46 +08:00
前端工作年限不限, 学历不限? 这个瞧不起前端么?
& & 13:07:57 +08:00
噢我知道为啥了...
跟腾讯 alloy team 对着干么?
[云云无情,腾腾有爱]
如果你没有100个“往来”好友,那就来腾讯领红包吧!红包精彩,腾讯更精彩!
& & 13:41:52 +08:00
想转测试 要求好高 cry
& & 13:49:03 +08:00
@ 学历都是浮云,能力决定一切
& & 13:49:54 +08:00
加 100 好友的能力么... 233
& & 19:01:19 +08:00
北京招IOS吗?最近刚离职
& & 20:13:05 +08:00
@ 来上海吧,会有机会转岗过去的
& & 22:31:10 +08:00
传说支付宝现在都996了?这些职位都是这样的工作强度么,朝九晚九一周六天?
& & 10:46:42 +08:00
@ 加班这种事从来都是按个人意愿
& & 11:26:36 +08:00
15年毕业的默默顶一记!阿里无线最近好辛苦呀
& & 12:01:41 +08:00
@ 听杭州支付宝的朋友说的,阿里无线最近很忙,工作强度比较大。所以只是想了解一下这些职位是否是无线部门的
& & 13:22:52 +08:00
顶一下,继续有效
& & 14:46:52 +08:00
@ 测试年限不够怎么办。。
& & 20:50:55 +08:00 via iPhone
@ 简历投了,不知道后续是啥流程啊
& & 11:58:03 +08:00
@ 正常招聘流程,简历先评估 再电面,后面试
& & 11:58:27 +08:00
@ 能力过关即可
& & 13:41:33 +08:00
& & 11:12:00 +08:00 via iPhone
问下发offer了没?
& · & 1566 人在线 & 最高记录 3541 & · &
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.0 · 72ms · UTC 16:07 · PVG 00:07 · LAX 08:07 · JFK 11:07? Do have faith in what you're doing.分享将iOS游戏移植到Android平台的注意要点
发布时间: 18:00:03
Tags:,,,,,
作者:Charilaos Kalogirou
当你为全世界的iPhone和iPad用户推出基于C/C++的iOS游戏时,你怎么忍心让忠实的Android用户无法享受同样的乐趣?我不能,所以我得把《Pop Corny》移植到Android平台。这是一次有趣的经历,让我受益匪浅,所以我要把我的心得体会分享给读者。
pop corny(from harryballs.com)
首先,如果你安于xcode、苹果生态圈的舒适开发环境,现在准备飞向那片叫作Android的大陆,那么,请准备迎接困难和挑战吧,因为Android提供的工具并不那么合理,且基本上没有文件编制。
NDK(开发Android的本地应用的工具链和类库)和SDK(软件开发工具包)没有关系。显然,为了使原生代码支持Android平台,谷歌已经很努力了,但我们开发原生代码还是不如用Java来得便利。
生成工具和进程非常重要。谷歌给NDK的开发者提供的工具,与构建Android平台的工具相同,这里的工具我指的是一套壳脚本和生成文件。
为了生成你的项目,你要做的是编写生成文件部分,这部分包括由NDK提供的主要生成文件。这使用户的学习难度增大,一开始就可能吓倒一些人。然而,当你掌握它以后,你就会觉得还不错,之后构建你的自定义生成文件时,你可能会觉得更好了。
最后,你建成的是一个动态链接库,Dalvic可以用JNI(Java的本地界面)装载它。对啊,你的游戏仍然是调用库的Dalvic Java VM进程。
混合Java和本地代码
所以你不能全完摆脱Java。你的代码必须与之兼容,这其实正是你想要的,因为几乎所有Android应用程序界面(API)仍然只用Java编写。另外,你可能想使用的大多数Android库也是用Java编写的。例如,如果你想采用Openfeint的排行榜和成就功能,使用Flurry分析工具,你就必须与Java打交道。
这是用Java Native Interface (JNI)完成的。JNI使在VM中运行的Java代码可以被用C/C++编写的本地代码调出和调回。以下是代码如何从本地代码中调出Dashboard.open() 的例子:
jclass cls = javaEnv-&FindClass(“com/openfeint/api/ui/Dashboard”);
jmethodID open = javaEnv-&GetStaticMethodID(cls, “open”, “()V”);
javaEnv-&CallStaticVoidMethod(cls, open);
以上代码唯一的问题是”()V”, 它是类函数的内部类型的署名。这是Java VM描述参数和类函数返回值的方法。
这种语法很容易出错,我建议你始终使用”javap -s myclass”指令,它将所有类函数与它们的署名一同输出。从那里复制和粘贴。记住,如果你拼错了一个署名,你就只能在运行时发现。
即使最新版的NDK允许你用全本地代码写一个活动,我仍然会按老方法在Java中写活动,然后从那里调用本地代码。
在Android上,处理触摸输入比在iOS上更复杂一点儿,因为Android设计师认为有一个直接调用一系列“历史”触摸事件的系统比较酷,而不是让你挨个调用。除此之外,其他都是一样的。你只需要确保你用了ACTIONUP和 ACTIONPOINTER_UP事件。
然而,存在于移植细节的许多其他方面的大问题是,这些事件是不同线程的。这可能会使一些iOS开发者感到吃惊,因为他们习惯于让几乎所有事件都发生在主线程循环中。
至少我是很意外,Android对线程非常大方。所以你要根据自己引擎的编码方式来排列事件,然后将它们从相应线程中传送到你的本地代码。
最后,还有按钮,即真正的硬件按钮——触摸。至少是后退键和主按键,要确保它们符合Android用户的操作习惯。
Apple Android(from 2-soft.com)
这是Android让我吃惊的另一点。请做好思想准备——居然没有OpenAL!你一定难以置信,一脸绝望,不敢接受这个事实。
但这就是真相。如果你希望轻松地将基于OpenAL的声音引擎移植到Android,恐怕你要大大地失望了。我认为这跟某些版权有关。所以,你能选择的只有MediaPlayer、SoundPool和OpenSL ES了。前两个是Java API,第三个是本地API。
MediaPlayer基本上是用于播放不需要低延迟的音乐和声音。我本可以用它播放音乐,但我决定尝试OpenSL。我试过OpenSL的引擎的音乐播放部分后,觉得不喜欢它的API。如果我一开始就知道,我就会直接选择非常简单的MediaPlayer。
SoundPool非常适合播放音效。它还帮你解压了声音,在内存中储存未压缩的现成样本。
但它还是有自己的缺陷,在我的测试中,它不能支持超过1MB的效果。SoundPool之后还有一个很糟的历史记录。因为代码的紊乱情况,SoundPool会让所有在第一代双核手机中运行它的应用程序崩溃!最为典型的就是运行vanilla Android版本的三星Galaxy S2。
你能想象吗?在店里,你的游戏运行得好好的,但有一天,让你的游戏崩溃的手机卖出了数百万台!三星在一年之后才解决了这个问题。从那以后,游戏开发者不得不放弃SoundPool,在OpenSL ES上执行相同的功能。我跟你说过了,OpenSL ES并不好玩。
最坏的是,即使是现在,三星发布的更新版本Android不会有这样的问题了,但大多数用户都没有更新操作系统。所以甚至是在上个月,当我发布《Pop Corny》时,大多数三星Galaxy S2的SoundPool还是有漏洞。我决定不放弃SoundPool,在运行有漏洞版本的SoundPool时进行简单的检测,并且完全不播放音效。
谢天谢地,Android确实支持OpenGL!这下没问题了。但你还是要小心Android的多线程特点,这样就没事了(所有GL指令都必须来自GL线程)。
但你必须准备好对付各种Android手机和平板电脑的分辨率。你不再生活在iOS的生态系统中了,所以你要解决的不只是两种高宽比(iPhone和iPad)的问题了。
对于《Pop Corny》,游戏已经支持iPhone和iPad的高宽比了,所以我只让代码接受某个范围的高宽比,之后增加必要的黑条。
screen-sizes(from gamasutra)
例如,某些手机拥有480×854像素的古怪分辨率,不重新设计整个游戏居然就不能解决这一问题。所以,游戏在这些手机上显示的是黑条。
只载入适当的MipMap或更低级的纹理,也非常有用,但这取决于屏幕的分辨率。这会节省宝贵的内存,特别是对于低端设备,因为它们的屏幕分辨率低。
当移植到Android时,你遇到的OpenGL主要问题是,处理活动生命周期。你可能已经知道了,Android上的任何事件都算一个活动。即使是一个小对话框也是一个活动。
问题是,当对话框出现时,它就会中断你的当前活动,并且如果那个活动是你的OpenGL视图,Android就会消除你的OpenGL活动!
这意味着,当对话框消失后,要返回你刚才的活动,你不得不重新载入所有OpenGL的资源。当用户后台运行你的游戏时,或当用户在游戏运行时打电话,相同的问题出现了。
每次都要再次载入所有纹理,这是无论如何也不能接受的。我想了好一阵子才想出解决办法。这可能是因为我没有Android设备做测试,所以我只能依靠低beta测试器反复测试。
无论如何,3.0版的Android最终解决这个问题了。那个版本的GLViewSurface(游戏邦注:GLSurfaceView的作用是使用户能更容易更好地使用OpenGL渲染应用程序)加了一个名为setPreserveEGLContextOnPause(boolean) 的方法,当开启时,它就会保存GL活动。
但你知道在Android生态系统中很少人会升级操作系统。所以我要做的就是,从Android最新资源中获取GLSurfaceView的类,做些调整,然后使用,而不是使用用户手机中的。就这么简单。
然而,即使是那样,许多手机还是丢失了GL活动。结果是,当GPU是Adreno时,无论GPU是否支持多活动,GLSurfaceView都不能保存活动。
好吧,我尝试的所有基于Adreno的设备都可以保存活动,只要移除在GLSurfaceView的资源中的测试,使游戏在活动中断后继续进行。
移植大业的最后一个障碍是,资源管理和载入。使用过iOS的人会很惊讶地发现,当安装程序时,Android居然不会像iOS那样解压程序包。
文件仍将保持.apk状态,但它实际上是一个zip文件。这引发了一连串的问题。你不能只是用自己信任的系统打开文件并读取。你必须打开apk文件,然后挨个寻找你的文件,解压,最后再使用。
对于某些文件,你可以跳过解压部分,即某类构建过程储存未压缩成apk的文件。大多数媒体文件都已经压缩了。如果你使用ant构建,你其实可以在无压缩的列表当中添加更多文件拓展名。
不幸的是,我对Eclipse(游戏邦注:著名的跨平台自由集成开发环境)没办法做同样的事。使用apk的文件描述符、字符补偿和长度(可以从Java资源管理器中获得),可以轻松地载入这些文件(使用常用文件处理功能)。
至于压缩的文件,你却不得不用Java资源管理器完全地载入,然后使用JNI将所有文件数据复制成C语言,这样效率会很低。
所幸的是,继2.3版本之后,谷歌加强了本地资源载入能力。所以如果你的设备只支持2.3或以上版本,你可以忽略以上问题,直接使用本地API。它会帮你解决所有问题。
正如你所见,Android平台有它自己的缺陷。大多数时候是因为NDK还不够成熟。不过,随着新版本的发布,它会越来越完善。当然,Android用户最好能勤快一点地更新版本……
对于以上所有问题,你可能想编译三个不同的CPU:ARM、ARM7和x86。现在仅有一些支持x86的平板电脑,但假以时日,我们还会看到更多这样的平板电脑。
如果你原本是开发iOS游戏,但移植到Android版本时不认真处理的话,字节顺序可能还是会给你带来一些麻烦。但这不是因为字节顺序的不同,而主要是因为会检测它的iOS/OSX特定C语言定义。
有时候会有一点儿麻烦,但努力总会得到回报的。最后,一个全新的世界等着你的游戏去探索。Android用户也非常热情友好,我认为会比iOS用户还更热情得多。所以让Android用户也来玩我们的游戏吧!(本文为游戏邦/gamerboom.com编译,拒绝任何不保留版权的转载,如需转载请联系:游戏邦)
In-depth: Porting your game from iOS to Android
by Charilaos Kalogirou
So you created a C/C++ game for iOS that gives joy to iPhone and iPad gamers from around the world. How can you deny this joy from loyal Android users? I can’t, so I had to port Pop Corny to the Android platform. It was a very interesting experience, full of gain as I say, and I think it would be nice to share some information and knowledge on the subject.
The basics
First of all, if you are feeling comfortable in your xcode environment and are enjoying the feathery wings of mother Apple, get prepared for a rough landing to the Android land. Be prepared to face lots of not-so-streamlined tools, and basically no documentation
The NDK (the toolchain and libraries you need to build native apps on Android) has no relation to the SDK. It is obvious that Google is working hard on bringing native code support to the platform, but we are not at the place where developing native code is as nice as it is with Java.
The first thing that you must get comfortable with are the build tools and process. Google exposes the same tools that are used for building the actual Android platform to the NDK developers, and by tools I mean a set of shell scripts and makefiles.
What you are actually being requested to do in order to build your project is write a makefile part that gets included in the main makefiles provided by the NDK. This causes a steep learning curve at the beginning that might demoralize some. However, when you get the grasp of it, it works fine and it is probably better that rolling out your custom makefiles.
In the end, what you are ultimately building is a dynamically linked library that Dalvic can load with JNI. That is right, your game will still be a Dalvic Java VM process that just calls out to your library.
Mixing Java and native code
So you will not be able to fully escape Java. Your code must get along with it, and this is actually something you want, as almost all of Android API’s are still Java only. Also most libraries for Android that you might want to use are also written in Java. For example, if you want Openfeint for leaderboards and achievements, of Flurry for analytics, you need to talk to Java.
This is accomplished with Java Native Interface (JNI). This interface allows Java code running in the VM to call out, and to be called back, by native code written in C/C++. This is an example of how the code to call out to Dashboard.open() from native code.
jclass cls = javaEnv-&FindClass(“com/openfeint/api/ui/Dashboard”);
jmethodID open = javaEnv-&GetStaticMethodID(cls, “open”, “()V”);
javaEnv-&CallStaticVoidMethod(cls, open);
The only dark point in the above code is the “()V”, which is the internal type signature of the method. This is the way that the Java VM describes the parameters and return value of a method.
The syntax is error prone, and I suggest you always use the “javap -s myclass” command that prints out all the methods along with their signatures. Copy and paste from there. Keep in mind that if you misspell a signature, you will only find out at runtime.g
Even though that the latest versions of the NDK allow you to write an activity in full native code, I went with the traditional way of creating the activity in Java, and then doing the calling out to native code from that.
Handling touch input is slightly more complex on Android than on iOS, as the designers of Android thought it would be cool to have the system pass in an array of “historical” touch events instead of calling you for each. Apart from that, the story is the same. Just make sure you handle both ACTIONUP and ACTIONPOINTER_UP events.
The major issue, however, that also applies to many other aspects of the porting details, is that these events come in on a different thread. This might surprise some iOS developers that are accustomed to almost everything happening on the main thread’s looper.
It did surprise me at least, but it turns out that Android is very generous with threads. So depending on how your engine is coded, you might have to queue up the events, and then pass them to your native code from the thread it expects them.
Finally, there is button — real hardware button — handling. You would want to handle at least the back and home button in the way Android users expect them to work.
This is where the Android platform took me by surprise… Brace yourself… there is no OpenAL! It was one of those things that you can’t believe, and you keep looking desperately, denying the simple truth.
So it is true, if you are hoping to easily port your OpenAL-based sound engine to Android, you are in for a big disappointment. I believe it had to do with some licensing rights or something. The choices you are left with are MediaPlayer, SoundPool and OpenSL ES. The first two are Java APIs while the third is native.
MediaPlayer is basically for playing music and sounds that don’t require low latency. I could have used that for playing music, but I decided to try OpenSL. I implemented the music playing part of the engine on OpenSL and decided that I don’t like the API. If I knew from the beginning, I would go straight for MediaPlayer, which is very straightforward.
The SoundPool class is very well suited for playing sound effects. It also does the sound decompression for you and stores the uncompressed-ready-to-play samples in memory.
It has its drawbacks as it can’t support effects that are bigger that 1MB in most of my test cases. The SoundPool class also has a bad history behind it. Due to a race condition in the code, SoundPool caused every app that used it on the first dual core phones to crash! Mainly the Samsung Galaxy S2 with the vanilla Android version.
Can you imagine that? You have your nice game running on the store, and one day a company releases a phone that causes your game to crash… and sells millions of it! The fix from Samsung came a year later. Until then, game developers had to drop SoundPool and probably implement the same functionality in OpenSL ES — which I tell you is not fun.
The worst part is that even now that Samsung released newer versions of Android that don’t have the problem, most of the users don’t upgrade. So even last month, when I released Pop Corny, most S2s had a buggy SoundPool. I made the decision not to drop SoundPool and simply detect when running on a buggy version and don’t play sound effects at all.
Thank god Android does support OpenGL! You will have no problems here. Just be a little careful with the multi-threaded nature of Android and you will be okay (all GL commands must come from the GL thread).
But you must be prepared for the variety of resolutions that Android phones and tablets have. You are no longer in the iOS ecosystem, where you can get away with just two aspect ratios (iPhone and iPad).
For Pop Corny, the game already supported the aspect ratios of iPhone and iPad, so I just generalized and made the code accept a certain range of aspect ratios, and after that add black bars as necessary.
For example, the exotic resolution of 480×854 pixels on some phones is so extreme that it can’t be handled without redesigning the whole game. Therefore it gets black bars.
It will also be useful to only load the appropriate texture mipmap and below, depending on the screen resolution. This will save precious memory especially on the low-end devices that usually come with the low resolution displays.
The major problem that you are going to face with OpenGL when porting to Android is dealing with the activity life cycle. As you probably already know, everything on Android is an activity. Even a small dialog box that you will bring up is an activity.
The problem is that when the dialog comes up, it pauses your current activity and if that activity was your OpenGL view, Android will trash your OpenGL context!
What that means is that when the dialog will go away, to get back to rendering you will have to reload every resource that OpenGL had. The same applies for when the user puts your application in the background, or when the user takes a call mid game.
Loading all your textures again, whenever something like that happens, is unacceptable. This one took me a while to sort out. Possibly due to the fact that I had no actual Android device to test on and I was relaying on the slow beta tester round trip.
Anyhow, it turns out that this was fixed on version 3.0 of Android. The GLViewSurface of that version adds a method named setPreserveEGLContextOnPause(boolean) that when set to true, it tries to preserve the GL context.
But as you knownvery few people upgrade on the Android ecosystem. So what I did was take the GLSurfaceView class from the latest sources of Android, make some changes, and use that instead of the one in the user’s phone. Simple as that.
However, even with that, many phones were losing the GL context. It turns out that the GLSurfaceView did not preserve the context in the case the GPU was an Adreno regardless of whether the GPU supported multiple contexts.
Well, all Adreno-based devices I tried can preserve the context, and simply removing that test in GLViewSurface’s source allows the game to continue instantly after an activity pause. Case closed.
The final thorn in the porting endeavor was the asset management and loading. Those that come from iOS will be surprised to find out that Android does not decompress the application bundle when installing an application, like iOS does.
The files will remain in the .apk file, which is essentially a zip file. This causes a number of problems. You can’t just use your trusted system calls to open a file and read it. You have to open the apk file and poke in it, find your file, decompress it, and then use it.
For some files you can skip the decompression part. There are some kinds of files that the build process stores uncompressed in the apk. Mostly media files that are already compressed. If you use ant for building, you can actually add more file extensions to the no-compression list.
Unfortunately, I didn’t manage to find a way to do it with Eclipse. These files can be loaded easily (with the usual file manipulation functions) using the file descriptor of the apk, an offset, and a length that you can get from the Java AssetManager.
In the case of a compressed file, however, you will have to load it completely in Java using the asset manager, and copy the whole file data over to C using JNI, which is inefficient.
Thankfully, Google added native asset loading capabilities after version 2.3. So if you are only supporting 2.3 and up, you can forget all the above and use the native API directly. It does all the work for you.
Closing words
As you can see, the Android platform has its quirks. Most of the time due to the NDK still being too young. It is getting better, though, with every new version. If only Android users were quick to upgrade to the latest version…
To all of the above, add that you probably want to compile for three different CPUs: ARM, ARM7 and x86. That’s right, x86. There are quite a few tablets out there that are based on x86 right now, and we are probably going to see even more with time.
Endianess might also give you some trouble if you weren’t so careful with it when originally developing the game for iOS. Not because of actual differences in the endianess, but mainly from depending on iOS/OSX specific C defines for detecting it.
It might be a little cumbersome at times, but the effort really pays off. In the end, you have a completely new world for your game to explore. And the Android users are also very welcome and warm. A lot more than iOS users, I think. So let’s give them our games!
Good luck!()
CopyRight Since 2010 GamerBoom All rights reserved &&闽ICP备&号-1}

我要回帖

更多关于 h5判断ios还是android 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信