4

我已经在 Eclipse 中成功创建了一个应用程序,它适用于 android 4.0 及更高版本。现在我想让它也兼容 android 2.3 及更高版本。在我的应用程序中,我使用了操作栏,因此我在工作区的工作集中添加了 android-support-v7-appcompat 库项目。遵循http://developer.android.com/tools/support-library/setup.html说明后,现在我有 'android-support--v7-appcompat.jar' 和 'android-support-v4.jar'under我的项目 Android 私有库部分。我的项目的 libs 文件夹下还有 jar 文件。

在我的主要活动中,我导入了:

import android.support.v7.app.ActionBarActivity;
    import android.support.v7.app.ActionBar;

在 AndroidManifest.xml 文件中,我声明:

<application android:allowBackup="true" 

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

此外,对于不同的活动,声明为:

 <activity android:
                 android:uiOptions="splitActionBarWhenNarrow"

以前我的 AndroidManifest.xml 是这样的:

<application android:allowBackup="true" 

        android:theme="@style/<theme>"

res>values 文件夹下的 styles.xml 是这样的:

    <resources xmlns:android="http://schemas.android.com/apk/res/android">

       <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
       -->
       <style name="<base>" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
        </style>

        <!-- Application theme. -->
       <style name="<theme>" parent="<base>">
        <!-- All customizations that are NOT specific to a particular API-level can go      here. -->
    </style>

</resources>

用过的

  <style name="<base>" parent="android:Theme.Holo.Light">
            <!-- API 11 theme customizations can go here. -->
        </style> 

在 values-v11 文件夹和

<style name="<base>" parent="android:Theme.Holo.Light.DarkActionBar">
            <!-- API 11 theme customizations can go here. -->
        </style> 

在 values-v14 文件夹中。

我现在已将库项目中的所有 styles_base.xml 和 theme_base.xml 文件包含到我的项目中。还通过将 Theme 替换为 .

每次运行该应用程序时,我都会面临崩溃,现在即使是 4.0 及更高版本的 android 版本。消息:

 java.main.NoClassDefFounderError: android.support.v7.appcompat.R$styleable
    at android.support.v7.app.ActionBarActivityDelegate.onCreate

请帮忙。

4

1 回答 1

4

确保在 Project Properties -> Java Build Path --> Order and Export 部分中检查了兼容性库,如下所示:

在此处输入图像描述

否则它们将不会包含在生成的 APK 中。

编辑:

我认为您应该从头开始,因为您真的不应该将这些 XML 从支持库添加到您自己的项目中。

  1. 从支持库中删除所有 XML 和 jar
  2. 根据您提供的链接重建一个新的 Android 库项目(按照“使用资源添加库”说明)
  3. 将 Android 库项目添加到您的项目中
  4. 清理并重建项目
于 2013-07-30T16:24:52.207 回答