2016-05-28 67 views
20

我正在將我的項目從eclipse移動到Android Studio。運行我的應用程序時,出現以下錯誤。無法找到任何解決方案。我也啓用了multidex。錯誤:android studio中的任務':app:transformClassesWithDexForDebug'的執行失敗

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1

也是我gradle這個文件是低於

apply plugin: 'com.android.application' 
android { 
compileSdkVersion 23 
buildToolsVersion "23.0.3" 
defaultConfig { 
    applicationId "com.myapp" 
    minSdkVersion 9 
    targetSdkVersion 21 
    multiDexEnabled true 
}buildTypes { 
    release { 
     minifyEnabled true 
     proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-project.txt', 'proguard-google-api-client.txt' 
    } 
    } 
} 
dependencies { 
compile 'com.android.support:support-v4:23.4.0' 
compile 'com.google.android.gms:play-services:+' 
compile 'com.google.http-client:google-http-client-gson:1.20.0' 
compile 'com.google.code.gson:gson:2.1' 
compile 'com.android.support:appcompat-v7:23.4.0' 
compile files('libs/activation.jar') 
compile files('libs/additionnal.jar') 
compile files('libs/android-support-v7-cardview.jar') 
compile files('libs/android-support-v7-recyclerview.jar') 
compile files('libs/commons-logging-1.1.1.jar') 
compile 'com.google.api-client:google-api-client:1.18.0-rc' 
compile 'com.google.api-client:google-api-client-android:1.18.0-rc' 
compile 'com.google.api-client:google-api-client-appengine:1.18.0-rc' 
compile 'com.google.http-client:google-http-client:1.18.0-rc' 
compile 'com.google.http-client:google-http-client-android:1.18.0-rc' 
compile 'com.google.http-client:google-http-client-appengine:1.18.0-rc' 
compile 'com.google.oauth-client:google-oauth-client:1.18.0-rc' 
compile 'com.google.oauth-client:google-oauth-client-appengine:1.18.0-rc' 
compile files('libs/google-api-client-gson-1.18.0-rc.jar') 
compile files('libs/google-api-client-jackson2-1.18.0-rc.jar') 
compile files('libs/google-api-client-java6-1.18.0-rc.jar') 
compile files('libs/google-api-client-servlet-1.18.0-rc.jar') 
compile files('libs/google-http-client-jackson2-1.18.0-rc.jar') 
compile files('libs/google-http-client-jdo-1.18.0-rc.jar') 
compile files('libs/google-oauth-client-java6-1.18.0-rc.jar') 
compile files('libs/google-oauth-client-jetty-1.18.0-rc.jar') 
compile files('libs/google-oauth-client-servlet-1.18.0-rc.jar') 
compile files('libs/GraphView-4.0.1.jar') 
compile files('libs/httpclient-4.0.1.jar') 
compile files('libs/httpcore-4.0.1.jar') 
compile files('libs/jackson-core-2.1.3.jar') 
compile files('libs/jetty-6.1.26.jar') 
compile files('libs/jetty-util-6.1.26.jar') 
compile files('libs/jsr305-1.3.9.jar') 
compile files('libs/jxl.jar') 
compile files('libs/mail.jar') 
compile files('libs/transaction-api-1.1.jar') 
} 
+1

