官方地址:Android Module Porting Guide for 1.8.0.1
专注于为中小企业提供成都网站设计、成都做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业官渡免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
概要
伴随着Titanium Mobile 1.8.0.1的发布, 对于Android的支持改变成支持多个Javascript引擎(V8和Rhino). 这个变化也影响了很多的APIs和第三方modules. 尽管平台的变化, 大多数内部module需要修改的地方也就是简单的方法标记,类型重命名, import 位置。
Manifest变化
开发在Titanium Mobile 1.8.0.1 (或者更高)的第三方modules需要在module manifest中设置一个新的属性:apiversion,值为2.
引用
apiversion: 2
如果你创建一个新的第三方module的话,Titanium Mobile 1.8.0.1会为你的工程自动生成这个属性,但是,如果是已经有的工程的话,你需要手动的添加这个属性,而且确保你重新编译你的module(参照下边的Build变化):
引用
$ ant clean && ant
Build变化
为了能使用新的V8引擎,所有的第三方Module都需要Android NDK来编译V8,可以从Google下载获取最新的NDK::
http://developer.android.com/sdk/ndk/index.html
编译Module之前,需要设置环境变量ANDROID_NDK:
引用
$ export ANDROID_NDK=/path/to/android-ndk
$ ant
当然,你也可以在build.properties中设置android.ndk属性:
引用
android.ndk=/path/to/android-ndk
你还得更新你的build.properties文件(如果使用Eclipse的话也要更新.classpath文件)来引用Titanium Mobile 1.8.0.1 和 API level 8 或者更高::
引用
titanium.sdk=/Library/Application\ Support/Titanium/
titanium.os=osx
titanium.version=1.8.0.1
android.sdk=/usr/android-sdk
titanium.platform=${titanium.sdk}/mobilesdk/${titanium.os}/${titanium.version}/android
android.platform=${android.sdk}/platforms/android-8
google.apis=${android.sdk}/add-ons/addon_google_apis_google_inc_8
基本变化
1. Remove TiContext.
TiContext is being replaced, and any implementation utilizing TiContext will take a performance / stability hit compared to using the desired API's directly.
In most of the places where TiContext is used as an argument, the TiContext argument can be removed entirely or replaced with an Activity reference.
Example:
Js代码
becomes:
Js代码
In the specific case of fromUrl, the following form can also be used:
Js代码
The specific alternative varies based on which API point is being modified, but generally there is a very simple alternative that can be used.
2. Use KrollFunction instead of KrollCallback
KrollFunction has been added, and KrollCallback has been removed; The dual runtime change required a common interface to be defined to replace KrollCallback.
In most cases, a direct replacement of KrollCallback with KrollFunction should suffice.
主要变化
Known compatibility points that need to be changed:
1. Remove KrollInvocation as a method argment.
Example:
Js代码
becomes:
Js代码
2. Remove TiContext from your module constructor. super(TiContext) will no longer work due to the previously mentioned TiContext change. In most if not all cases, simply removing the argument will address the problem.
Example:
Js代码
becomes:
Js代码
3. When replacing KrollCallback with KrollFunction, you need to to pass a KrollObject argument to the call and callAsync methods.
Example:
Js代码
becomes:
Js代码
4. Change getView() on a TiViewProxy to getOrCreateView()/
Example:
Js代码
becomes:
S代码
5. Change TiDrawableReference.fromUrl(proxy.getTiContext(), tiImage) to TiDrawableReference.fromUrl(proxy.getActivity(), tiImage) due to the TiContext change. Same applies to all the "from
Example:
Js代码
becomes:
Js代码
6.
Example:
Js代码
becomes:
Js代码
7. Calling addOnLifeCycleEvent on a module is no longer necessary. Modules are now automatically registered to receive the lifecycle events (onPause, onResume, onStart, onStop, and onDestroy).
8.
Example:
Js代码
9. resolveUrl has been moved to the proxy object.
Example:
Js代码
becomes:
Js代码
10. Change getModuleById to getModuleByName and specify the module name in the module constructor. By default the module cannot be found by calling getModuleByName. You must use the form of super() in the module constructor that allows you to specify the module name.
Example:
Js代码
becomes:
Js代码
11.
Example:
Js代码
becomes:
Js代码 <
12. getContext() on a TiProxy no longer exists because its purpose was to return a TiContext instance. This call should no longer be needed in module implementation once TiContext is no longer being passed in as an argument (the normal use case for this method).
Example:
Js代码
becomes:
Js代码
13. Remove context from TiFileFactory.createTitaniumFile.
Example:
Js代码
becomes:
Js代码
14. getChangeDir is now called on the TiApplication instance.
Example:
Js代码
becomes:
Js代码
15. Overriding the fireEvent method requires a change to the method signature. The argument has changed from a KrollDict class to an Object.
Example:
Js代码
becomes:
Js代码
16.
17. Change usage of KrollDict in method signatures to HashMap. Dictionary values are now passed to methods as HashMap objects. If you need to access any of the KrollDict methods on the HashMap object you can create a KrollDict object from the HashMap object.
Example:
Js代码
becomes:
Js代码
18. runOnUiThread is no longer supported. You must explicitly manage and call your methods on the UI thread where necessary. Specifically, you can use the TiMessenger class to run code on the UI thread.
Example:
Js代码
becomes:
Js代码
当前名称:Titanium中Android模块开发:移植到1.8版本上
浏览路径:http://www.gawzjz.com/qtweb2/news9/6259.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联