パルカワ2

最近はFlutterをやっています

Robolectric 3.3.2から3.4.2へのバージョンアップでやったこと

hisaichi5518.hatenablog.jp

Android Studio 3.0系ではAAPT2がデフォルトでONになっているので、Robolectric 3.3.2ではリソースまわりでエラーが出て動かないようだ。

AAPT2. We are continuing to stabilize AAPT2 which enables incremental resource processing. If your build fails due to resource processing issue, please send us a bug report. To temporarily disable AAPT, set android.enableAapt2=false in your gradle.properties file.
a. Roboelectric is currently not compatible with AAPT2
Android Studio Release Updates: Android Studio 3.0 Canary 5 is now available

AAPT2をfalseにするのも試したけど、テスト用のApplicationクラスを実行してくれなかったので、めんどくさくなって将来的に必要であろうということでバージョンアップした。
追記:テスト用のApplicationクラスを実行してくれなかったというのは僕の勘違いだった!!!!

  • バージョンをあげる
  • testOptionsの追加
  • Add-On Modules の名前変更
  • compileSdkVersion の変更
  • org.assertj.core.api.Java6Assertions.assertThatの利用をやめる
バージョンをあげる

はい

testCompile "org.robolectric:robolectric:3.4.2"
testOptionsの追加

Robolectricのドキュメントであるgetting startedに書かれてある通り、testOptionsを追加する必要がある。

android {
    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
}
Add-On Modules の名前変更

ドキュメントはまだ更新されていないけど、Robolectric 3.4のRelease noteを見ると名前が変わっていたので変更した。一応、ドキュメント更新のプルリクを出しておいた。

