LoginSignup
0
0

More than 5 years have passed since last update.

robolectric3.0で Android SDK23 を動かす方法

Last updated at Posted at 2015-11-05

最新のrobolectricでは、compileSdkVersion 23を指定すると二つの問題が発生します。

  • Gradle: エラー: AndroidHttpClientにアクセスできません が出る
  • Robolectric does not support API level 23 が出る

解決方法

一つ目の原因は、API Level 23から AndroidHttpClientが削除されたからです。
なので、以下のように記述すれば解決します。

build.gradle
android {
    useLibrary 'org.apache.http.legacy'

Http関連の処理を記述していなくてもこのエラーは出るので必須です。

これは、githubのissueに上がっているので、次のバージョンでは解決されるでしょう。
https://github.com/robolectric/robolectric/issues/1862

二つ目のエラーはsdk = Build.VERSION_CODES.LOLLIPOP)を指定すれば、解決です。
こんな感じです。

MainActivityTest.java
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
public class MainActivityTest {

robolectricは、SDK21以下でないと対応していないようです。

これもissueにあるので次のバージョンでは解決されるでしょう。
https://github.com/robolectric/robolectric/issues/1865

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