2017-04-18 17 views
1

私は新しいAndroid Studioプロジェクトを作成し、以下の私は、次のように私の最初のroboeletricテストを書いたアンドロイド Roboeletric - java.lang.UnsupportedClassVersionError

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 24 
    buildToolsVersion "24.0.0" 
    defaultConfig { 
     applicationId "retailstore.android.com.tddandroid" 
     minSdkVersion 15 
     targetSdkVersion 24 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:24.0.0' 
    testCompile 'junit:junit:4.12' 

    // import roboeletric 

    testCompile "org.robolectric:robolectric:3.3.2" 


} 

compileSDKVersion

から離れて何かを変えdidntのGradleのファイルでいます

@RunWith(RobolectricTestRunner.class) 
public class MainActivityTest { 

    @Test 
    public void clickingLogin_shouldStartLoginActivity() { 

     assertThat("").isEqualTo(""); 
    } 
} 

Iは以下のようにコマンドプロンプトを介してテストを実行してM:

enter image description here

+0

http://stackoverflow.com/a/35866015/3329708 –

+0

どのバージョンのAndroid用のgradleプラグインを使用していますか? Gradleは既にバージョン3.5で、おそらく(ラッパーで)アップデートする時間です –

+0

@EugenMartynovこれは 'classpath 'を使用しているgraleのプラグインです。com.android.tools.build:gradle:2.2.2' ' – KOTIOS

答えて

1

robolectricバージョンがjavaのバージョンと互換性があることを確認してください。

Robolectric 24+ apiバージョンにはJDK 1.8が必要です。 1.7と1.8 JDKのバージョンの両方が、コマンドの下でインストールされているすべてのバージョンをチェックしますかMac用のマシンにインストールされていることを

それは可能かもしれない:

$ ls -l /Library/Java/JavaVirtualMachines/ 
total 0 
drwxr-xr-x 3 root wheel 102 Nov 4 2013 jdk1.7.0_45.jdk 
drwxr-xr-x 3 root wheel 102 Jan 16 14:13 jdk1.8.0_25.jdk 

スイッチJDKのバージョン適切

関連する問題