ページ

2015年5月24日日曜日

Jenkinsと戯れる 3 - CI実施 -

いよいよ今回からCIを実施!!

最終的にはAndroidのプロジェクトをCIするようにできればいいなあ〜。
その為には色々クリアしないといけなさそう><;

以下サイトでAndroid用のエミュレータのプラグインがあるとのこと!!
http://www.atmarkit.co.jp/ait/articles/1205/23/news116.html

実際にJenkinsのプラグインリストから探してみる。






















なんか色々ある。。
とりあえずAndroid Emulator Pluginを入れてみる。
↓再起動せずにインストール























Port Allocator Plugin ?なるものも一緒にインストールされた
調べてみるとポートが重複しないようにしてくれるものらしい。
https://wiki.jenkins-ci.org/display/JENKINS/Port+Allocator+Plugin

Jenkinsの設定でAndroid Emulatorが使えるようになりました^^
























JenkisサーバーにAndroidSDKをインストール

以下サイトを参考にインストールしてみる。
http://qiita.com/usamao/items/93535df778916ee70ad8

↓公式ページからSDKをダウンロード
https://developer.android.com/sdk/index.html#


















/var/lib配下にコピーし、パッケージ一覧を確認。

[vagrant@localhost tools]$ ./android list sdk --all
Refresh Sources:
  Fetching https://dl.google.com/android/repository/addons_list-2.xml
  Validate XML
  Parse XML
  Fetched Add-ons List successfully
  Refresh Sources
  Fetching URL: https://dl.google.com/android/repository/repository-10.xml
  Validate XML: https://dl.google.com/android/repository/repository-10.xml
  Parse XML:    https://dl.google.com/android/repository/repository-10.xml
  Fetching URL: https://dl.google.com/android/repository/addon.xml
  Validate XML: https://dl.google.com/android/repository/addon.xml
  Parse XML:    https://dl.google.com/android/repository/addon.xml
  Fetching URL: https://dl.google.com/android/repository/addon-6.xml
  Validate XML: https://dl.google.com/android/repository/addon-6.xml
  Parse XML:    https://dl.google.com/android/repository/addon-6.xml
  Fetching URL: https://dl-ssl.google.com/glass/gdk/addon.xml
  Validate XML: https://dl-ssl.google.com/glass/gdk/addon.xml
  Parse XML:    https://dl-ssl.google.com/glass/gdk/addon.xml
  Fetching URL: https://dl.google.com/android/repository/extras/intel/addon.xml
  Validate XML: https://dl.google.com/android/repository/extras/intel/addon.xml
  Parse XML:    https://dl.google.com/android/repository/extras/intel/addon.xml
  Fetching URL: https://dl.google.com/android/repository/sys-img/android/sys-img.xml
  Validate XML: https://dl.google.com/android/repository/sys-img/android/sys-img.xml
  Parse XML:    https://dl.google.com/android/repository/sys-img/android/sys-img.xml
  Fetching URL: https://dl.google.com/android/repository/sys-img/android-wear/sys-img.xml
  Validate XML: https://dl.google.com/android/repository/sys-img/android-wear/sys-img.xml
  Parse XML:    https://dl.google.com/android/repository/sys-img/android-wear/sys-img.xml
  Fetching URL: https://dl.google.com/android/repository/sys-img/android-tv/sys-img.xml
  Validate XML: https://dl.google.com/android/repository/sys-img/android-tv/sys-img.xml
  Parse XML:    https://dl.google.com/android/repository/sys-img/android-tv/sys-img.xml
  Fetching URL: https://dl.google.com/android/repository/sys-img/google_apis/sys-img.xml
  Validate XML: https://dl.google.com/android/repository/sys-img/google_apis/sys-img.xml
  Parse XML:    https://dl.google.com/android/repository/sys-img/google_apis/sys-img.xml
  Fetching URL: https://dl.google.com/android/repository/sys-img/x86/addon-x86.xml
  Validate XML: https://dl.google.com/android/repository/sys-img/x86/addon-x86.xml
  Parse XML:    https://dl.google.com/android/repository/sys-img/x86/addon-x86.xml
