polish builder 功能二

上一篇文章,我们大致讲了polish的一个基本应用,但我们手头上有同一个游戏不同版本的代码的时候,我们就开始利用polish进行整合,那么在利用polish之前,我们必须把环境搭配好,接下来简单的谈谈polish环境的搭建。
1、eclipse me+jdk+wtk这是开发环境,一般移动百宝箱需要我们用wtk1.0.4,而一般我们开发可以用更高的版本wtk2.2.
2、ant工具(ant是一个基于JAVA的自动化脚本引擎,脚本格式为XML。除了做JAVA编译相关任务外,ANT还可以通过插件实现很多应用的调用。)
3、polish安装文件
4、build.xml文件
对于第一条,我想这样的文章已经很多了,我就不说了。关于ant工具,大家可以去下ant的免安装包,解压缩路径假如是E:/ant/,那么把E:/ant/bin;添加到系统环境变量中的path中就可以了。这个时候你打开cmd,敲入ant后如果提示:
Warning: JAVA_HOME environment variable is not set.
If build fails because sun.* classes could not be found
you will need to set the JAVA_HOME environment variable
to the installation directory of java.

Buildfile: build.xml does not exist!
Build failed
则说明安装成功,警告没有可供解析的build.xml文件,这个工具到底用来干嘛的,等我们最后分析完build.xml的时候,大家就知道了。
polish的下载安装也很简单,大家可以搜索一下,安装就可以了,笔者的安装路径是E:/JAVA/J2ME-Polish。
接下来就是定制自己的build.xml了。笔记给出一个简单例子,并简单给出解释,希望对大家有所帮助:
<project
name="KalaPolish" ------------------------------------------>你的项目名称
default="j2mepolish">
<property file="${user.name}.properties" />
<property name="polish.home" location="E:/JAVA/J2ME-Polish" />--------------------------->你的polish安装路径
<property name="wtk.home" location="E:/JAVA/WTK22" />--------------------------->你的wtk安装路径
<property file="${polish.home}/global.properties" />

<!-- Definition of the J2ME Polish task:-->
<taskdef name="j2mepolish"
classname="de.enough.polish.ant.PolishTask"
classpath="${polish.home}/import/enough-j2mepolish-build.jar:${polish.home}/import/jdom.jar:${polish.home}/import/proguard.jar:${polish.home}/yguard-lib.jar:${wtk.home}/wtklib/kenv.zip"/>



<!-- build targets, each target can be called via "ant [name]",
e.g. "ant clean", "ant test j2mepolish" or just "ant" for calling the default-target -->

<target name="setdeploy"
description="Call this target first to set the OTA download-URL, e.g. ant setdeploy j2mepolish"
>
<property name="deploy-url" value="http://www.company.com/download/" />
</target>

<target name="enableDebug"
description="Call this target first to skip the obfuscation step, call the emulator and start the debugger, e.g. ant enableDebug j2mepolish"
>
<property name="debug" value="true" />
</target>


<target name="test"
description="Call this target first to skip the obfuscation step and call the emulator, e.g. ant test j2mepolish"
>
<property name="test" value="true" />
<property name="dir.work" value="build/test" />
</target>
<target name="init">
<property name="test" value="false" />
<property name="dir.work" value="build/real" />
<property name="deploy-url" value="" />
</target>
<!-- In this target the J2ME Polish task is used. -->
<!-- 此任务分3部分: -->
<!-- 1. The info-section 定义一般信息 -->
<!-- 2. The deviceRequirements-section 定义适配的机型 -->
<!-- 3. The build-section 定义build过程 -->
<!-- depends分别为test或者init用于切换是否处于测试阶段. -->
<target name="j2mepolish"
depends="init"
description="这是build过程的控制部分."
>
<j2mepolish>

<info
license="GPL"
name="杀手"--------------------------->MIDlet-Name
version="1.0.0"--------------------------->项目版本
vendorName="Air Long(C)"--------------------------->项目供应商
icon="/icon.png"--------------------------->项目图标
jarName="Kala${polish.Name}.jar"
------>jar的名字,注意因为我们会同时打很多不同的版本,${polish.Name}来区分,“Kala”你可以自己定义
copyright="Copyright 2007 Air Long(C). All rights reserved." --------------------->项目版权
/>
<deviceRequirements >
<requirement name="Identifier" value="Panasonic/X800,Nokia/7610,Nokia/6230i,Nokia/7260,Nokia/6101,Motorola/E398,Motorola/L7,Motorola/C650,Motorola/V600,Samsung/SGH-D508,Sony-Ericsson/K700,Sony-Ericsson/K506"/>--------------------------->需要打包的机型,注意机型必须在polish中有定义。
</deviceRequirements>

