gpt4 book ai didi

android - 添加 google-play-services 后,您需要在此 Activity 中使用 Theme.AppCompat 主题(或后代)

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:14:37 29 4
gpt4 key购买 nike

在我目前正在开发的应用程序中(这是我的第一个 android 应用程序),我使用 android-maven-plugin 和 maven-android-sdk-deployer。在我添加 google-play-servies 库之前,应用程序一直运行良好(使用 ActionBarActivity 的 MainActivity 已正确显示)。之后我得到以下异常(除了向 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

我的 pom.xml 是:

<?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>

和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>

我的 styles.xml(在 values-vXX 中我有类似的条目):

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

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

</resources>

所以基本上添加这两个依赖项会导致应用程序崩溃,并显示“您需要使用 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>

您是否知道上述问题的原因是什么?任何帮助将不胜感激。

最佳答案

我遇到了同样的问题,我通过从

切换到AndroidManifest.xml中修复了它
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

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

我从对以下 issue 的回答中得到了这个提示.

关于android - 添加 google-play-services 后,您需要在此 Activity 中使用 Theme.AppCompat 主题(或后代),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26723822/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com