Reputation: 2353
I'm running into a strange IllegalStateException and I think it is a problem with Robolectric. This is the stack trace:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:340)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:309)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:273)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
at com.sr.dd.dd_app.screens.main.MainActivity.onCreate(MainActivity.java:87)
MainActivity.java line 87
setContentView(R.layout.activity_main);
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/main_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/main_left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="#FFFFFF" />
</android.support.v4.widget.DrawerLayout>
The Unit Test where the Activity is instantiated:
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, shadows = {ShadowGoogleApiAvailability.class}, manifest="app/src/main/AndroidManifest.xml")
public class ScreenUnitTest {
... //Some unimportant stuff
@Before
public void setUp() {
... //More unimportant stuff
mainActivity = Robolectric.setupActivity(MainActivity.class);
}
}
build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.mockito:mockito-core:1.+'
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'com.android.support:support-annotations:23.3.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.+'
testCompile 'org.robolectric:robolectric:3.1'
testCompile "org.robolectric:shadows-support-v4:3.1"
testCompile "org.robolectric:shadows-play-services:3.1"
testCompile 'org.robolectric:shadows-maps:3.1'
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
testCompile 'com.android.support:design:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:support-annotations:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:design:23.0.+'
compile 'com.android.support:cardview-v7:23.0.+'
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'joda-time:joda-time:2.9.4'
}
Compiling with Sdk version 23
Just wondering if anyone else has seen this. It looks similar to other questions, but the answers I have found aren't helping.
Upvotes: 1
Views: 297
Reputation: 7438
Remove the manifest entry from your config tag, robolectric will find it self. Or when necessary then use the manifest file located in your build directory. This is a common mistake and then robolectric can't find some stuff.
Upvotes: 1