[Android java.exe完成非零退出值1]的可能重複(http://stackoverflow.com/questions/29045129/android-java-exe-finished-with-non-zero-exit-value -1) –

回答

4

這可能是由於以下原因:

  1. 內項目的jar文件之一是使用的谷歌遊戲舊版本服務。

  2. 使用multiDexEnabled truedefaultconfig

  3. 要具體與您的相關性添加類。像

    編譯 'com.google.android.gms:發揮服務,地圖:8.4.0'

不喜歡編譯'com.google.android.gms:play-services:+'

+0

嘗試了這兩個選項,仍然是相同的問題 – user1938357

+0

我更新了我的答案 –

4

請 這種添加到您的gradle這個文件

android { 
... 
defaultConfig { 
    ... 
    multiDexEnabled true 
    } 
} 

也可以增加你的gradle這個下面的依賴

dependencies { 
    compile 'com.android.support:multidex:1.0.1' 
} 

或者其他選項是:在清單文件中,從應用程序標記中的multidex支持庫中添加MultiDexApplication包。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.android.multidex.myapplication"> 
    <application 
     ... 
     android:name="android.support.multidex.MultiDexApplication"> 
     ... 
    </application> 
</manifest> 
+0

試過這個,同樣的問題仍然 – user1938357

+0

嘿,請試試這個。它對我有用 – Naina

48

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1

上限誤差occure由於很多原因的。所以我可以把這個錯誤發生的原因以及如何解決它。

原因1:類文件名的重複

SOLUTION:

當你的一些類文件的重構到一個庫項目。到時候你寫的類文件,所以,仔細檢查的名稱,你沒有任何重複的名稱

原因2:當你有大量的緩存內存

解決方案:

有時如果你有很多的緩存內存,那麼這個錯誤發生,所以解決它。 轉至File/Invalidate caches/Restart,然後選擇Invalidate and Restart它將清除緩存內存。

原因3:當有內部錯誤或使用的Beta版本切換回穩定版本。

SOLUTION:

解決方案只是簡單的去蓋菜單,然後單擊Clean Project和清潔點擊Rebuild Project後。

原因4:當您對系統的內存配置較低時。

SOLUTION:

打開任務管理器,停止未使用的大多數在那個時候這樣就釋放了空間,解決OutOfMemory其他應用程序。

原因5:問題是您的方法數量已超過65K。

SOLUTION:

打開項目build.gradle文件添加

defaultConfig { 
     ... 
     multiDexEnabled true 
    } 

和依賴添加下面一行。

dependencies 
    { 
     compile 'com.android.support:multidex:1.0.0' 
    } 
+5

如果你已經添加multiDexEnabled true,那麼REASON-2對你有幫助。謝謝@Ironman,它幫助我。 – Nils

+0

@Nils很高興知道這一點。 – Ironman

+0

我如何找到方法數? –

1

我什麼都試過,但還是這個錯誤不會去,直到我改變了我的JDK版本

我的JDK版本是7,當我將它更改爲8後,錯誤消失了,如果沒有其他的工作,您可以嘗試它。

8

檢查是否在您的的build.gradle(應用級)啓用與否multidex下dependencies.if不一樣的地方下面

dependecies{ 
multidexEnabled true 
} 

檢查gradle.properties(應用級)。如果你看到下面的代碼之前的線

#org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 

移除#,那麼它應該是這樣的

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 
+0

謝謝!這些解決方案幫助我! –

+0

這個解決方案也適用於我。謝謝 –

2

我已經試過這一個,它爲我工作。 希望它也適用於其他人。

  1. 開放的build.gradle模塊文件
  2. 降級您sdkversion從25到24或23
  3. 添加 'multiDexEnabled真正的'
  4. 評論這一行:編譯「com.android.support:appcompat-v7 :25.1.0'(如果它在'依賴'中)
  5. 同步您的項目 並準備好去。

在這裏我附上截圖來解釋事情。 Go through this steps

樂意幫忙。

謝謝。

1

的臨時解決方案是下面將代碼模塊build.gradle中:

android { 
    aaptOptions.cruncherEnabled = false 
    aaptOptions.useNewCruncher = false 
} 

和同步的項目。

1

或者你可以嘗試這個 -

Extend your Application class with MultiDexApplication instead of Application ! 
1

重複名稱類別

class BackGroundTask extends AsyncTask<String, Void, Void> { 

class BackgroundTask extends AsyncTask<String, Void, Void> { 
-1

我的設置截圖: image

感謝this post

只需在您的設置中關閉即時運行。您可以像我所顯示的那樣輕鬆搜索關鍵字「即時」,並且它會切換到您想要的窗口。

1

我已經嘗試過這一個更多的項目,它爲我工作。注意,解決方案可以配置你的應用程序的multidex:

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.1" 

    defaultConfig { 
      ... 
      minSdkVersion 9 
      targetSdkVersion 25 
    } 

    buildTypes { 
      release { 
       shrinkResources true 
       minifyEnabled true 
       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
      } 
    }} 

dependencies { 
     compile 'com.android.support:support-v4:25.1.0' 
     compile 'com.google.android.gms:play-services:8.3.0' 
     ... 
} 
1

他完整的答案謝謝@Ironman,但是我要補充,根據我所面對的這個問題經歷了我的解決方案。

在的build.gradle(模塊:APP):

compile 'com.android.support:multidex:1.0.1' 

    ... 

    dexOptions { 
      javaMaxHeapSize "4g" 
     } 

    ... 

    defaultConfig { 
      multiDexEnabled true 
    } 

而且,把在gradle.properties以下文件:

org.gradle.jvmargs=-Xmx4096m -XX\:MaxPermSize\=512m -XX\:+HeapDumpOnOutOfMemoryError -Dfile.encoding\=UTF-8 

我應該提到,這些數字是對我的筆記本電腦配置(帶16 GB RAM的MacBook Pro),因此請將它們編輯爲您的配置。

相關問題