【轉】android-support-v7-appcompat.jar 的安裝及相關問題解決 --- 匯總整理


原文網址:http://tdppro.blog.51cto.com/749956/1388853

1、DownLoading the Support Libraries

   1)Start the Android SDK Manager.

   2)In the SDK Manager window, scroll to the end of the Packages list, find theExtras

     folder and, if necessary, expand to show its contents.

   3)Select the Android Support Library item.

  4)Click the Install Packages... button

After downloading, the tool installs the Support Library files to your existing Android SDK directory. The library files are located in the following subdirectory of your SDK: <sdk>/extras/android/support dirctory

2、安裝支持庫

  1)首先創建一個Library Project

       File->import.

       選擇Existing Android Code Into Workspace ,單擊 Next

      找到SDK 安裝目錄的支持庫。比如,這里需要找到以下目錄錄 <sdk>/extras/android/support/v7/appcompat/.  

      單擊Finish 就可以導入項目。現在你可以看到一個名為 android-support-v7-appcompat.的        新項目。

      在新項目下的libs目錄下,將.jar文件加入到路徑中。

      在新項目文件名稱上面右鍵,選擇Configure Build Path

      在Order and Export 標簽下面,選中剛剛加入的.jar文件,將Android Dependencies不選中,單擊OK

  2)將支持庫加入到自己的項目中

       在項目中右鍵自己的項目名稱,選擇Properties

       在左側邊欄選中Android

       點擊Add按鈕

       選擇庫項目,比如這里的android-support-v7-appcompat.。如果此處找不到,則在安裝支持庫之前需要<sdk>/extras/android/support中的文件拷貝到你的workplaces中,

        選擇OK即可。

如何使用V7包中ActionBar(Eclipse版)

原文網址:http://blog.csdn.net/appte/article/details/11712591

以前3.0以前的版本要使用ActionBar,必須使用國外大牛寫的ActionBarSherlock這個開源項目。今年的Google/IO大會之后,Google官方在android-support-v7包中添加了ActionBar,開始讓2.1以后的版本支持ActionBar,從此以后曾經最火的Android開源項目ActionBarSherlock可以退出歷史舞台了。

要是用V7包中ActionBar也很簡單,但有一個需要注意的地方。有些人可能剛開始僅僅是把android-support-v7-appcompat.jar導入項目中,但是在設置Activity的theme時會報錯,提示找不到"@style/Theme.AppCompat"。這是由於我們要把v7和資源文件一起導入才行。

具體使用步驟(針對於Eclipse):

Create a library project based on the support library code:

  1. Make sure you have downloaded the Android Support Library using the SDK Manager.
  2. Create a library project and ensure the required JAR files are included in the project's build path:
    1. Select File > Import.
    2. Select Existing Android Code Into Workspace and click Next.
    3. Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding theappcompat project, browse to <sdk>/extras/android/support/v7/appcompat/.
    4. Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
    5. In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar andandroid-support-v7-appcompat.jar files to the build path.
    6. Right-click the project and select Build Path > Configure Build Path.
    7. In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
    8. Uncheck Android Dependencies.
    9. Click OK to complete the changes.

You now have a library project for your selected Support Library that you can use with one or more application projects.

Add the library to your application project:

  1. In the Project Explorer, right-click your project and select Properties.
  2. In the Library pane, click Add.
  3. Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
  4. In the properties window, click OK.

Once your project is set up with the support library, here's how to add the action bar:

  1. Create your activity by extending ActionBarActivity.
  2. Use (or extend) one of the Theme.AppCompat themes for your activity. For example:
    <activity android:theme="@style/Theme.AppCompat.Light" ... >

Now your activity includes the action bar when running on Android 2.1 (API level 7) or higher.

On API level 11 or higher

The action bar is included in all activities that use the Theme.Holo theme (or one of its descendants), which is the default theme when either the targetSdkVersion or minSdkVersion attribute is set to "11" or higher. If you don't want the action bar for an activity, set the activity theme to Theme.Holo.NoActionBar.以上摘自Android官網。

示例代碼:

[html]  view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.folyd.actionbartest"  
  4.     android:versionCode="1"  
  5.     android:versionName="1.0" >  
  6.   
  7.     <uses-sdk  
  8.         android:minSdkVersion="8"  
  9.         android:targetSdkVersion="17" />  
  10.   
  11.     <application  
  12.         android:allowBackup="true"  
  13.         android:icon="@drawable/ic_launcher"  
  14.         android:label="@string/app_name"  
  15.         android:theme="@style/AppTheme" >  
  16.         <activity  
  17.             android:theme="@style/Theme.Base.AppCompat.Light"  
  18.             android:name="com.folyd.actionbartest.MainActivity"  
  19.             android:label="@string/app_name" >  
  20.             <intent-filter>  
  21.                 <action android:name="android.intent.action.MAIN" />  
  22.   
  23.                 <category android:name="android.intent.category.LAUNCHER" />  
  24.             </intent-filter>  
  25.         </activity>  
  26.     </application>  
  27.   
  28. </manifest>  