<!-- build settings -->
<build
symbols=""
usePolishGui="no"
workDir="${dir.work}"
>
<!-- midlets definition -->
<midlet class="Kala" name="杀手" number="1"/> ----------------->MIDlet class的名字,必须正确
<resources
dir="res"
defaultexcludes="yes"
excludes="readme.txt">
<fileset
dir="res/Sound"
includes="*.bin"
if="polish.Identifier == Nokia/7210"
/>---------------------------><fileset />内定义了一些具体的资源文件的应用,比如这里如果打包时候判断是Nokia/7210,那么就自动包含res/Sound文件下的*.bin文件。*为通配符,如果包含全部文件,那就是*.*。其余的几个大家自己分析一下就知道怎么用了。
<fileset
dir="res/Sound"
includes="*.bin"
if="polish.Identifier == Nokia/N-Gage_QD"
/>
<fileset
dir="res/Sound"
includes="*.mid"
if="polish.Identifier == Nokia/7260"
/>
<fileset
dir="res/Sound"
includes="*.mid"
if="polish.Identifier == Motorola/C650"
/>
<fileset
dir="res/Sound"
includes="*.mid"
if="polish.Identifier == Sony-Ericsson/K506"
/>
<!--
<root dir="resources/base/images" />
<root dir="resources/base/sounds" />
<root dir="resources/customization1" if="cfg.customization1" />
<root dir="resources/customization1/images" if="cfg.customization1" />
<root dir="resources/customization1/sounds" if="cfg.customization1" />
<root dir="resources/customization2" if="cfg.customization2" />
<root dir="resources/customization2/images" if="cfg.customization2" />
<root dir="resources/customization2/sounds" if="cfg.customization2" />
add the localization element for created localized
versions of your application:
<localization>
<locale name="en_US" />
<locale name="de_DE" encoding="utf-8" unless="test" />
</localization>
-->
</resources>

<!--midlet class="MenuMidlet" name="Example" /-->
<!-- project-wide variables - used for preprocessing. -->
<!-- You can set localized variables in the resources/messages.txt files as well. -->
<!-- Here you can set the dir attribute to "resources2" for an alternative design. -->
<!--

-->
<!-- obfuscator settings: do not obfuscate when the test-property is true -->
<obfuscator name="ProGuard" useDefaultPackage="false" unless="test" >
----------->混淆器设置,我们这里用ProGuard,wtk2.2下面的一个混淆器
<!--
You can set additional parameters here, e.g.:
<parameter name="optimize" value="false" />
-->
</obfuscator>
<!-- log settings: only use debug setting when the test-property is true -->
<debug if="test" showLogOnError="true" verbose="true" level="error">
<filter pattern="de.enough.polish.example.*" level="debug" />
<filter pattern="de.enough.polish.ui.*" level="warn" />
<!-- example for writing log entries to the Recordstore Management System:
<handler name="rms" />
-->
</debug>
<!-- user defined JAD attributes can also be used: -->
<jad>
<attribute name="SMS_NUM" value="1065816730107" />---------->这里定义了jad里面的信息
<attribute name="SMS_GAMEID" value="02" />
<attribute name="SMS_CHANNELID" value="07" />
</jad>
</build>
<!-- execution of emulator(s) -->
<emulator
wait="true"
securityDomain="trusted"
enableProfiler="true"
enableMemoryMonitor="true"
enableNetworkMonitor="true"
if="debug"
>
<!-- this is an example for connecting to a debugger - use the ${polish.debug.port} Ant property
for getting to know the port of the debugger. In this example the
"connect-debugger" target is also required.
-->
<!--
<debugger name="antcall" target="connect-debugger" port="6001" />
-->
</emulator>

<emulator
wait="true"
trace="none"
securityDomain="trusted"
enableProfiler="false"
enableMemoryMonitor="false"
enableNetworkMonitor="false"
if="test and not debug"
>
</emulator>
</j2mepolish>
</target>

<target
name="emulator"
depends="test,j2mepolish"
description="invokes the emulator"
>
</target>

<target name="clean"
description="allows a clean build. You should call [ant clean] whenever you made changes to devices.xml, vendors.xml or groups.xml">
<delete dir="build" />
<delete dir="dist" includes="**/*" />----------->clean dist文件夹下面内容功能,可以让用户删除打包文件,这点很有用,有的时候版本更新,必须先clear
</target>

<target
name="cleanbuild"
description="allows a clean build. You should call [ant cleanbuild] whenever you made changes to devices.xml, vendors.xml or groups.xml"
depends="clean, j2mepolish"
/>----------->clean build文件夹下面内容功能,可以让用户删除打包文件,这点很有用,有的时候版本更新,必须先clear

<target name="debug" description="debugs the project" depends="enableDebug, test, j2mepolish" />

<target name="enableCustomization1">
<property name="dir.work" value="build/customization1" />
<property name="cfg.customization1" value="true" />
</target>

<target name="customization1"
description="customizes this project with the settings found in resources/customization1"
depends="enableCustomization1, j2mepolish"
/>

<target name="enableCustomization2">
<property name="dir.work" value="build/customization2" />
<property name="cfg.customization2" value="true" />
</target>

<target name="customization2"
description="customizes this project with the settings found in resources/customization2"
depends="enableCustomization2, j2mepolish"
/>

</project>

以上红色比分,大家修改成自己的就可以了,当然,玩家也可以把打包工具改成wtk1.0.4,注意的是,无论你的打包工具,bin目录下面是否安放了混淆器,都没有关系,因为打包用的混淆器并不是利用wtk里面的混淆器,而是利用了,polish自带的混淆器,具体polish怎么解析这个build文档,大家可以看polish的原文件。有点提醒大家,混淆器的定义的时候,本文中是ProGuard,第一个字母必须大写,否则就出错,想知道问什么的,可以去看polish的代码实现中关于混淆器的代码。
好了,把这个文档放到你的项目目录下面,就可以在eclipse中点击这个build.xml选择ant构建来打包我们的程序了。到这里我们的环境就配置好了。文章写的很粗略,希望对大家有所帮助。文章红色部分为注释,用的时候,必须删除。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值