Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 0.3.1, appcompat-v7 and android library project always generate IllegalStateException

I am developing an application that uses the libraries appcompat v7 and support-v4. The application works correctly and its main theme is derived from Theme.AppCompat.

Problems arise when I try to add any module (android library project) to the main project: I always get an IllegalStateException.

At the moment the project library is completely empty: no Java classes or XML resources, there is only the file AndroidManifest:

MyLibrary AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.viewpagerindicator"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="18" />
    <application />
</manifest>

I also tried to add the theme Theme.AppCompat to the Application section of MyLibrary:

<?xml version="1.0" encoding="utf-8"?>
[...]
    <application android:theme="@style/Theme.AppCompat" />
</manifest>

But the result is always the same exception:

10-28 12:22:36.761    1770-1770/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.akhela.tekpea/com.akhela.tekpea.ui.OverviewActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:102)
            at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
            at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
            at com.akhela.tekpea.ui.OverviewActivity.onCreate(OverviewActivity.java:39)
            at android.app.Activity.performCreate(Activity.java:5104)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)

MyProject settings.gradle

include ':MyApp', ':MyLibrary'

MyApp build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 18
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.android.support:support-v4:+'
    compile project(":MyLibrary")
}

MyLibrary build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android-library'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 18
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.android.support:support-v4:+'
}
like image 491
Roberto Leinardi Avatar asked Oct 28 '13 16:10

Roberto Leinardi


People also ask

How do I fix Appcompat error v7?

"You must have the latest versions of SDK Tools / Build Tools / Platform Tools." This trick resolved my problem. I have all updated Tools except "Build Tools". So I just update the "Build Tools", restarted eclipse then clean "appcompat" project and found my problem is solved.

What is appcompat library?

426. An Android support library that enables the use of the ActionBar and Material Design specific implementations such as Toolbar for older devices down to Android v2.


1 Answers

I don't know exactly whats's happening but I suppose there are some issues during the resource merging.

I would try removing these dependencies from the application build.gradle

compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'

leaving them just in the library build.gradle.

like image 144
rciovati Avatar answered Oct 20 '22 14:10

rciovati