2016年6月15日 星期三

About Eclipse appcompat_v7 Error




當專案用到了新的效果 需要Class 引用 AppCompatActivity


ex.
public class MainActivity extends AppCompatActivity { ...

在Eclipse 中需要比較多的步驟來引入 appcompat_v7

這個問題也卡了很久 紀錄一下解決辦法


首先是設定 Support Library

主要是關於 Import 及 Build Path 的問題

方法參考 老灰鴨大大的筆記有很詳盡的說明

但設定完之後卻不是天下太平

接著出現各種錯誤訊息,導致專案Build不起來 (這邊整整卡了半天左右的時間...哭)

例如:

Hello World Android App, Error: workspace\appcompat_v7\res\values-v21\styles_base.xml No resource found that matches the given name

Error retrieving parent for item: No resource found that matches the given name after upgrading to AppCompat v23

appcompat-v7:21.0.0': No resource found that matches the given name: attr 'android:actionModeShareDrawable'


eclipse android Build Tools Version 問題


Failing to launch activity due to ClassNotFoundException

Theme  引用問題

Error. You need to use a Theme.AppCompat theme (or descendant) with this activity


...各種奇怪的問題都出現了,Akira解到快昏頭


因此整理一下解決方案:

首先到Android SDK Manager 確認Build Tool下載至新版


Import android-support-v7-appcompat 專案進來


並在專案中 找到libs 裡面的 .jar檔 右鍵 Build Path > add to Build Path



再到要使用的專案中 點右鍵 > Properties > 選 Android 標籤 >

右下角 add > 找到 android-support-v7-appcompat 加進來 OK




讓Class XXXXX extends AppCompatActivity


Import 一下專案

接著到專案的 AndroidManifest.xml 找到下面



android:targetSdkVersion 設定成你要用的版本 通常是看特效支援的最低版

最後 找到 android:theme="@style/" 把它改成 @style/Theme.AppCompat.Light !!
最後 找到 android:theme="@style/" 把它改成 @style/Theme.AppCompat.Light !!
最後 找到 android:theme="@style/" 把它改成 @style/Theme.AppCompat.Light !!







然後Clean & Build 你的專案就可以用嘍

Ps. 後來在使用 Design.Weiget 又產生Error

http://stackoverflow.com/questions/31430633/how-to-add-android-design-support-library-to-eclipse-with-adt-plugin


使用此篇方法解決


1 則留言:

  1. 可分享你的extras資料夾嗎?我這裡面路徑和你不同也不能匯入

    回覆刪除