Some Robolectric sub-projects have been renamed. build.gradle files will need to updated accordingly. [issue #3186]:

robolectric-annotations -> annotations
robolectric-junit -> junit
robolectric-processor -> processor
robolectric-resources -> resources
robolectric-sandbox -> sandbox
robolectric-utils -> utils
shadows-core -> framework
shadows-httpclient -> httpclient
shadows-maps -> maps
shadows-multidex -> multidex
shadows-play-services -> playservices
shadows-support-v4 -> supportv4

Rename projects. by xian · Pull Request #3186 · robolectric/robolectric · GitHub

compileSdkVersion の変更

compileSdkVersion が25未満だとShortcutManagerがないと怒られるのでバージョンを25以上にする必要がある。

org.assertj.core.api.Java6Assertions.assertThatの利用をやめる

Robolectric now requires JDK8.

とのことで依存からなくなったようなので、org.assertj.core.api.Assertions.assertThatに変更

アプリをAndroid Studio 3.0 beta 4に対応したのでやったこと

まだマージする気はないけど、対応しておくかと思ったのでやってみた。
結構色々と変わっているようだけど、ビルド出来るところまではすぐ出来た。しかしRobolectricまわりでテストが死んでる…(まだ調べてない)追記:Robolectricがエラーになるのを調べたので書いた

  • gradleの更新
  • maven.google.com を追加
  • deploygateのプラグインを更新
  • gradle pluginの更新
  • retrolambda を削除
  • provided を利用してた箇所を annotationProcessorに変更
gradleの更新
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wr
index 4d0f7f7e7..01ed591b3 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Thu Jan 19 11:13:41 JST 2017
+#Tue Sep 05 17:23:15 JST 2017
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
maven.google.com を追加

google()を buildscript と allprojects 両方に指定する必要があった。

deploygateのプラグインを更新

古いプラグインは対応していないようなので1.1.3に更新した
https://docs.deploygate.com/v1.1/docs/gradle-plugin

gradle pluginの更新
diff --git a/build.gradle b/build.gradle
index 156d515ea..ccc0c96f1 100644
--- a/build.gradle
+++ b/build.gradle
@@ -16,7 +16,7 @@ buildscript {
         maven { url 'https://jitpack.io' }
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.3.3'
+        classpath 'com.android.tools.build:gradle:3.0.0-beta4'
         classpath 'com.deploygate:gradle:1.1.3'
retrolambda を削除

Android Studio 3.0から一部Java8の文法に対応しているようなので削除

Use Java 8 language features | Android Studio

provided を利用してた箇所を annotationProcessorに変更

icepickとlombokがprovided使ってたので修正
ただLombokがannotationProcessorのみだとエラーになるので、compileOnly も加えた

https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#annotationProcessor_config

diff --git a/app/build.gradle b/app/build.gradle
index cb74189ff..a62e509c0 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -260,7 +260,7 @@ dependencies {

     compile 'frankiesardo:icepick:3.2.0'

-    provided 'frankiesardo:icepick-processor:3.2.0'
+    annotationProcessor 'frankiesardo:icepick-processor:3.2.0'

@@ -347,7 +347,8 @@ dependencies {
         transitive = true;
     }

-    provided 'org.projectlombok:lombok:1.16.18'
+    compileOnly "org.projectlombok:lombok:1.16.18"
+    annotationProcessor "org.projectlombok:lombok:1.16.18"
 }

AndroidエミュレータでのAuto Backup for Appsを検証する

  • Settings > Backup & Reset でバックアップを有効にする
  • バックアップ用にGoogleアカウントにログインしている必要がある
  • adb shell bmgr run
  • データを保存するような動作をする
  • adb shell bmgr backupnow
  • App infoからデータをクリアする
  • adb shell bmgr restore

Auto Backup for Apps | Android Developers

コマンドを実行するとTransport errorというのが出ていて???ってなってたけど、バックアップが有効になってなかった事とバックアップアカウントが設定されていないのが原因だった。

Retrofit2+RxJava2 で リクエストするときに subscribeOn を指定する必要がないようにする

こういう風にRetrofit2を利用してた。

new Retrofit.Builder()
    .client(clientBuilder.build())
    .baseUrl(...)
    .addConverterFactory(GsonConverterFactory.create())
    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
    .build();

APIを叩くコードを書くたびsubscribeOnを指定していてめんどくさかったので調べたらcreateWithSchedulerを利用すればどうにか出来ると知った。

new Retrofit.Builder()
    .client(clientBuilder.build())
    .baseUrl(...)
    .addConverterFactory(GsonConverterFactory.create())
    .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
    .build();

便利

お産合宿11に出た

お産合宿にいってきた。

「お産合宿」はデザイナーやエンジニアなどの「クリエイター」という枠にとらわれず、普段は別々の仕事をしているさまざまな職種のスタッフが、所属する部署や職種を飛び越えてチームを作り、自分たちが「もっとおもしろくできる」と思うものを存分に作る、そんな合宿です。
【 #ペパボお産11 】開催決定!応援よろしくお願いします! | お産合宿11 | GMOペパボ株式会社


チームメンバーはminneのマネージャー二人とminneのCTL二人の計四人です。

お産合宿の前には全く開発せずにお産合宿でのみ開発する気持ちでいったら、なかなか大変でしたがそれも含めて楽しかったです。
今の会社に入って3年過ぎて、ついに4年目なのですが、お産合宿は初参加でした。昔は趣味で吉高由里子関連のアレコレをつくっていた僕も今では汚れてしまい、お金がもらえないとつくる力が無になっていたのですが、お産合宿に参加する人たちや作られたものたちを見てるとテンションが上がり、ちょっと作るか…!という気持ちになったので参加してよかったです。次があるなら次はサービス作ってみたいナー

プロジェクトを動かすために必要なAndroid Studioのプラグインを設定する

Preferences -> Build, Execution, Deployment -> Required Plugins

で設定出来た。+を教えて出てきたダイアログがこんなんで、Pluginのところがスクロール出来る。今の今まで、スクロールが出来ることに気づいてなかった………なんてこった…

f:id:hisaichi5518:20170829012010p:plain

設定するとこんな感じで表示される。良さそうなら保存すれば、 .idea/externalDependencies.xmlが作成される。
f:id:hisaichi5518:20170829011758p:plain

あとは .gitignore に .idea/externalDependencies.xmlを除外するようにしておくとよい。