Packages available for installation or update: 140
   1- Android SDK Tools, revision 24.2
   2- Android SDK Platform-tools, revision 22
   3- Android SDK Build-tools, revision 22.0.1
   4- Android SDK Build-tools, revision 22 (Obsolete)
   5- Android SDK Build-tools, revision 21.1.2
   6- Android SDK Build-tools, revision 21.1.1 (Obsolete)
   7- Android SDK Build-tools, revision 21.1 (Obsolete)
   8- Android SDK Build-tools, revision 21.0.2 (Obsolete)
   9- Android SDK Build-tools, revision 21.0.1 (Obsolete)
  10- Android SDK Build-tools, revision 21 (Obsolete)
  11- Android SDK Build-tools, revision 20
  12- Android SDK Build-tools, revision 19.1
  13- Android SDK Build-tools, revision 19.0.3 (Obsolete)
  14- Android SDK Build-tools, revision 19.0.2 (Obsolete)
  15- Android SDK Build-tools, revision 19.0.1 (Obsolete)
  16- Android SDK Build-tools, revision 19 (Obsolete)
  17- Android SDK Build-tools, revision 18.1.1 (Obsolete)
  18- Android SDK Build-tools, revision 18.1 (Obsolete)
  19- Android SDK Build-tools, revision 18.0.1 (Obsolete)
  20- Android SDK Build-tools, revision 17 (Obsolete)
  21- Documentation for Android SDK, API 22, revision 1
  22- SDK Platform Android 5.1.1, API 22, revision 2
  23- SDK Platform Android 5.0.1, API 21, revision 2
  24- SDK Platform Android 4.4W.2, API 20, revision 2
  25- SDK Platform Android 4.4.2, API 19, revision 4
  26- SDK Platform Android 4.3.1, API 18, revision 3
  27- SDK Platform Android 4.2.2, API 17, revision 3
  28- SDK Platform Android 4.1.2, API 16, revision 5
  29- SDK Platform Android 4.0.3, API 15, revision 5
  30- SDK Platform Android 4.0, API 14, revision 4 (Obsolete)
  31- SDK Platform Android 3.2, API 13, revision 1 (Obsolete)
  32- SDK Platform Android 3.1, API 12, revision 3 (Obsolete)
  33- SDK Platform Android 3.0, API 11, revision 2 (Obsolete)
  34- SDK Platform Android 2.3.3, API 10, revision 2
  35- SDK Platform Android 2.3.1, API 9, revision 2 (Obsolete)
  36- SDK Platform Android 2.2, API 8, revision 3
  37- SDK Platform Android 2.1, API 7, revision 3 (Obsolete)
  38- SDK Platform Android 2.0.1, API 6, revision 1 (Obsolete)
  39- SDK Platform Android 2.0, API 5, revision 1 (Obsolete)
  40- SDK Platform Android 1.6, API 4, revision 3 (Obsolete)
  41- SDK Platform Android 1.5, API 3, revision 4 (Obsolete)
  42- SDK Platform Android 1.1, API 2, revision 1 (Obsolete)
  43- Samples for SDK API 22, revision 5
  44- Samples for SDK API 21, revision 4
  45- Samples for SDK API 20, revision 3
  46- Samples for SDK API 19, revision 6
  47- Samples for SDK API 18, revision 1
  48- Samples for SDK API 17, revision 1
  49- Samples for SDK API 16, revision 1
  50- Samples for SDK API 15, revision 2
  51- Samples for SDK API 14, revision 2 (Obsolete)
  52- Samples for SDK API 13, revision 1 (Obsolete)
  53- Samples for SDK API 12, revision 1 (Obsolete)
  54- Samples for SDK API 11, revision 1 (Obsolete)
  55- Samples for SDK API 10, revision 1
  56- Samples for SDK API 9, revision 1 (Obsolete)
  57- Samples for SDK API 8, revision 1
  58- Samples for SDK API 7, revision 1 (Obsolete)
  59- Android TV ARM EABI v7a System Image, Android API 22, revision 1
  60- Android TV Intel x86 Atom System Image, Android API 22, revision 1
  61- Android Wear ARM EABI v7a System Image, Android API 22, revision 1
  62- Android Wear Intel x86 Atom System Image, Android API 22, revision 1
  63- ARM EABI v7a System Image, Android API 22, revision 1
  64- Intel x86 Atom_64 System Image, Android API 22, revision 1
  65- Intel x86 Atom System Image, Android API 22, revision 1
  66- Android TV ARM EABI v7a System Image, Android API 21, revision 3
  67- Android TV Intel x86 Atom System Image, Android API 21, revision 3
  68- Android Wear ARM EABI v7a System Image, Android API 21, revision 3
  69- Android Wear Intel x86 Atom System Image, Android API 21, revision 3
  70- ARM EABI v7a System Image, Android API 21, revision 3
  71- Intel x86 Atom_64 System Image, Android API 21, revision 3
  72- Intel x86 Atom System Image, Android API 21, revision 3
  73- Android Wear ARM EABI v7a System Image, Android API 20, revision 4
  74- Android Wear Intel x86 Atom System Image, Android API 20, revision 4
  75- ARM EABI v7a System Image, Android API 19, revision 2
  76- Intel x86 Atom System Image, Android API 19, revision 2
  77- ARM EABI v7a System Image, Android API 18, revision 2
  78- Intel x86 Atom System Image, Android API 18, revision 1
  79- ARM EABI v7a System Image, Android API 17, revision 2
  80- Intel x86 Atom System Image, Android API 17, revision 1
  81- MIPS System Image, Android API 17, revision 1
  82- ARM EABI v7a System Image, Android API 16, revision 3
  83- Intel x86 Atom System Image, Android API 16, revision 1
  84- MIPS System Image, Android API 16, revision 4
  85- ARM EABI v7a System Image, Android API 15, revision 2
  86- Intel x86 Atom System Image, Android API 15, revision 1
  87- MIPS System Image, Android API 15, revision 1
  88- ARM EABI v7a System Image, Android API 14, revision 2 (Obsolete)
  89- Intel x86 Atom System Image, Android API 10, revision 2
  90- Google APIs, Android API 22, revision 1
  91- Google APIs, Android API 21, revision 1
  92- Google APIs (x86 System Image), Android API 19, revision 13
  93- Google APIs (ARM System Image), Android API 19, revision 13
  94- Glass Development Kit Preview, Android API 19, revision 11
  95- Google APIs, Android API 18, revision 3
  96- Google APIs, Android API 17, revision 3
  97- Google APIs, Android API 16, revision 3
  98- Google APIs, Android API 15, revision 2
  99- Google APIs, Android API 14, revision 2 (Obsolete)
 100- Google APIs, Android API 13, revision 1 (Obsolete)
 101- Google TV Addon, Android API 13, revision 1 (Obsolete)
 102- Google APIs, Android API 12, revision 1 (Obsolete)
 103- Google TV Addon, Android API 12, revision 2 (Obsolete)
 104- Google APIs, Android API 11, revision 1 (Obsolete)
 105- Google APIs, Android API 10, revision 2
 106- Google APIs, Android API 9, revision 2 (Obsolete)
 107- Google APIs, Android API 8, revision 2
 108- Google APIs, Android API 7, revision 1 (Obsolete)
 109- Google APIs, Android API 6, revision 1 (Obsolete)
 110- Google APIs, Android API 5, revision 1 (Obsolete)
 111- Google APIs, Android API 4, revision 2 (Obsolete)
 112- Google APIs, Android API 3, revision 3 (Obsolete)
 113- Google APIs ARM EABI v7a System Image, Google Inc. API 22, revision 1
 114- Google APIs Intel x86 Atom_64 System Image, Google Inc. API 22, revision 1
 115- Google APIs Intel x86 Atom System Image, Google Inc. API 22, revision 1
 116- Google APIs ARM EABI v7a System Image, Google Inc. API 21, revision 5
 117- Google APIs Intel x86 Atom_64 System Image, Google Inc. API 21, revision 5
 118- Google APIs Intel x86 Atom System Image, Google Inc. API 21, revision 5
 119- Sources for Android SDK, API 22, revision 1
 120- Sources for Android SDK, API 21, revision 1
 121- Sources for Android SDK, API 20, revision 1
 122- Sources for Android SDK, API 19, revision 2
 123- Sources for Android SDK, API 18, revision 1
 124- Sources for Android SDK, API 17, revision 1
 125- Sources for Android SDK, API 16, revision 2
 126- Sources for Android SDK, API 15, revision 2
 127- Sources for Android SDK, API 14, revision 1 (Obsolete)
 128- Android Support Repository, revision 14
 129- Android Support Library, revision 22.1.1
 130- Google AdMob Ads SDK, revision 11 (Obsolete)
 131- Google Analytics App Tracking SDK, revision 3 (Obsolete)
 132- Google Cloud Messaging for Android Library, revision 3 (Obsolete)
 133- Google Play services for Froyo, revision 12 (Obsolete)
 134- Google Play services, revision 24
 135- Google Repository, revision 18
 136- Google Play APK Expansion Library, revision 3
 137- Google Play Billing Library, revision 5
 138- Google Play Licensing Library, revision 2
 139- Android Auto API Simulators, revision 1
 140- Google Web Driver, revision 2

