1. 程式人生 > >Android studio 常見錯誤以及問題

Android studio 常見錯誤以及問題

1.dexDebug ExecException finished with non-zero exit value 2 全bug日誌如下:

(Error:Execution failed for task ':app:dexDebug'.

> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\JDK8\jdk1.8.0_11\bin\java.exe'' finished with non-zero exit value 2)
需要在gradle中配置下面的程式碼,原因是引用了多個libraries檔案

defaultConfig {
multiDexEnabled true
}

2.Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/app/BackStackState$1.class

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/ArrayRes.class

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/android/volley/ServerError.class

原因:在所新增的jar包或aar包中也引用了support-V4,與工程中引用的相沖突
Ctrl+N --> 在搜尋框中輸入BackStackState --> 查詢到所有引用該類的類,這些類即為引起衝突的類
去掉本工程中gradle中用於引用有衝突的包的程式碼或者將衝突的程式碼從jar包或aar包中移除,確保一個module中只引用了一份相同的第三方包

3.project sturcture和Project Structure 無論是按快捷鍵或者是從files中開啟都不顯示

event log中報:IllegalArgumentException:Multiple entries with same key: Google Inc.:Google APIs:23=Google APIs (Google Inc.) (API 23) and Google Inc.:Google APIs:23=Google APIs (Google Inc.) (API 23)

解決辦法:先看一下系統配置的SDK的位置和Android Studio所用的路徑是否一致,如果不一致重新配置系統的SDK路徑或者是重新修改Android Studio的SDK路徑
通過SDK Manager刪除掉google API23
如果解決不了,解除安裝android studio -->重新安裝 ,還有問題點選File --> Invalidate Cashes/Restart --> Invalidate and Restart,解決不了繼續通過SDK Manager刪除掉google API23

4.Error:Execution failed for task ':app:clean'.

> Unable to delete directory: E:\as_workspaces\DJIgo\app\build\intermediates\res\merged\debug

專案中有錯,無法刪除這個資料夾下面的檔案。手動刪除debug資料夾或某工具粉碎即可(補充與20160916)。

5.Error:Execution failed for task ':tongyan_bugs_framework_master:processDebugAndroidTestManifest'.

> java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 18 cannot be smaller than version 19 declared in library [DJIgo:tysubwayinspection3.0-framework:unspecified] E:\as_workspaces\DJIgo\tongyan_bugs_framework_master\build\intermediates\exploded-aar\DJIgo\ty3.0-framework\unspecified\AndroidManifest.xml
Suggestion: use tools:overrideLibrary="com.ton.framework" to force usage

應該是Library的sdk的版本與app的sdk的版本有衝突

6.Error:Execution failed for task ':app:processDebugManifest'.

> Manifest merger failed : uses-sdk:minSdkVersion 17 cannot be smaller than version 19 declared in library [DJIgo:tongyan-djigo-lib:unspecified] E:\as_workspaces\DJIgo\app\build\intermediates\exploded-aar\DJIgo\tongyan-djigo-lib\unspecified\AndroidManifest.xml
Suggestion: use tools:overrideLibrary="com.tongyan.lib.djigo" to force usage

7.Error:Execution failed for task ':tongyan-djigo-lib:compileReleaseJavaWithJavac'.

> Compilation failed; see the compiler error output for details.

8.注: E:\as_workspaces\DJIgo\tongyan-djigo-lib\src\main\java\com\tongyan\lib\djigo\ui\view\ControlMoveView.java使用或覆蓋了已過時的 API。

注: 有關詳細資訊, 請使用 -Xlint:deprecation 重新編譯。 android studio-File->Project Structure->Android sdk location(路徑應該不正確)

9.Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

> java.io.FileNotFoundException: E:\as_workspaces\TYSubway\app\libs\pushservice-4.5.6.88.jar (系統找不到指定的檔案。)

需要把dependencies中的lib包下面的jar包全部取消下,再新增。

10.Error:Execution failed for task ':tysubwayinspection3.0-framework:packageReleaseResources'.

> java.io.IOException: Could not delete folder E:\as_workspaces\DJIgo\tysubwayinspection3.0-framework\build\intermediates\bundles\release\res

11.由於使用sdk5.0造成的以下問題,需要用sdk6.0

E:\as_workspaces\DJIgo\app\build\intermediates\res\merged\debug\values-v23\values-v23.xml
Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
Error:(18) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\Android\adt-bundle-windows-x86_64-20140702\android_sdk\build-tools\23.0.0\aapt.exe'' finished with non-zero exit value 1

12.Error:Execution failed for task ':app:clean'.

> Unable to delete file: E:\as_workspaces\DjiGo-Demo\app\build\intermediates\exploded-aar\com.android.support\support-v4\23.3.0\jars\classes.jar

專案中有錯

13.Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.

> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/IntegerRes.class

包衝突了,在app及子library中仔細找是否有相同的jar包

14.Error:Execution failed for task ':app:clean'.

> Unable to delete directory: E:\as_workspaces\DJIGO_FLY\app\build\outputs\apk

無法刪除這個資料夾下的檔案,到目錄下面就知道了。

15.關於R檔案無法引入,導致很長時間無法找到錯誤的根源。比如:如果錯誤在A類裡面發生,但是Message裡提示的是B類的R檔案無法引入。

這樣你就要用排除法,就像做選擇題,要將B類的問題先註釋掉,A類裡面的問題才會暴露出來。

16. 2016-07-04

關於該問題,需要注意的是。有時候雖然有個紅叉但是也能執行,可能as校驗導致該問題。另外如果程式碼中沒有什麼問題時,就需要檢視下AndroidManifest.xml是否有錯誤,一般情況下是這個原因導致。只要知道這個即可。

17.2016-07-04

Error:Execution failed for task ':Tongyan_StructureCheck_Library:clean'.
> Unable to delete directory: E:\as_workspaces\TYSubwayInspectionNJ_Reconsitution\StructureCheck_Library\build\intermediates\exploded-aar

按照上面的說明,不能刪除這個目錄,你就手動刪除下

18.2016-07-15

Error:Execution failed for task ':app:clean'.
> Unable to delete directory: E:\as_workspaces\TYSubwayInspectionNJ_Reconsitution\app\build\intermediates\classes\debug\com\tongyan\nanjing\subway

Unable to delete directory 像這樣不能刪除檔案,你就找這個這個資料夾刪除掉,如果不能刪除就粉碎掉。官網的錯誤提示還是比較傻瓜式的,他讓你幹嘛,你就幹嘛就行了。

19.2016-07-18

20.2016-09-14 當Model中的程式碼無法生產R檔案,可以做如下操作,但前提是包中的xml、java程式碼無衝突(保證之前儘量多clean,然後檢視Message)。 21.2016-09-16 當發生如下問題時 1.將下圖中的配置改成你AS中能編譯專案中配置行即可 2.如下圖中的地方也需要注意下(就是講目前你as中能正常執行的專案中的配置替換成這句distributionUrl-更新於20160920) 22.2016-09-23 EditText: layout tag was TextView [WrongViewCast] 場景:程式碼執行、clean、編譯都沒問題,在手機上執行也沒問題,但是使用簽名以後就曝該錯誤。怎麼折騰都不行,但是前提是所有程式碼都是正確的View的型別轉換完全正確。 解決:AActivity在app包下面,但是layou佈局在另外一個Library(下稱B包)中,在解決問題的過程中猜想可能是這個問題導致,最後將B包中本屬於app包下面的佈局檔案移至app包下面就解決了該問題。 23.2016-10-24

Error:(1, 0) Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to "ad3f801955f53e94516853b8f93ac2b9ee8cc4"
<a href="fixGradleElements">Fix plugin version and sync project</a><br><a href="openFile:E:\as_workspaces\PedometerDemo\app\build.gradle">Open File</a>

將該處的配置改成目前能使用的專案的配置

24.2016-10-24

Error:Could not open no_initscript class cache for initialization script 'C:\Users\Rubert\AppData\Local\Temp\asLocalRepo194.gradle' (C:\Users\Rubert\.gradle\caches\2.4\scripts\asLocalRepo194_dzs652nv4687n61mc501sfben\InitScript\no_initscript).
> Failed to create directory 'C:\Users\Rubert\.gradle\caches\2.4\scripts\asLocalRepo194_dzs652nv4687n61mc501sfben\InitScript\no_initscript\classes'

25.2016-11-01 Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException 該問題是由於libs匯入的v4包版本有問題,後來改成下面就可以了
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/Volley.jar')
    compile files('libs/gson-1.7.1.jar')
    compile 'com.android.support:support-v4:22.0.0'
}

26.2016.12.26
> Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

File-->Project-->Structrue-->SDK Location-->JDK location

Use embedded JDK 前面勾去掉,指定一個JDK地址。

27.2017.1.10

Error:com.android.builder.internal.aapt.AaptException: Failed to crunch file E:\as_workspaces\TYSubwayInspectionNJ_Reconsitution3\Tongyan_StructureCheck_Library\build\intermediates\exploded-aar\TYSubwayInspectionNJ_Reconsitution3\Tongyan_Framework_Library\unspecified\res\drawable-hdpi-v4\np_numberpicker_up_disabled_focused_holo_dark.png into E:\as_workspaces\TYSubwayInspectionNJ_Reconsitution3\Tongyan_StructureCheck_Library\build\intermediates\res\merged\androidTest\debug\drawable-hdpi-v4\np_numberpicker_up_disabled_focused_holo_dark.png

修改名稱路徑,避免路徑過長

28.2017.2.16

當你android:targetSdkVersion="22" 再將22改成23時會遇到各種問題,例如編譯不通過,檔案無法寫入(許可權註冊過)。把手機上的app刪除,再安裝即可。

29.2017.2.23

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

30.2017.2.24

Error:A problem occurred configuring project ':app'.
> Unable to find optional library: org.apache.http.legacy

複製程式碼
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId 'com.xxx.xxxe'
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    useLibrary 'org.apache.http.legacy'
}
複製程式碼

31.2017-03-08

Error:Execution failed for task ':app:compileReleaseJava'.
> Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

將此處的勾選去掉,再改成你的jdk根目錄

32.Error:Error converting bytecode to dex:

Cause: com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/net/DatagramSocketClient;

clean

33.2017-04-28

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

同第25.

34.2017-04-28

android API23 無法使用HttpClient無法使用,在build.gradle檔案中加入下面程式碼即可

android {
    useLibrary "org.apache.http.legacy"
}