天天看點

使用android studio過程中遇到的異常

1.dexDebug ExecException 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

原因:在所添加的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.如果依賴工程和主工程中有同名同類型的資源檔案,需要修改依賴工程中的資源名稱編譯時才不會報錯,如果依賴工程中的這個資源檔案是整個工程都不需要用到的,可以直接删掉;

5..Logcat的console中,顯示”no debuggable applications”的問題:Tools→Android→Enable ADB Integration;

6.移除所有support-v4的依賴

configurations {

    all*.exclude group: 'com.android.support', module: 'support-v4'

}

6.14.Execution failed for task ':xxx:validateRelealseSigning'.

> Keystore file E:\code\xxxr\xxx_keystore not found for signing config 'relealse'.

build.gradle目錄中的配置内容為

 //簽名

    signingConfigs {

        relealse {

            storeFile file("../xxx_keystore")

            storePassword "xxx"

            keyAlias "xxx"

            keyPassword "xxx"

        }

    }

../xxx_keystore指的是該工程所在的工作空間目錄,在具體工程目錄的上一級,如果檔案位置放錯會導緻找不到檔案

7.出現下面的異常時

Error:Execution failed for task ':xxx:transformClassesAndResourcesWithProguardForRelease'.

> java.io.FileNotFoundException: E:\testimportintostudio\xxx\proguard.cfg (系統找不到指定的檔案。)

從eclipse中導出的gradle工程,會報這個錯誤

一種方式可以将eclipse中的proguard.cfg這個檔案拷貝到所提示的目錄中

另一種方式可以将Module中的build.gradle中的混淆編譯代碼改為

//加載預設混淆配置檔案

//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'

改為

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

8.導包時報錯This fragment should provide a default constructor,

忽略錯誤

lintOptions { 

  abortOnError false 

  checkReleaseBuilds false 

9.從eclipse中導出的工程在android studio中亂碼

下載下傳超級批量轉碼轉換 --> 将所要轉碼的檔案所在的檔案夾拖到工具中 -- >不管原來是什麼編碼,将編碼方式複選框中選中你所要轉換的編碼格式-->點選開始

注:轉碼之前将代碼複制一份,因為偶爾有個别檔案在轉碼過程中出現異常,代碼隻剩下一半的問題,需将原來的代碼拷貝過去

10.E:\MyApplication3\app\build\intermediates\res\merged\apus\debug\values-v23\values-v23.xml

Error:(4) Error retrieving parent for item: No resource found that matches the given name 

'android:TextAppearance.Material.Widget.Button.Inverse'.

Error:(33) Error retrieving parent for item: No resource found that matches the given name 

'android:Widget.Material.Button.Colored'.

編譯時所需要的資源檔案所需要的SDK版本是23,将編譯的版本改為23就可以了  compileSdkVersion 23

11.

Error:Error converting bytecode to dex:

Cause: Dex cannot parse version 52 byte code.

This is caused by library dependencies that have been compiled using Java 8 or above.

If you are using the 'java' gradle plugin in a library submodule add 

targetCompatibility = '1.7'

sourceCompatibility = '1.7'

to that submodule's build.gradle file.

解決辦法:在android層級添加jackOptions選項

android {
  ...


  compileSdkVersion 23
  buildToolsVersion "24rc2"
  defaultConfig {
  ...
    jackOptions {
      enabled true
    }
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
} 
           

12.Error:A problem occurred configuring project ':app'.

> Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.

解決辦法:在android層級添加jackOptions選項

android {
  ...


  compileSdkVersion 23
  buildToolsVersion "24rc2"
  defaultConfig {
  ...
    jackOptions {
      enabled true
    }
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}