次に必要なパッケージをインストール
  • 必要そうなパッケージは以下
    • Android SDK Build-tools
    • SDK Platform
    • Android Support Repository
    • Android Support Library

[vagrant@localhost tools]$ ./android update sdk -u -a -t 3
[vagrant@localhost tools]$ ./android update sdk -u -a -t 22
[vagrant@localhost tools]$ ./android update sdk -u -a -t 128
[vagrant@localhost tools]$ ./android update sdk -u -a -t 129

環境変数を設定。
とりあえず/etc/profileに記述
export ANDROID_HOME=/var/lib/android-sdk-linux/

テスト用プロジェクトを作成しAntでビルドしてみる。
まずはAntのインストール。

    wget http://www.apache.org/dist/ant/binaries/apache-ant-1.9.4-bin.tar.gz
    tar zxvf apache-ant-1.9.4-bin.tar.gz
    sudo mv apache-ant-1.9.4 /usr/share/ant
    sudo ln -s /usr/share/ant/bin/ant /usr/bin/ant
    sudo vi /etc/profile

↓/etc/profileに追加した内容
export ANDROID_HOME=/var/lib/android-sdk-linux/
export ANT_HOME=/usr/share/ant/
PATH=$PATH:/var/lib/android-sdk-linux/tools/:/usr/share/ant/

