LoginSignup
2
1

More than 5 years have passed since last update.

Parceler1.0.3とButterKnife8.4.0を併用する

Posted at

Parcelを簡単に使うためのライブラリParceler

Parcelを使いたいけど、いちいちCREATORとか書くのは面倒なので、こう記述して使います。

build.gradle
dependencies {
  compile "org.parceler:parceler-api:1.0.3"
  apt "org.parceler:parceler:1.0.3"
}

今更言うまでもないButterKnife

DataBindingとかもありますが、やっぱ手軽だなと感じるので、もっぱらButteKnifeを使っています。

build.gradle
dependencies {
  compile 'com.jakewharton:butterknife:8.4.0'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}

そして同じアプリに、これらを同時に使用すると…

build.gradle
dependencies {
  compile "org.parceler:parceler-api:1.0.3"
  apt "org.parceler:parceler:1.0.3"
  compile 'com.jakewharton:butterknife:8.4.0'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}

当然こう書きますよね。

すると、ビルドは問題なく通りますが@BindViewとかでbindしたはずの変数が実はbindされていずアプリが落ちます。

対策

build.gradle
dependencies {
  compile "org.parceler:parceler-api:1.0.3"
  apt "org.parceler:parceler:1.0.3"
  compile 'com.jakewharton:butterknife:8.4.0'
  apt 'com.jakewharton:butterknife-compiler:8.4.0'
}

これで行けます。

ちなみに…

build.gradle
dependencies {
  compile "org.parceler:parceler-api:1.0.3"
  annotationProcessor "org.parceler:parceler:1.0.3"
  compile 'com.jakewharton:butterknife:8.4.0'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}

では、org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable class(抜粋)とか言われて駄目でした。

追記

Parceler1.1.6(現時点の最新版)ではbuild.gradleに書く、aptの部分がannotationProcessorになっているので、問題なく併用できます。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1