You need to use a Theme.AppCompat theme (or descendant) with this activity after adding google-play-services
Asked Answered
A

4

6

In application I'm currently developing (it's my first android application) I use android-maven-plugin and maven-android-sdk-deployer. Application had been working great (MainActivity that uses ActionBarActivity had been shown correctly) until I added a google-play-servies library. After that I'm getting the following exception (no changes in application except adding required dependencies to pom.xml):

E/AndroidRuntime( 2146): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.acts.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
E/AndroidRuntime( 2146):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
E/AndroidRuntime( 2146):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
E/AndroidRuntime( 2146):    at android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime( 2146):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
E/AndroidRuntime( 2146):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 2146):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 2146):    at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime( 2146):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 2146):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 2146):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime( 2146):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime( 2146): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
E/AndroidRuntime( 2146):    at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:147)
E/AndroidRuntime( 2146):    at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:139)
E/AndroidRuntime( 2146):    at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
E/AndroidRuntime( 2146):    at com.metova.roboguice.appcompat.RoboActionBarActivity.onCreate(RoboActionBarActivity.java:45)
E/AndroidRuntime( 2146):    at com.myapp.acts.BaseActionBarActivity.onCreate(BaseActionBarActivity.java:23)
E/AndroidRuntime( 2146):    at com.myapp.acts.MainActivity.onCreate(MainActivity.java:62)
E/AndroidRuntime( 2146):    at android.app.Activity.performCreate(Activity.java:5933)
E/AndroidRuntime( 2146):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime( 2146):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
E/AndroidRuntime( 2146):    ... 10 more

