LoginSignup
0
0

More than 3 years have passed since last update.

Kotlin用Twitter APIラッパー『Penicillin』をAndroidで使う

Last updated at Posted at 2020-07-08

はじめに

Gradleのdependenciesに書くだけでは動かず、かなり面倒だったので忘備録として残しておく。
Androidを触るのは久しぶりなので、違うやり方してるかも。

環境
Windows10
Android Studio 4.0
Kotlin 1.3.72
Android SDK Build-Tools 30

Penicillinとは

Penicillin - Github
日本の大学生が作っているTwitterラッパー。めちゃくちゃ使いやすい。
クエリを非同期やコールバックで実行できたり、.next()や.untilLast() ひとつでページングが出来る。
Twitterクライアントブームが過ぎてtwitter4jも死んだ今、オレオレTwitterアプリ界に燦然と輝く若き星。

やり方

appモジュールのbuild.gradleを以下のように追記。
バージョンは適宜変更。

build.gradle
android {
    ...
    kotlinOptions {
        jvmTarget = "1.8"
    }
    packagingOptions {
        exclude("META-INF/*.kotlin_module")
        // More than one file was found with OS independent path 'META-INF/jsonkt.kotlin_module'.
        // ビルド時のこのエラー回避。正しい方法かは分からないが、ちゃんと動作している。
    }
}

repositories {
    mavenCentral()
    maven {
       url "https://dl.bintray.com/nephyproject/stable"
    }
}

dependencies {
    ...
    implementation "io.ktor:ktor-client-android:$ktor_version"
    // OkHttpを使う場合  後述
    // implementation "com.squareup.okhttp3:okhttp:4.7.2"
    // implementation "io.ktor:ktor-client-okhttp:$ktor_version"

    implementation "blue.starry:penicillin:5.0.0"
}

Ktor HTTP Client Engineについて

Penicillinが使用するHTTPクライアントエンジンを選択する必要がある。エンジンが違えば、依存関係やサポート機能も異なる。
Engines - Clients - Ktor
READMEに書いてあるリンクを見ると、AndroidではOkHttpかAndroid標準を使えと書いてある。
画像表示でPiccasoを使うなら一緒にOkHttpも入れるだろうから、そうした方が良いだろう。

0
0
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
0
0