Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robolectric 4.3.1 fails with message: Android 29 requires Java 9 (have Java 1)

Tags:

I'm trying to run my android tests via robolectric, but it get the following error message:

at.guger.moneybook.data.repository.AccountsRepositoryTest STANDARD_ERROR
    [Robolectric] WARN: Android SDK 16 requires Java 8 (have Java 1). Tests won't be run on SDK 16 unless explicitly requested.
    [Robolectric] WARN: Android SDK 17 requires Java 8 (have Java 1). Tests won't be run on SDK 17 unless explicitly requested.
    [Robolectric] WARN: Android SDK 18 requires Java 8 (have Java 1). Tests won't be run on SDK 18 unless explicitly requested.
    [Robolectric] WARN: Android SDK 19 requires Java 8 (have Java 1). Tests won't be run on SDK 19 unless explicitly requested.
    [Robolectric] WARN: Android SDK 21 requires Java 8 (have Java 1). Tests won't be run on SDK 21 unless explicitly requested.
    [Robolectric] WARN: Android SDK 22 requires Java 8 (have Java 1). Tests won't be run on SDK 22 unless explicitly requested.
    [Robolectric] WARN: Android SDK 23 requires Java 8 (have Java 1). Tests won't be run on SDK 23 unless explicitly requested.
    [Robolectric] WARN: Android SDK 24 requires Java 8 (have Java 1). Tests won't be run on SDK 24 unless explicitly requested.
    [Robolectric] WARN: Android SDK 25 requires Java 8 (have Java 1). Tests won't be run on SDK 25 unless explicitly requested.
    [Robolectric] WARN: Android SDK 26 requires Java 8 (have Java 1). Tests won't be run on SDK 26 unless explicitly requested.
    [Robolectric] WARN: Android SDK 27 requires Java 8 (have Java 1). Tests won't be run on SDK 27 unless explicitly requested.
    [Robolectric] WARN: Android SDK 28 requires Java 8 (have Java 1). Tests won't be run on SDK 28 unless explicitly requested.
    [Robolectric] WARN: Android SDK 29 requires Java 9 (have Java 1). Tests won't be run on SDK 29 unless explicitly requested.

at.guger.moneybook.data.repository.AccountsRepositoryTest > testUpdateAccount FAILED
    java.lang.UnsupportedOperationException: Failed to create a Robolectric sandbox: Android SDK 29 requires Java 9 (have Java 1)
...

My installed JDK version is 13.

I've added android.enableUnitTestBinaryResources=true to gradle.properties and configured testOptions.unitTests.includeAndroidResources = true in build.gradle.

My test runner is AndroidJUnit4::class as specified in the Robolectric 4.x docs.

like image 515
the_dani Avatar asked Oct 15 '19 20:10

the_dani


1 Answers

There is an issue will order versions of Robolectric specifically 4.3.1. Simply upgrade the Robolectric Version to 4.5.1 or later.

 implementation "org.robolectric:robolectric:4.5.1"

Thanks.

like image 89
Tonnie Avatar answered Oct 10 '22 22:10

Tonnie