テストプロジェクト作成
[vagrant@localhost vagrant]$ android list target
Available Android targets:
----------
id: 1 or "android-22"
     Name: Android 5.1.1
     Type: Platform
     API level: 22
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
 Tag/ABIs : no ABIs.
[vagrant@localhost vagrant]$ android create project --target android-22 --name HelloWorld --activity HelloWorldMainActivity --path HelloWorld --package org.sample.HelloWorld
Created project directory: HelloWorld
Created directory /vagrant/HelloWorld/src/org/sample/HelloWorld
Added file HelloWorld/src/org/sample/HelloWorld/HelloWorldMainActivity.java
Created directory /vagrant/HelloWorld/res
Created directory /vagrant/HelloWorld/bin
Created directory /vagrant/HelloWorld/libs
Created directory /vagrant/HelloWorld/res/values
Added file HelloWorld/res/values/strings.xml
Created directory /vagrant/HelloWorld/res/layout
Added file HelloWorld/res/layout/main.xml
Created directory /vagrant/HelloWorld/res/drawable-xhdpi
Created directory /vagrant/HelloWorld/res/drawable-hdpi
Created directory /vagrant/HelloWorld/res/drawable-mdpi
Created directory /vagrant/HelloWorld/res/drawable-ldpi
Added file HelloWorld/AndroidManifest.xml
Added file HelloWorld/build.xml
Added file HelloWorld/proguard-project.txt