[java]  view plain copy print ?
  1. package com.folyd.actionbartest;  
  2.   
  3. import android.os.Bundle;  
  4. import android.support.v7.app.ActionBar;  
  5. import android.support.v7.app.ActionBarActivity;  
  6.   
  7. public class MainActivity extends ActionBarActivity {  
  8.     private ActionBar actionBar;  
  9.   
  10.     @Override  
  11.     protected void onCreate(Bundle savedInstanceState) {  
  12.         super.onCreate(savedInstanceState);  
  13.         setContentView(R.layout.activity_main);  
  14.         actionBar = getSupportActionBar();  
  15.         actionBar.setDisplayShowHomeEnabled(true);  
  16.     }  
  17.   
  18. }  

效果截圖:

    

2016/01/19 

1. File->Import (android-sdk\extras\android\support\v7)導入appCompat后出現如下

error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.

解決方案1:下載API23的SDK Platform source packet --可行

右擊 appcompat -> Properties -> android, 選擇android5.0.1

原文網址:http://www.phperz.com/article/14/1204/39233.html

使用sdk manager下載以下內容:

解決方案2:直接將value-v23刪除。--可行

解決方案3:(--好像不行
如果你不想創建appcompat_v7,你可以在創建項目時將minimum Required SDK設置為4.1以上,這時就不再生成
appcompat_v7項目了,然后你再去清單文件中將minSdkVersion還原為8就行了.

2. 自己的工程出現 error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.

原文網址:http://www.tuicool.com/articles/YreyEn3

在整合android過程中導入別人的項目出現下面的錯誤:

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

error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.

通過stackoverflow查到其解決方法,如下:

(1)File->Import (android-sdk\extras\android\support\v7). Choose "appcompat"

在"文件"中導入sdk路徑extras\android\support\v7中的appcompat文件夾.如下圖所示:

(2) Project-> properties->Android.  In  the  section library "Add" and choose "appCompat"

此時問題即可解決,能正確運行.

    問什么會出現這個問題呢?這是我整合“隨時拍”項目其他人的代碼,他的版本比我的低,

新的eclipse默認模版主題UI需要使用比較高版本api,如果需要支持低版本,需要導入appCompact庫來支持

注意的地方:(原文網址:http://blog.csdn.net/huiguixian/article/details/41210895)

簡單來說就是新的eclipse默認模版主題UI需要使用比較高版本api,如果需要支持低版本,需要導入appCompact庫來支持,網上一般給出的解法:

  1. File->Import (android-sdk\extras\android\support\v7). Choose "appcompat"
  2. Project-> properties->Android. In the section library "Add" and choose "appCompat"
包括stackoverflow上也有很多人遇到,但很多人通過這個解決,但我就是沒辦法解決。
 
后來發現這個是eclipse的bug,如果你引用的庫和你的代碼不在一個盤符,就有此異常。
我的代碼在E盤,appCompact的庫在D盤,我從新將其移動到E盤就ok。
fuck,浪費好多時間。

android新建項目時 出現appcompat_v7工程錯誤和紅色感嘆號

原文網址:http://www.cnblogs.com/xiaozhang2014/p/4109856.html

最近初學android,版本是22.6.0的話,每次創建一個項目就會出現一個appcompat_v7工程;然后我升級到最新的版本23.0.4之后,創建第一個項目,也會出現一個appcompat_v7工程,但創建多個項目的話,appcompat_v7工程也僅有一個,但有錯誤;

上網查了一下,原來appcompat_v7是Google的一個兼容包,就是一個支持庫,項目新建后之所以會生成appcomat_v7工程,是為了能兼容2.2以上的版本,eclipse在新建項目的時候自動關聯了所需要的lib;

關聯的方式是:項目 -> Properies -> Android ->Libary;

你會看到appcomat_v7被作為lib加載了進來,如果不想引用這個lib,把它刪除了,關聯就解除了,也就不能兼容以前的版本了;

如果不想讓appcompat_v7自動生成,可以在創建項目時,將Minimum Required SDK(即兼容的最小版本)設置為4.0,那就不會有這個工程的出現了;

而出現歸出現,這個錯誤還是要解決的,解決方式為:

(1)打開Android SDK Manager,把最新的Android SDK和Tools里對應的Android SDK Build-tools下載下來,截止到2014年11月,應該是Android 5.0(API 21);當然,Extras的Android Support Respository,Android Support Library和Google USB Driver也要下載下來;

(2)下載完成后,選中appcompat_v7工程,點擊菜單欄里的Project ,把Build Automatically的勾去掉,即不要自動構建;

         然后clean一下整個項目:clean all projects,然后再build project;當然,這當中最好能重啟一下;然后再clean;

         

         然后就應該沒有錯誤了,然后再把Build Automatically選上,以后就可以新建項目了;

(3)新建項目時,為了兼容以前的版本,如果不想生成appcompat_v7工程的話,就要引入appcompat_v7的jar包作為支持;

在Eclipse添加Android兼容包( v4、v7 appcompat )

原文網址:http://www.cnblogs.com/kissazi2/p/3644848.html

昨天添加Android兼容包,碰到了很多問題,在這里記錄一下,讓后面的路好走。

如何選擇兼容包,

請參考Android Support Library Features(二)

一、下載Support Library

方法1:右擊項目→選擇Android Tools→Add Support Library…

image

方法2:

通過SDK Manager獲取Support Library:

1.打開Android SDK Manager

2.在SDK Manager窗口,滾動到Package List的末尾,找到Extra文件夾,如果需要的話打開文件夾顯示它的內容。

3.選擇Android Support Library項目。

注意:如果你使用的是Android Studio開發,選擇並安裝Android Support Repository項目而不是Android Support Library項目。

4.點擊Install packages按鈕。

下載完成后,SDK會將Support Library文件安裝到你已經存在的Android SDK目錄下。庫文件位於SDK的如下子目錄:<sdk>/extras/android/support/目錄。

 

二、添加V4兼容包(v4 appconpat)

  1. 確保你已經利用SDK Manager下載了Android Support Library 。
  2. 在你的項目的根目錄下創建一個libs/目錄。
  3. 從你的Android SDK安裝目錄(例如,<sdk>/extras/android/support/v4/android-support-v4.jar)下拷貝JAR文件到你項目的libs/目錄下。
  4. 右鍵點擊JAR文件並選擇Build Path > Add to Build Path。

三、添加V7兼容包(v7 appconpat)

創建一個基於support library代碼的 library project

  1. 確保你已經利用 SDK Manager下載了Android Support Library
  2. 創建一個library項目並且確保需要的JAR文件包含在了項目的build path中:
    1. 選擇File > Import
    2. 選擇Existing Android Code Into Workspace 並點擊Next
    3. 瀏覽SDK安裝目錄,並進入Support Library目錄下。例如,如果你要添加appcompat項目,瀏覽 <sdk>/extras/android/support/v7/appcompat/。
    4. 點擊Finish引入項目。對於v7 appcompat項目,你將看到一個標題為android-support-v7-appcompat的新項目。
  • image
    1. 在新項目中,展開libs/ 文件夾,右鍵點擊每一個.jar文件,並選擇Build Path > Add to Build Path。例如,當創建v7 appcompat項目時,同時將android-support-v4.jar和android-support-v7-appcompat.jar文件添加到build path中。
    2. 右鍵點擊library項目文件夾並選擇Build Path > Configure Build Path
    3. 在Order and Export選項中,在剛剛添加到build path中的.jar文件上打勾,這時這些文件成為項目可用的了並依賴於這個library項目。例如,appcompat項目要求同時導出android-support-v4.jar和android-support-v7-appcompat.jar文件。
    4. 去掉Android Dependencies上的對勾。
    5. 點擊OK完成設置

image

現在你擁有了一個包含你選擇的Support Library的library項目,你可以在一個或多個應用項目中利用這個Support Library。

現在我們要向應用工程(需要加入Support Library的工程)添加庫:

  1. 在項目瀏覽器中右鍵單擊你的項目,選擇Properties
  2. 在左邊的分類面板中,選擇Android
  3. 在Library面板中,點擊Add
  4. 選擇庫項目,然后點擊OK。例如,appcompat項目會在列表中顯示為android-support-v7-appcompat
  5. 在properties窗口中,點擊OK

image

遇到的問題:

1、java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$attr

這個問題,是因為app在運行時沒有找到對應的V7兼容包導致的,請參考文中  添加V7兼容包(v7 appconpat)

2、java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

完成上文提到的1,3步驟后,修改android:theme為@style/Theme.AppCompat

image

作者:kissazi2 
出處:http://www.cnblogs.com/kissazi2/ 
本文版權歸作者所有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM