[Android開發] Android Studio問題以及解決記錄

來源:互聯網
上載者:User

標籤:navbar   11g   導包   注釋   recycle   project   bsp   cte   原因   

http://blog.csdn.net/niubitianping/article/details/51400721

1、真機運行報錯Multi dex requires Build Tools 21.0.0 / Current: 19.1

解決:

在項目 build.gradle 裡面把classpath ‘com.android.tools.build:gradle:1.5.0’ 改為1.5.0 或者1.3.0

2、匯入第三方包運行報錯:前言不允許有內容

解決

一般是包的位置錯誤,請放到main目錄下的libs 檔案夾裡面,再右鍵 add as library

3、運行錯誤: finished with non-zero exit valule 2

1. 包衝突

例如可能你v7支援包,v4支援包都有這個類,一編譯就衝突了,或者你complie了包,然後又手動add as library了,或者重複add了,等等。 (反正我出現這個問題幾乎都是包衝突)

2. 其他錯誤

這個一般會有錯誤提示,在編譯的日誌上面,例片不正確,看看是不是重新添加了圖片,然後在Android studio 裡面雙擊開啟這個圖片看看 是否能正常開啟,打不開就重新儲存一下格式(這個情況一般是出現在自己一個搞項目時候亂搞圖片會出現的問題)

4、編譯錯誤 Gradle DSL method not found: ‘apt()’

解決

1、在項目的gradle的dependencies裡面添加

classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8‘
  • 1

2、在你這個module的gradle裡面的頭部添加

apply plugin: ‘android-apt‘
  • 1

重新編譯解決

5、Failed to resolve: org.hamcrest:hamcrest-core:1.3

解決:

開啟as 的Setting,gradle路徑下的offline work 勾選,路徑改為gradle解壓之後的檔案夾,gradle可以自己上網下載http://services.gradle.org/distributions

6、打包時候報錯 Error: Expected resource of type styleable [ResourceType]

一般位於這裡:

TypedArray ta = mContext.obtainStyledAttributes(attrs);boolean hasBottomLine = ta.getBoolean(0, false);boolean hasTopLine = ta.getBoolean(1, false);
  • 1
  • 2
  • 3

解決:

在報錯的這行代碼的 方法體上面加@SuppressWarnings(“ResourceType”)

