構建Android自動編譯持續整合系統

來源:互聯網
上載者:User

因為我們專業,所以我們用Auto Build,所以我們用CI系統。

代碼管理使用SVN,自動編譯使用Ant,而持續整合使用Hudson,作業系統使用Ubuntu10.04。

1. 安裝1.1 安裝JDK

      sudo apt-get install sun-java6-jdk

1.2 安裝Ant

      sudo apt-get install ant-optional

1.3 安裝Hudson

      sudo apt-get upgrade
      wget -O /tmp/key http://hudson-ci.org/debian/hudson-ci.org.key
      sudo apt-key add /tmp/key
      wget -O /tmp/hudson.deb http://hudson-ci.org/latest/debian/hudson.deb
      sudo dpkg --install /tmp/hudson.deb

1.4 安裝Android SDK

      http://androidappdocs.appspot.com/sdk/index.html

2. Project配置 2.1 build.xml

http://androidappdocs.appspot.com/guide/developing/other-ide.html

按照官方的做法,使用自動產生的build檔案就可以了。

<?xml version="1.0" encoding="UTF-8"?>
<project name="test-android">

<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked in in Version
Control Systems. -->
<property file="local.properties" />

<!-- The build.properties file can be created by you and is never touched
by the 'android' tool. This is the place to change some of the default property values
used by the Ant rules.
Here are some properties you may want to change/update:

application.package
the name of your application package as defined in the manifest. Used by the
'uninstall' rule.
source.dir
the name of the source directory. Default is 'src'.
out.dir
the name of the output directory. Default is 'bin'.

Properties related to the SDK location or the project target should be updated
using the 'android' tool with the 'update' action.

This file is an integral part of the build system for your application and
should be checked in in Version Control Systems.

-->
<property file="build.properties" />

<!-- The default.properties file is created and updated by the 'android' tool, as well
as ADT.
This file is an integral part of the build system for your application and
should be checked in in Version Control Systems. -->
<property file="default.properties" />

<!-- Custom Android task to deal with the project target, and import the proper rules.
This requires ant 1.6.0 or above. -->
<path id="android.antlibs">
<pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
<pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
<pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
<pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar" />
<pathelement path="${sdk.dir}/tools/lib/jarutils.jar" />
</path>

<taskdef name="setup" classname="com.android.ant.SetupTask" classpathref="android.antlibs" />

<!-- Execute the Android Setup task that will setup some properties specific to the target,
and import the build rules files.

The rules file is imported from
<SDK>/platforms/<target_platform>/templates/android_rules.xml

To customize some build steps for your project:
- copy the content of the main node <project> from android_rules.xml
- paste it in this build.xml below the <setup /> task.
- disable the import by changing the setup task below to <setup import="false" />

This will ensure that the properties are setup correctly but that your customized
build steps are used.
-->
<setup />

</project>

 

2.2 local.properties

這個設定檔定義了Android SDK的位置
sdk.dir=${tool.android.sdk}
2.3 build.properties

這個檔案裡面定義了App的Package,以及產生App簽名必須用的一些配置。

application.package=test.android
key.store=../test-android.keystore
key.alias=test-android
key.store.password=password
key.alias.password=password

3. Hudson配置3.1 System Configuration

系統配置很簡單,只需要配置JDK、Ant的位置就可以了。

比較有用的還有一項:E-mail Notification,如果你需要在build失敗發送郵件的話,那麼需要配置這一項。

3.2 Job Configuration3.2.1 Source Code Management

1. 選擇Subversion,並且設定好SVN的地址以及使用者名稱、密碼

2. 把Use update和Revert勾選上

3.2.2 Build Triggers

1. 勾選上Build Periodically,然後設定自動Build的時機,這裡文法跟cron的文法是一樣的。

例如:0 2 * * 1-6

2. 勾選上Poll SCM,設定每隔多長時間檢測SVN的變更。

例如:0,15,30,45 9-23 * * 1-5

3.2.3 Build

Step1:刪除上次編譯的檔案

rm –f test-android.keystore
rm –f –R ./test-android/gen
rm –f –R ./test-android/bin

Step2:產生Keystore

http://androidappdocs.appspot.com/guide/publishing/app-signing.html

例如:keytool -genkey -v -alias test-android -keyalg RSA -keysize 2048 -dname 'CN=xxx, OU=xxx, O=xxx, L=xxx, ST=xxx, C=xx' -validity 10000 -keypass password -storepass password -keystore 'test-android.keystore'

Step3:Invoke Ant

設定Targets:release –Dsdk.dir=$your-sdk-dir

例如:release –Dsdk.dir=/home/build/android-sdk-linux

3.2.3 Post-build Actions

1. 勾選上Archive the artifacts,設定Files to archive:test-android/bin/test-android-release.apk

2. 勾選上E-mail Notification,可以設定發送郵件的對象和時機

 

經過以上步驟的設定,大功告成了。

專業就是這麼簡單!!!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.