いざビルド!!
[vagrant@localhost HelloWorld]$ ant debug
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/lib/tools.jar
Buildfile: /vagrant/HelloWorld/build.xml

-set-mode-check:

-set-debug-files:

-check-env:

BUILD FAILED
/var/lib/android-sdk-linux/tools/ant/build.xml:396: SDK Platform Tools component is missing. Please install it with the SDK Manager (tools/android)
こけたorz
SDK Managerをインストールしろと。。
とりあえず以下を実行
[vagrant@localhost tools]$ ./android update sdk -u -a -t 3
[vagrant@localhost tools]$ ./android update sdk -u -a -t 22

もう一度ant debugすると・・・
[vagrant@localhost HelloWorld]$ ant debug
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/lib/tools.jar
Buildfile: /vagrant/HelloWorld/build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 24.2.0
 [checkenv] Installed at /var/lib/android-sdk-linux

-setup:
     [echo] Project Name: HelloWorld
  [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 22.0.1
     [echo] Resolving Build Target for HelloWorld...
[gettarget] Project Target:   Android 5.1.1
[gettarget] API level:        22
[gettarget] WARNING: No minSdkVersion value set. Application will install on all Android versions.
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /vagrant/HelloWorld/bin/rsObj
    [mkdir] Created dir: /vagrant/HelloWorld/bin/rsLibs
     [echo] ----------
     [echo] Resolving Dependencies for HelloWorld...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency] 
[dependency] ------------------
     [echo] ----------
     [echo] Building Libraries with 'debug'...
   [subant] No sub-builds to iterate on

-code-gen:
[mergemanifest] No changes in the AndroidManifest files.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...

BUILD FAILED
/var/lib/android-sdk-linux/tools/ant/build.xml:653: The following error occurred while executing this line:
/var/lib/android-sdk-linux/tools/ant/build.xml:698: Execute failed: java.io.IOException: Cannot run program "/var/lib/android-sdk-linux/build-tools/22.0.1/aapt": error=2, そのようなファイルやディレクトリはありません
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at java.lang.Runtime.exec(Runtime.java:617)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:428)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:442)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:628)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:669)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:495)
at com.android.ant.AaptExecTask.execute(AaptExecTask.java:703)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at com.android.ant.IfElseTask.execute(IfElseTask.java:120)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.io.IOException: error=2, そのようなファイルやディレクトリはありません
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:186)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 46 more

Total time: 1 second

やっぱしエラーがっorz

原因を色々調べていく中でどうやらaaptは32bitらしい。
[vagrant@localhost HelloWorld]$ file /var/lib/android-sdk-linux/build-tools/22.0.1/aapt
/var/lib/android-sdk-linux/build-tools/22.0.1/aapt: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
http://blog.mx17.net/2012/10/25/android-on-ubuntu-ioexception-on-aapt/
http://stackoverflow.com/questions/20001530/jenkins-cant-find-aapt-file-during-the-ant-building-of-android-application

必要なライブラリをインストール
[vagrant@localhost HelloWorld]$ sudo yum install glibc.i686 libgcc.i686 libXrender.i686 libSM.i686 libXext.i686
[vagrant@localhost HelloWorld]$ sudo yum install compat-libstdc++-296.i686 compat-libstdc++-33.i686

が、それでもダメでしたorz
Ubuntuでやるのがいいのか><;


7 件のコメント: