WEB+DB PRESS Vol.81にAndroidの記事を書きました

Google I/O 2014が来週に迫った今日このごろですが、I/Oの前日に発売されるWEB+DB Vol.81に同僚たちとAndroidの特集記事を寄稿しました。私の担当はAndroid Studio+Gradleについてです。

とにかく変化の早いAndroid開発環境ですが、この一年で開発環境周りは格段に良くなってきています。また、いまから開発を始めるアプリなら2.x系のサポートも必須ではないでしょう。今回の記事ではそのあたりを踏まえて、Android開発の知見をまとめました。Androidの特集記事は以下の様な構成です。どうぞよろしく!

Androidアプリ開発最前線
設計,実装,デザインの新定石!

第1章:最新Android開発環境構築ガイド
Android StudioとGradleの基礎知識……藤 吾郎

第2章:あとで苦労しないための設計と実装
簡単なルールの導入で,可読性,メンテナンス性を高めよう……八木 俊広

第3章:使い勝手の良いデザイン
UIの基本,モックアップ,デザイナとの連携……日高 一明

第4章:チーム開発での改善サイクル
テスト,CI,段階的リリース,定量・定性データの収集……滝口 健太郎

WEB+DB PRESS Vol.81

WEB+DB PRESS Vol.81

電子版の定期購読もできるようですよ!

最近作ったAndroid用ライブラリ

すべてMaven Centralに公開している。

ところでこれらは一口にAndroid用といっても上からgradle plugin、pure Javaandroid-libraryとそれぞれ微妙にプロジェクトフォーマットが違うのだけど、maven archiveの作り方も微妙にちがっていて共有できるところが少なく非常につらい。Maven系ではないAndroidエコシステムを作らなければならないという思いを新たにした。

Android StudioでのコーディングにAndroidStyle.xmlを適用する

curl -L https://raw.githubusercontent.com/android/platform_development/master/ide/intellij/codestyles/AndroidStyle.xml > ~/Library/Preferences/AndroidStudioPreview/codestyles/AndroidStyle.xml

これでAndroidStyleを使えるようになる。XMLのインデントがAndroid Studio標準より深かったり、コードの幅が狭かったりして個人的にはそんなに好きなスタイルではないものの、まあこれも時代の趨勢かと思って使うことにした。

Bakusoku Iterations Tokyoで話したりrebuild.fmで話したりしました

Mobile First Development at COOKPAD

ブランチングモデルの話で、頻繁にデプロイするweb appではgithub-flowを、リリース間隔が長いmobile appではgit-flow(を簡略化したもの)を使ってるという話です。このへんはウェブかアプリかというよりは、kazuhoさんの指摘するように配布形態に依存するというのが実際のところでしょうね。

s]

つまり、web appでもリリース間隔が1~2週間なのであればgit-flowを採用するほうが安定した開発ができると。その後 develop ブランチなんてオワコン という議論もありましたが、一概に何がベストとはいえないのでそれぞれのプロジェクトのそれぞれの時期によって最適なブランチングモデルを検討するのがいいと思います。

Rebuild #45

最近はもっぱらモバイルアプリ、しかもそのなかの共通ライブラリ開発やアプリ/サービス間の連携などをやっているので、そのあたりの話です。

Rebuild #44で「JavaだとUIつくりこむの大変でしょ。JavaScriptでいいじゃん」みたいな話があったのでそれをうけてJavaの話とかしたんですが、UIの作り込みのコストは言語とか関係なくてUI frameworkやIDEの出来に依存するんじゃないかと感じてます。HTML+JavaScriptが楽な面はもちろんあるわけですが、それもChrome DevToolsの出来がいいとかそういう話なのかなと。

Macbook Air 2014を買った

Mid 2011からの乗り換えなので快適。とあるAndroidプロジェクトをビルドしてみたところ、2011機だと30秒かかるビルドが2014機だと20秒で終わった。これは効率上がりそう。

もっとも、2014機は本当にマイナーチェンジのようで、型番はMid 2013と変わらないらしい。

Maven CentralにdeployするときのgroupIdについて

結論:groupIdはプロジェクト名を含めるべき

POM referenceには以下のように書いてあります。

groupId: This is generally unique amongst an organization or a project. For example, all core Maven artifacts do (well, should) live under the groupId org.apache.maven. Group ID's do not necessarily use the dot notation, for example, the junit project. Note that the dot-notated groupId does not have to correspond to the package structure that the project contains. It is, however, a good practice to follow. When stored within a repository, the group acts much like the Java packaging structure does in an operating system. The dots are replaced by OS specific directory separators (such as '/' in Unix) which becomes a relative directory structure from the base repository. In the example given, the org.codehaus.mojo group lives within the directory $M2_REPO/org/codehaus/mojo.

artifactId: The artifactId is generally the name that the project is known by. Although the groupId is important, people within the group will rarely mention the groupId in discussion (they are often all be the same ID, such as the Codehaus Mojo project groupId: org.codehaus.mojo). It, along with the groupId, create a key that separates this project from every other project in the world (at least, it should :) ). Along with the groupId, the artifactId fully defines the artifact's living quarters within the repository. In the case of the above project, my-project lives in $M2_REPO/org/codehaus/mojo/my-project.

しかし、groupId=com.github.gfx, artifactId=android-power-assert-pluginは、sonatypeのnexus serverでは以下のように見えます。


なんとgroupIdしか表示されないのですね。nexusでの表示がそんなに重要なわけではないですが、一応プロジェクト名を含めるほうがよさそうです。

Travis-CIがandroidをサポートしたので試した

potatotips #7 で、 Travis-CIのandroid supportが始まったことを知った。

そこで、werckerを使っていたプロジェクトをtravisに乗り換えることにした。理由は、Chrome extensionのMy Travisを使っているため。これはfailureの数を教えてくれるエクステンションで、複数のプロジェクトをCIしているときは必須の機能である。

Travisの設定は以下のようになった。android emulatorを使うためにはandroid(1)を使ってavdを作るところからはじめなければいけないが、これはwerckerも同じなので、設定の手間としては大差ない。

https://github.com/gfx/android-power-assert-plugin/blob/master/.travis.yml

language: android
before_install:
    - export TERM=dumb # to get clean gradle output
    - export ANDROID_TARGET=android-19
    # setup and run the Android emulator
    - android list targets # for debugging
    - echo no | android create avd --force -n test -t $ANDROID_TARGET -b armeabi-v7a
    - emulator -avd test -no-skin -no-audio -no-window &
    - curl -L https://raw.githubusercontent.com/embarkmobile/android-sdk-installer/master/wait_for_emulator | bash
script:
    - ./gradlew lint
    - ./gradlew connectedAndroidTest