Android Studio使用心得 - 常見問題集錦

來源:互聯網
上載者:User

標籤:android studio   google   gradle   stackoverflow   ide   

整理了一些這段時間遇到的常見問題,希望對各位猿們有協助。。。如果覺得有用就點個贊哦


問題一:

Error:(26, 9) Attribute [email protected] value=(@drawable/logo) from AndroidManifest.xml:26:9

Error:(28, 9) Attribute [email protected] value=(@style/ThemeActionBar) from AndroidManifest.xml:28:9
is also present at XXXX-trunk:XXXXLib:unspecified:15:9 value=(@style/AppTheme)
Suggestion: add ‘tools:replace="android:theme"‘ to <application> element at AndroidManifest.xml:24:5 to override
Error:Execution failed for task ‘:XXXX:processDebugManifest‘.

> Manifest merger failed with multiple errors, see logs


原因:

AS的Gradle外掛程式預設會啟用Manifest Merger Tool,若Library項目中也定義了與主專案相同的屬性(例如預設產生的android:icon和android:theme),則此時會合并失敗,並報上面的錯誤。


解決方案有以下2種:

方法1:在Manifest.xml的application標籤下添加tools:replace="android:icon, android:theme"(多個屬性用,隔開,並且記住在manifest根標籤上加入xmlns:tools="http://schemas.android.com/tools",否則會找不到namespace哦)

方法2:在build.gradle根標籤上加上useOldManifestMerger true (懶人方法)


參考官方介紹:

http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger



問題二:

Library Project裡面的BuildConfig.DEBUG永遠都是false。這是Android Studio的一個已知問題,某Google的攻城獅說,Library projects目前只會產生release的包。

Issue 52962: https://code.google.com/p/android/issues/detail?id=52962


解決方案:(某Google的攻城獅推薦的方法)

Workaround: instaed of BuildConfig.DEBUG create another boolean variable at lib-project‘s e.g. BuildConfig.RELEASE and link it with application‘s buildType. 

https://gist.github.com/almozavr/d59e770d2a6386061fcb


參考stackoverflow上的這篇帖:

http://stackoverflow.com/questions/20176284/buildconfig-debug-always-false-when-building-library-projects-with-gradle



問題三:

每次儲存的時候,每行多餘的空格和TAB會被自動刪除(例如結尾、空行的多餘空格或TAB)

特別是每次準備提交SVN,Review代碼時候你就蛋疼了,顯示一堆不相關的更改,看的眼花。


解決方案:

Settings->IDE Settings->Editor->Other->Strip trailing spaces on Save->None



問題四:

編譯的時候,報:Failure [INSTALL_FAILED_OLDER_SDK]。一般是系統自動幫你設定了compileSdkVersion 


解決方案:

修改build.gradle下的compileSdkVersion ‘android-L‘為compileSdkVersion 19(或者你本機已有的SDK即可)





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.