My pom.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myapp</groupId>
    <artifactId>myapp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>myapp</name>

    <properties>
        <android.sdk.path>/data/tools/android-sdk-linux</android.sdk.path>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <platform.version>5.0_r1</platform.version>
        <android.plugin.version>3.8.2</android.plugin.version>
        <robospice.version>1.4.13</robospice.version>
        <picasso.version>2.3.5-SNAPSHOT</picasso.version>
        <android.support.version>21.0.1</android.support.version>
        <sdk.platform.version>21</sdk.platform.version>

        <commons.logging.version>1.1.3</commons.logging.version>
        <android-maven-plugin.version>3.7.0</android-maven-plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>android.support</groupId>
            <artifactId>compatibility-v7-appcompat</artifactId>
            <version>${android.support.version}</version>
            <type>apklib</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>android.support</groupId>
            <artifactId>compatibility-v7-appcompat</artifactId>
            <version>${android.support.version}</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>android.support</groupId>
            <artifactId>compatibility-v4</artifactId>
            <version>${android.support.version}</version>

        </dependency>
        <dependency>
            <groupId>org.roboguice</groupId>
            <artifactId>roboguice</artifactId>
            <version>2.0</version>
        </dependency>

        <dependency>
            <groupId>com.octo.android.robospice</groupId>
            <artifactId>robospice</artifactId>
            <version>${robospice.version}</version>
        </dependency>

        <dependency>
            <groupId>com.octo.android.robospice</groupId>
            <artifactId>robospice-retrofit</artifactId>
            <version>${robospice.version}</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>${commons.logging.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.squareup</groupId>
            <artifactId>otto</artifactId>
            <version>1.3.5</version>
        </dependency>

        <dependency>
            <groupId>android</groupId>
            <artifactId>android</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.google.android.maps</groupId>
            <artifactId>maps</artifactId>
            <version>21_r1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.google.android.gms</groupId>
            <artifactId>google-play-services</artifactId>
            <version>21.0.0</version>
            <type>apklib</type>
        </dependency>

        <dependency>
            <groupId>com.google.android.gms</groupId>
            <artifactId>google-play-services</artifactId>
            <version>21.0.0</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>com.squareup.okhttp</groupId>
            <artifactId>okhttp</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp</groupId>
            <artifactId>okhttp-urlconnection</artifactId>
            <version>2.0.0</version>
        </dependency>

        <dependency>
            <groupId>com.squareup.picasso</groupId>
            <artifactId>picasso</artifactId>
            <version>${picasso.version}</version>
        </dependency>

        <dependency>
            <artifactId>crouton</artifactId>
            <groupId>de.keyboardsurfer.android.widget</groupId>
            <version>1.8.5</version>
            <exclusions>
                <exclusion>
                    <groupId>com.android.support</groupId>
                    <artifactId>support-v4</artifactId>

                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <classifier>no_aop</classifier>
            <version>4.0-beta</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>${android.plugin.version}</version>
                    <extensions>true</extensions>
                </plugin>

                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                                        <artifactId>android-maven-plugin</artifactId>
                                        <versionRange>[1.0.0,)</versionRange>
                                        <goals>
                                            <goal>consume-aar</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore />
                                    </action>
                                </pluginExecution>

                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <sdk>
                        <platform>${sdk.platform.version}</platform>
                    </sdk>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

and AndroidManifest.xml:

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

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- maps -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <!-- /maps -->
    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="MY_KEY" />

        <activity android:name=".acts.LoginActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".acts.RegisterActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".acts.MainActivity"
            android:label="@string/app_name">
        </activity>
        <activity
            android:name=".acts.profiles.SearchProfilesActivity"
            android:label="@string/title_activity_search_profiles" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".acts.MainActivity" />
        </activity>

        <service
            android:name="com.myapp.net.RetrofitSpiceService"
            android:exported="false" />
    </application>

</manifest>

My styles.xml (in values-vXX I have simillar entries):

<resources>
    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
    </style>

</resources>

So basically adding these two dependencies causes application crash with "You need to use a Theme.AppCompat...":

       <dependency>
            <groupId>com.google.android.gms</groupId>
            <artifactId>google-play-services</artifactId>
            <version>21.0.0</version>
            <type>apklib</type>
        </dependency>

        <dependency>
            <groupId>com.google.android.gms</groupId>
            <artifactId>google-play-services</artifactId>
            <version>21.0.0</version>
            <type>jar</type>
        </dependency> 

Do you have any idea what is the cause of above problem? Any help would be appreciated.

Aviva answered 3/11, 2014 at 21:46 Comment(0)
A
1

Problem solved. I've changed section in pom.xml to this showed below.

<build>
        <finalName>${project.artifactId}</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>${lifecycle-mapping-plugin.version}</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            com.jayway.maven.plugins.android.generation2
                                        </groupId>
                                        <artifactId>
                                            android-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [${android-maven-plugin.version},)
                                        </versionRange>
                                        <goals>
                                            <goal>consume-aar</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                    <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                    <resourceDirectory>${project.basedir}/res</resourceDirectory>
                    <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                    <sdk>
                        <platform>${sdk.platform.version}</platform>
                    </sdk>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

I've also changed the dependency for google-play-services to aar:

<dependency>
    <groupId>com.google.android.gms</groupId>
    <artifactId>google-play-services</artifactId>
    <version>6.1.71</version>
    <type>aar</type>
</dependency>
Aviva answered 15/11, 2014 at 12:55 Comment(0)
K
7

I had the same problem and I fixed it in the AndroidManifest.xml by switching from

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

to

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat" >

I got this hint from an answer to the following issue.

Kameko answered 21/11, 2014 at 7:1 Comment(0)
A
1

Problem solved. I've changed section in pom.xml to this showed below.

<build>
        <finalName>${project.artifactId}</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>${lifecycle-mapping-plugin.version}</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            com.jayway.maven.plugins.android.generation2
                                        </groupId>
                                        <artifactId>
                                            android-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [${android-maven-plugin.version},)
                                        </versionRange>
                                        <goals>
                                            <goal>consume-aar</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                    <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                    <resourceDirectory>${project.basedir}/res</resourceDirectory>
                    <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                    <sdk>
                        <platform>${sdk.platform.version}</platform>
                    </sdk>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

I've also changed the dependency for google-play-services to aar:

<dependency>
    <groupId>com.google.android.gms</groupId>
    <artifactId>google-play-services</artifactId>
    <version>6.1.71</version>
    <type>aar</type>
</dependency>
Aviva answered 15/11, 2014 at 12:55 Comment(0)
A
1

You should use this:

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

inside activity in manifest. Good Luck!

Anthropology answered 21/8, 2015 at 16:59 Comment(0)
U
0

try to change:

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">

to:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
Unvoice answered 3/11, 2014 at 22:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.