@SuppressWarnings("ResourceType")    public SystemBarTintManager(Activity activity) {        Window win = activity.getWindow();        ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {            // check theme attrs            int[] attrs = {android.R.attr.windowTranslucentStatus,                    android.R.attr.windowTranslucentNavigation};            TypedArray a = activity.obtainStyledAttributes(attrs);            try {                mStatusBarAvailable = a.getBoolean(0, false);                mNavBarAvailable = a.getBoolean(1, false);            } finally {                a.recycle();            }            。。。。。。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

即可解決

7、混淆後打包報錯: java.io.IOException: The same input jar [D:\Users\workspace_studio\Test5\app\libs\xxxxxxx.jar] is specified twice

原因: 
build.gradle檔案配置了 
dependencies { compile fileTree(include: ‘*.jar’, dir: ‘libs’)}

裡面已經添加過jar包,混淆檔案proguard-rules.pro裡面又加了句-libraryjars libs/.jar,將-libraryjars libs/.jar

解決:

proguard-rules.pro中的 -libraryjars libs/*.jar ,前面用#號注釋或者直接刪掉即可。

8、打包時候報錯Suspicious method call; should probably call “layout” rather than”onLayout”:
Suspicious method call; should probably call "layout" rather than"onLayout"
  • 1
  • 2

解決:

在調用onLayout的方法 上加

@SuppressLint("WrongCall")
  • 1
9、編譯的時候報錯:Error running app:Instant Run requires ‘Tools|Android|Enable ADB integration’ to be enabled

解決:

開啟adb, 菜單Tools—-Android——Enable ADB Integration

10、R 檔案報錯,無法取值 (Dereference)int

原因:

自動匯入了其他的R檔案包,例如百度地圖的R檔案包

解決:

把其他R檔案的包刪掉,添加自己的包名的R檔案。

11、Gradle sync failed: Unable to load class ‘org.gradle.internal.logging.LoggingManagerInternal’

gradle版本和android-maven-gradle-plugin 版本不協調

解決: 
如果你的gradle用的是2.1.2 ,你要把android-maven-gradle-plugin改為1.3

11、匯入ADT項目報錯There are unrecoverable errors which must be corrected first

看android Studio的資訊,說appcompat_v7_12 could not found,所以就是這個問題了。

把eclipse的project根目錄project.properties裡面的android.library.reference.1=../appcompat_v7刪掉,再重新匯入AndroidStudio就行了

12、列印的Log顯示不全

log輸出進行了字元的限制為4000個,解決方案是寫一個類採用分段的方法輸出log

    public static void printAll(String str){        if (str.length() > 4000) {            Log.v(TAG, "sb.length = " + str.length());            int chunkCount = str.length() / 4000;     // integer division            for (int i = 0; i <= chunkCount; i++) {                int max = 4000 * (i + 1);                if (max >= str.length()) {                    Log.v(TAG, "chunk " + i + " of " + chunkCount + ":" + str.substring(4000 * i));                } else {                    Log.v(TAG, "chunk " + i + " of " + chunkCount + ":" + str.substring(4000 * i, max));                }            }        } else {            Log.v(TAG, str);        }    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
13、匯入demo錯誤:Error:java.lang.RuntimeException:Some file crunching failed,see logs for details

在build.gradle的andoid裡面添加

aaptOptions.cruncherEnabled = falseaaptOptions.useNewCruncher = false
  • 1
  • 2
14、斷開手機串連,遠程主機強迫關閉了一個現有的串連


1. miui系統關閉usb安裝管理,運行安裝未知來源。 
2. 重寫拔插手機 
3. 電腦換個插口 
4. 換根資料線

15、Failed to open zip file.

Gradle’s dependency cache may be corrupt(this sometimes ocurs after a network connection timeout.) 

我是搞了svn才出現的問題。

解決方案: 
設定gradle

1. 設定本地gradle

把gradle壓縮包解壓出來,放隨便一個盤,在as裡面設定 

2. 搭建本地的gradle伺服器。

Windows安裝iis,然後把gradle的壓縮包放iis目錄裡面,然後在 項目根目錄\gradle\wrapper\gradle-wrapper.properties,修改最後的為distributionUrl=http://localhost/xxxxx.zip ,重新構建就o了

例如我的就是

distributionUrl=http://localhost/gradle-2.14.1-all.zip

16、No cached version of com.android.tools.build:gradle:2.2.3 available for offl

更新了AS之後出現的問題,更新AS,對應的gradle也得更新了,但是如果你使用的是之前的離線的GRadle就會出現這樣的問題了。

解決方案

File – Setting – Gradle – 取消勾選Offine work,選擇回預設的gradle wrapper

17、Error converting bytecode to dex:Cause:com.android.dex.DexEcception:Multiple dex files define….

原因1: 重複導包 
原因2: buildToolsVersion和compileSdkVersion的版本不對

解決: 對應上面的原因修改即可,本人的原因是因為第二個。

18、Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection Possible causes for this unexpected error include:Gradle’s dependency…

原因: gradle的版本不對。

解決: 把project的build.gralde的版本改為你的AndroidStudio的版本號碼,例如我是2.3.0版本的,就得把gradle版本改為2.3.0,然後重新sync即可。看圖 

然後重新構建,出現下面的問題,就點第一個update即可。 

19、Error while Installing APK,安裝app失敗,遠程主機強迫關閉了一個現有的連結

解決: 開啟工作管理員,把adb進程給關掉就行了

[Android開發] Android Studio問題以及解決記錄

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.