BlackBerry - 用于更复杂应用程序的 Ant 构建脚本 [英] BlackBerry - Ant build script for more complex apps

查看:22
本文介绍了BlackBerry - 用于更复杂应用程序的 Ant 构建脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在为我们的生产应用创建 Ant 构建脚本时遇到问题.

我阅读了很多关于 Ant 和 bb-ant-tools.我在 Ant & 上关注了许多 stackoverflow 问题.BB(在下面的评论中引用以链接"问题).我想要一个比通常的Hello World!"更复杂的脚本的帮助.风格的应用程序.我当前的构建过程完全在 Eclipse 中运行,并手动完成.

对于这个问题,我想问如何使用Ant来构建一个使用2个(或更多)不同库项目(也需要构建)的项目,而完全不使用Eclipse?强>

我安装了 Ant、bb-ant-tools.我已经建立 &在设备上部署了一个基本的 Hello World,按照基本示例使用这些工具.我创建了一个构建脚本和一些属性文件;但是当我运行脚本时,最终产品不会在手机上运行(手机 UI 在启动屏幕上冻结).

<小时>

我有 3 个构建脚本,一个用于每个库,一个用于主应用程序.除了项目名称之外,它们是相同的(并且可以在某些时候组合成一个通用的导入脚本).3 个 java 项目中的每一个都有一个与之相关的 Ant 属性文件.我还使用 3 个通用属性文件来定义常量,将信息存储在 JDE & 上.代码签名密码.

  • common.properties:

    jde.home=C:/development/tools/bb-jde/jde4.5/componentssigtool.jde = ${jde.home}sigtool.password = xxx_pass_xxx

  • project.properties(用于 SOAP 库):

    output=MySOAP类型=midlet

  • project.properties(用于内部 SDK 库):

    output=MySDK类型=midlet

更新 1: 自最初发布以来,我已经更新了库属性文件.以前我设置了 type=library(基于 RIM 文档).根据我在这篇文章中概述的研究(BlackBerry - 在自己的项目中使用自己的 JAR 文件),我尝试更改为 type=midlet.这提供了更好的结果(至少在我的平台 BB JDE 5.0 上).

  • project.properties(对于我的应用):

    output=MyApp标题=应用程序类型=cldc供应商=理查德版本=1.0.7描述=一个不错的应用程序图标=图标.png

  • build.xml(除了顶部的名称外,其余都相同,并且两个库脚本没有在 import.jars 中声明文件集):

    <项目名称=MyApp"默认=构建"><!-- 黑莓蚂蚁工具--><property name="bb-ant-tools.home" location="C:/development/tools/bb-ant-tools"/><taskdef resource="bb-ant-defs.xml" classpath="${bb-ant-tools.home}/bb-ant-tools.jar"/><!-- 配置文件--><property file="${common.basedir}/common.properties"/><property prefix="project" file="project.properties"/><!-- 文件夹--><property name="dest.dir" location="build"/><!-- 在库脚本中这是空的--><path id="import.jars"><fileset dir="../MySDK/build" includes="*.jar"/><fileset dir="../MySOAP/build" includes="*.jar"/></路径><path id="src.files"><fileset dir="src" includes="**/*"/><fileset dir="res" includes="**/*"/></路径><!-- 目标行动--><target name="build"depends=""><mkdir dir="${dest.dir}"/><!-- 解决需要应用程序图标位于输出文件夹中的错误--><copy file="${basedir}/res/icon.png" tofile="${dest.dir}/icon.png"/><rapcjdehome="${jde.home}"输出="${project.output}"destdir="${dest.dir}" ><import refid="import.jars"/><src refid="src.files"/><jdp file="${basedir}/project.properties"/></rapc></目标><目标名称=符号"取决于=构建"><sigtoolcodfile="${dest.dir}/${project.output}.cod"jdehome="${sigtool.jde}"密码="${sigtool.password}"/></目标><目标名称=干净"><delete dir="${dest.dir}"/></目标></项目>

更新 2: 我已经更新了 build.xml 自从最初的帖子.目标 build 现在将应用程序图标复制到构建输出文件夹 (${dest.dir}) 以解决 bb-ant-tools/rapc 中的错误.><小时>

所以这是一个非常简单的 Ant 脚本,除了:

  1. 我想知道如何从主程序中触发子构建应用程序构建(我的回答下面处理这个问题).
  2. 最重要的是,由此产生的输出确实不工作.

<小时>

FWIW 我找到了以下流行资源,并将它们列出来,这样就不需要将它们添加为答案,并帮助将来寻找信息的任何人:

解决方案

这是我在多个项目中使用的方案.

<属性名称=buildversion"/><属性名称=描述"/><顺序><mkdir dir="${build.dir}"/><rapc output="${cod.name}_bbminterface" destdir="${build.dir}" verbose="false" quiet="true" nowarn="true"><src><fileset dir="${bbminterface.src.dir}"/></src><import location="./lib/net_rim_bb_qm_platform.jar"/><jdp type="library" title="${app.name}_bbminterface" vendor="my vendor" version="@{buildversion}"><entry title="${app.name}_bbminterface" description=""/></jdp></rapc><rapc output="${cod.name}_bbmimpl" destdir="${build.dir}" verbose="false" quiet="true" nowarn="true"><src><fileset dir="${bbmimpl.src.dir}"/></src><import location="./lib/net_rim_bb_qm_platform.jar"/><import location="${build.dir}/${cod.name}_bbminterface.jar"/><jdp type="library" title="${app.name}_bbmimpl" vendor="my vendor" version="@{buildversion}" runonstartup="true" startuptier="6"><entry title="${app.name}_bbmimpl" description="" runonstartup="true" startuptier="6"/></jdp></rapc><rapc output="${cod.name}" destdir="${build.dir}" verbose="false"><src><fileset dir="${tmpsrc.dir}"/></src><src><fileset dir="${res.dir}"/></src><src><fileset file="${lib.dir}/paymentapi.jar"/></src><import location="./lib/net_rim_bb_qm_platform.jar"/><import location="${build.dir}/${cod.name}_bbminterface.jar"/><jdp type="cldc" title="${app.name}" vendor="my vendor" icon="../res/icon.png" version="@{buildversion}" description="@{description}" startuptier="7"ribbonposition="0"><entry title="${app.name}" icon="../res/icon.png" description="@{description}" runonstartup="true" arguments="boot" systemmodule="true" startuptier="7"ribbonposition="0"/><entry title="${app.name}" icon="../res/icon.png" description="@{description}" arguments="daemon" runonstartup="true" systemmodule="true" startuptier="7"ribbonposition="0"/></jdp></rapc></顺序></宏定义>

这是编译代码.我们正在编译一些库,然后是应用程序,链接刚刚创建的库.

然后签名:

<sigtool codfile="${build.dir}/${cod.name}_bbminterface.cod" password=""/><sigtool codfile="${build.dir}/${cod.name}_bbmimpl.cod" password=""/><sigtool codfile="${build.dir}/${cod.name}.cod" password=""/></目标>

然后上传到我们的 OTA 服务器:

I am having trouble creating an Ant build script for our production apps.

I have been reading a lot about Ant, and bb-ant-tools. I have followed many stackoverflow questions on Ant & BB (referenced below in comments to "link" the questions). I would like help with a script more complex than the usual "Hello World!" style apps. My current build process is run entirely in Eclipse, and done manually.

For this question, I would like to ask how to use Ant to build a project that uses 2 (or more) different library projects (which also need to be built), without using Eclipse at all?

I have Ant, bb-ant-tools installed. I have built & deployed on device a basic Hello World, using these tools following basic examples. I have created a build script, and some property files; but when I run the scripts, the end product does not run on the phone (phone UI freezes on the launch screen).


I have 3 build scripts, one for each library, and one for the main app. These are identical, except for the project name (and could be combined into one common imported script at some point). Each of the 3 java projects has an Ant properties file related to it. I also use 3 common properties files for defining constants, storing info on the JDE & the code signing password.

  • common.properties:

    jde.home=C:/development/tools/bb-jde/jde4.5/components
    sigtool.jde = ${jde.home} 
    sigtool.password = xxx_pass_xxx
    

  • project.properties (for SOAP library):

    output=MySOAP
    type=midlet
    

  • project.properties (for internal SDK library):

    output=MySDK
    type=midlet
    

Update 1: I have updated the library property files since initial post. Previously I set type=library (based on RIM documentation). Based on my research outlined in this post (BlackBerry - use own JAR file in own project), I tried changing to type=midlet. This gives better results (at least on my platform BB JDE 5.0).

  • project.properties (for my app):

    output=MyApp
    title=App
    type=cldc
    vendor=Richard
    version=1.0.7
    description=A nice app
    icon=icon.png
    

  • build.xml (all the same except for the name at the top, and the 2 library scripts do not have filesets declared inside import.jars):

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <project name="MyApp" default="build">
    
        <!-- BLACKBERRY ANT TOOLS -->
        <property name="bb-ant-tools.home" location="C:/development/tools/bb-ant-tools" />
        <taskdef resource="bb-ant-defs.xml" classpath="${bb-ant-tools.home}/bb-ant-tools.jar" />
    
        <!-- CONFIG FILES -->
        <property file="${common.basedir}/common.properties" />
        <property prefix="project" file="project.properties" />
    
        <!-- FOLDERS -->
        <property name="dest.dir" location="build" />
    
        <!-- this is empty in the library scripts -->
        <path id="import.jars">
            <fileset dir="../MySDK/build" includes="*.jar" />
            <fileset dir="../MySOAP/build" includes="*.jar" />
        </path>
    
        <path id="src.files">
            <fileset dir="src" includes="**/*" />
            <fileset dir="res" includes="**/*" />
        </path>
    
        <!-- TARGET ACTIONS -->
    
        <target name="build" depends="">
            <mkdir dir="${dest.dir}" />
    
            <!-- work around a bug requiring app icons to be in the output folder -->
            <copy file="${basedir}/res/icon.png" tofile="${dest.dir}/icon.png" />
    
            <rapc 
                    jdehome="${jde.home}"
                    output="${project.output}" 
                    destdir="${dest.dir}" >
    
                <import refid="import.jars" />
                <src refid="src.files" />
                <jdp file="${basedir}/project.properties" />
            </rapc>
        </target>
    
        <target name="sign" depends="build">
            <sigtool
                    codfile="${dest.dir}/${project.output}.cod" 
                    jdehome="${sigtool.jde}" 
                    password="${sigtool.password}" />
        </target>
    
        <target name="clean">
            <delete dir="${dest.dir}" />
        </target>
    
    </project>
    

Update 2: I have updated the build.xml since the initial post. Target build now copies the app icon into the build output folder (${dest.dir}) to work around a bug in bb-ant-tools / rapc.


So this is a very simple Ant script, except:

  1. I would like to know how to trigger the sub-builds off from the main app build (my answer below deals with that).
  2. The big one, is that the resulting output from this does not work.


FWIW I have found the following popular resources, and list them so that they need not be added as answers, and to help anyone in the future looking for info:

解决方案

This is what I'm using across multiple projects.

<macrodef name="compile">
    <attribute name="buildversion" />
    <attribute name="description" />
    <sequential>
        <mkdir dir="${build.dir}" />

        <rapc output="${cod.name}_bbminterface"  destdir="${build.dir}" verbose="false" quiet="true" nowarn="true">
            <src>
                <fileset dir="${bbminterface.src.dir}"/>
            </src>
            <import location="./lib/net_rim_bb_qm_platform.jar" />
            <jdp type="library" title="${app.name}_bbminterface" vendor="my vendor" version="@{buildversion}">
                <entry title="${app.name}_bbminterface" description=""/>    
            </jdp>
        </rapc>
        <rapc output="${cod.name}_bbmimpl" destdir="${build.dir}" verbose="false" quiet="true" nowarn="true">
            <src>
                <fileset dir="${bbmimpl.src.dir}"/>
            </src>
            <import location="./lib/net_rim_bb_qm_platform.jar" />
            <import location="${build.dir}/${cod.name}_bbminterface.jar" />
            <jdp type="library" title="${app.name}_bbmimpl" vendor="my vendor" version="@{buildversion}" runonstartup="true" startuptier="6">
                <entry title="${app.name}_bbmimpl" description="" runonstartup="true" startuptier="6"/> 
            </jdp>
        </rapc>

        <rapc output="${cod.name}" destdir="${build.dir}" verbose="false">

            <src>
                <fileset dir="${tmpsrc.dir}" />
            </src>
            <src>
                <fileset dir="${res.dir}" />
            </src>
            <src>

                <fileset file="${lib.dir}/paymentapi.jar" />
            </src>
            <import location="./lib/net_rim_bb_qm_platform.jar" />
            <import location="${build.dir}/${cod.name}_bbminterface.jar"/>

            <jdp type="cldc" title="${app.name}" vendor="my vendor" icon="../res/icon.png" version="@{buildversion}" description="@{description}" startuptier="7" ribbonposition="0">
                <entry title="${app.name}" icon="../res/icon.png" description="@{description}" runonstartup="true" arguments="boot" systemmodule="true" startuptier="7" ribbonposition="0" />
                <entry title="${app.name}" icon="../res/icon.png" description="@{description}" arguments="daemon" runonstartup="true" systemmodule="true" startuptier="7" ribbonposition="0" />
            </jdp>
        </rapc>
    </sequential>
</macrodef>

This is the compilation code. We're compiling a few libraries and then the application, linking the just created libraries.

Then for signing:

<target name="sign" description="Sign the cod file">
    <sigtool codfile="${build.dir}/${cod.name}_bbminterface.cod" password=""/>
    <sigtool codfile="${build.dir}/${cod.name}_bbmimpl.cod" password=""/>
    <sigtool codfile="${build.dir}/${cod.name}.cod" password="" />
</target>

And then uploading to our OTA server:

这篇关于BlackBerry - 用于更复杂应用程序的 Ant 构建脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