1

I have an app that uses the v4 and v7 support libraries. It runs absolutely fine in debug, but now i've gone to run it in Release mode im getting an error relating to the Theme.

"You need to use a Theme.AppCompat theme (or descendant) with this activity."

This is the declaration at the top of my app, where i DO declare an AppCompat theme:

   [Activity(Label = "My App", LaunchMode = LaunchMode.SingleTask, Theme="@style/Theme.AppCompat.Light", ScreenOrientation = ScreenOrientation.Portrait)]

I also declare it in the Manifest:

<application android:icon="@drawable/logo" android:debuggable="false" android:label="My App" android:theme="@style/Theme.AppCompat.Light">

Here is my stack trace. Any help would be very much appreciated.

libc] WARNING: generic atexit() called from legacy shared library
[monodroid-gc] GREF GC Threshold: 46800
[dalvikvm-heap] Grow heap (frag case) to 9.750MB for 803952-byte allocation
[dalvikvm-heap] Grow heap (frag case) to 11.473MB for 1607840-byte allocation
[Adreno-EGL] <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
[OpenGLRenderer] Enabling debug mode 0
[Request] Warning: Sessionless Request needs token but missing either application ID or client token.
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Java.Lang.RuntimeException: Exception of type 'Java.Lang.RuntimeException' was thrown.
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x00028>
[MonoDroid] at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) <0x000e7>
[MonoDroid] at Android.App.Activity.OnCreate (Android.OS.Bundle) <0x001f3>
[MonoDroid] at FrogPoint.Droid.MainActivity.OnCreate (Android.OS.Bundle) <0x0001f>
[MonoDroid] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x0005b>
[MonoDroid] at (wrapper dynamic-method) object.167c14b1-1233-456f-ab3e-1b59de9fa9bf (intptr,intptr,intptr) <0x00043>
[MonoDroid]   --- End of managed exception stack trace ---
[MonoDroid] java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
[MonoDroid]     at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
[MonoDroid]     at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
[MonoDroid]     at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
[MonoDroid]     at frogpoint.droid.MainActivity.n_onCreate(Native Method)
[MonoDroid]     at frogpoint.droid.MainActivity.onCreate(MainActivity.java:41)
[MonoDroid]     at android.app.Activity.performCreate(Activity.java:5231)
[MonoDroid]     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
[MonoDroid]     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
[MonoDroid]     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
[MonoDroid]     at android.app.ActivityThread.access$800(ActivityThread.java:135)
[MonoDroid]     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
[MonoDroid]     at android.os.Handler.dispatchMessage(Handler.java:102)
[MonoDroid]     at android.os.Looper.loop(Looper.java:136)
[MonoDroid]     at android.app.ActivityThread.main(ActivityThread.java:5001)
[MonoDroid]     at java.lang.reflect.Method.invokeNative(Native Method)
[MonoDroid]     at java.lang.reflect.Method.invoke(Method.java:515)
[MonoDroid]     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
[MonoDroid]     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
[MonoDroid]     at dalvik.system.NativeStart.main(Native Method)
[mono] 
[mono] Unhandled Exception:
[mono] Java.Lang.RuntimeException: Exception of type 'Java.Lang.RuntimeException' was thrown.
[mono] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x00028>
[mono] at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) <0x000e7>
[mono] at Android.App.Activity.OnCreate (Android.OS.Bundle) <0x001f3>
[mono] at FrogPoint.Droid.MainActivity.OnCreate (Android.OS.Bundle) <0x0001f>
[mono] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x0005b>
[mono] at (wrapper dynamic-method) object.167c14b1-1233-456f-ab3e-1b59de9fa9bf (intptr,intptr,intptr) <0x00043>
[mono] 
[mono]   --- End of managed exception stack trace ---
[mono] java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
[mono]  at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
[mono]  at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
[mono]  at android.support.v7.app.ActionBarActivit
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.RuntimeException: Exception of type 'Java.Lang.RuntimeException' was thrown.
[mono-rt] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x00028>
[mono-rt] at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) <0x000e7>
[mono-rt] at Android.App.Activity.OnCreate (Android.OS.Bundle) <0x001f3>
[mono-rt] at FrogPoint.Droid.MainActivity.OnCreate (Android.OS.Bundle) <0x0001f>
[mono-rt] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x0005b>
[mono-rt] at (wrapper dynamic-method) object.167c14b1-1233-456f-ab3e-1b59de9fa9bf (intptr,intptr,intptr) <0x00043>
[mono-rt] 
[mono-rt]   --- End of managed exception stack trace ---
[mono-rt] java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
[mono-rt]   at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
[mono-rt]   at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
[mono-rt]   at android.support.v7.app.Act
Can'tCodeWon'tCode
  • 543
  • 1
  • 11
  • 36
  • You need to compile it with API 14 or higher. – Cheesebaron Sep 04 '14 at 21:26
  • Thanks Cheesebaron, but my Target framework is already 4.4, and the minimum set to 4.3. So i don't think that's the issue unless i'm missing something. – Can'tCodeWon'tCode Sep 05 '14 at 07:44
  • Are you using ActionBarActivity or just Activity? – Cheesebaron Sep 05 '14 at 09:37
  • Also if you are using 4.3 and above, why do you need Support v7? – Cheesebaron Sep 05 '14 at 09:38
  • Yep, very good question, and to resolve the problem, i've ended up changing from ActionbarActivity to Activity, and making all other necessary changes in my fragments. That seems to have done it, i was just nervous about changing it being fairly inexperienced in fragments and support packages. I thank you for your help Cheesebaron. – Can'tCodeWon'tCode Sep 05 '14 at 12:12

3 Answers3

1

I was having the same error in my app. The solution which worked for me was simple. Just use this theme in your activity label

android:theme="@style/Theme.AppCompat.NoActionBar"

Don't use any other theme. It will surely work.

Gero
  • 4,394
  • 20
  • 36
1

Here are the steps: Go to Property-->Androidmanifest.xml It will open the file in IDE Enter the value in the Application theme as @style/MagicTheme Save it Now go to Resources-->Values -- Add a file by style.xml write the below code in style.xml

<resources>
  <style name="MyTheme.Base" parent="Theme.AppCompat.Light">
  </style>
  <style name="MyTheme" parent="MyTheme.Base">
  </style>
  <style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/pngfilename</item>
    <item name="android:windowNoTitle">true</item>  
    <item name="android:windowFullscreen">false</item>  
    <item name="android:windowContentOverlay">@null</item>  
    <item name="android:windowActionBar">true</item>  
  </style>
</resources>
0

So as we discussed in the comments to the OP. There is no need to use Support v7 if you are targeting Android 4.3 and up. Support packages are meant to give backwards compatibility to API levels which do not support the stuff from in newer API levels. Such as the ActionBar, Fragments etc. However since API 13, Fragments and ActionBar are included, so Support v7 is only needed for API levels below.

As for the crash you were experiencing, this was fixed in an earlier version of Xamarin.Android, so if you are not using any of the newer versions, this might have been the problem. Latest stable should be fine.

Cheesebaron
  • 24,131
  • 15
  • 66
  • 118