問題描述
今天在碼代碼時遇到一個莫名其妙的問題,問題是這樣的:
不論 clean project锣咒、rebuild project 還是 make module 都能順利執(zhí)行草讶,但是只要 Run app 就會報如下錯誤
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/connorlin/Program/jdk1.7.0_71/bin/java'' finished with non-zero exit value 134
問題分析
通常,看到 with non-zero exit value 134
首先想到的是依賴沖突了臭家,但細(xì)心點能發(fā)現(xiàn)忽匈,依賴沖突一般是with non-zero exit value 1
或 with non-zero exit value 2
房午,此處卻是134
。
再看Process 'command '/home/connorlin/Program/jdk1.7.0_71/bin/java'' finished with non-zero exit value 134
似乎是JDK相關(guān)丹允。
那么郭厌,首先排除依賴沖突,因為之前是正常的雕蔽,代碼又沒任何改動折柠,是突然出現(xiàn)報錯。再看到JDK批狐,檢查是否JDK配置出問題了扇售,因為我同時裝了sun JDK
和 OpenJDK
。
問題定位
一次定位
開始查看java 版本:
java -version
結(jié)果顯示:
java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-1~trusty1)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)
再看:
update-alternatives --config java
結(jié)果顯示:
有 3 個候選項可用于替換 java (提供 /usr/bin/java)嚣艇。
選擇 路徑 優(yōu)先級 狀態(tài)
------------------------------------------------------------
0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 自動模式
* 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 手動模式
2 /usr/local/jdk/bin/java 255 手動模式
3 /usr/local/jdk1.6.0_30/bin/java 255 手動模式
要維持當(dāng)前值[*]請按回車鍵承冰,或者鍵入選擇的編號:
證明JDK環(huán)境配置沒錯。
接著食零,把Android Studio JDK改為OpenJDK:
/home/connorlin/Program/jdk1.7.0_71
改為
/usr/lib/jvm/java-7-openjdk-amd64
再次編譯 Run app困乒,再次報錯,但本次報錯與上次不一樣:
Error:Failed to complete Gradle execution.
Cause:
Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
居然Gradle build daemon
異常贰谣,那肯定不是代碼的問題了娜搂。
二次定位
后來迁霎,無意中發(fā)現(xiàn)在項目跟路徑下有多個類似hs_err_pid11776.log
文件,其內(nèi)容節(jié)選如下:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fcac7773d44, pid=11776, tid=140508865505024
#
# JRE version: OpenJDK Runtime Environment (7.0_75-b13) (build 1.7.0_75-b13)
# Java VM: OpenJDK 64-Bit Server VM (24.75-b04 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea 2.5.4
# Distribution: Ubuntu 14.04 LTS, package 7u75-2.5.4-1~trusty1
# Problematic frame:
# V [libjvm.so+0x82ad44] MoveAndUpdateClosure::do_addr(HeapWord*, unsigned long)+0xa4
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please include
# instructions on how to reproduce the bug and visit:
# http://icedtea.classpath.org/bugzilla
#
--------------- T H R E A D ---------------
Current thread (0x00007fcac0023800): GCTaskThread [stack: 0x00007fcac4f42000,0x00007fcac5043000] [id=11785]
siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR), si_addr=0x00000000007d0038
Registers:
RAX=0x00000000007d0020, RBX=0x00007fcac5041cb0, RCX=0x0000000000000000, RDX=0x00000000007d0020
RSP=0x00007fcac5041ba0, RBP=0x00007fcac5041be0, RSI=0x00000000007d0020, RDI=0x00000000c47529c0
R8 =0x00007fcaa5800000, R9 =0x00007fcac7d0b420, R10=0x00000000030c9100, R11=0x00007fcac850f810
R12=0x0000000000000001, R13=0x0000000000000008, R14=0x00007fcac007abe0, R15=0x00000000c47529b8
RIP=0x00007fcac7773d44, EFLAGS=0x0000000000010202, CSGSFS=0x0000000000000033, ERR=0x0000000000000004
TRAPNO=0x000000000000000e
通過查看百宇,其中:
--------------- T H R E A D ---------------
Current thread (0x00007fcac0023800): GCTaskThread [stack: 0x00007fcac4f42000,0x00007fcac5043000] [id=11785]
siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR), si_addr=0x00000000007d0038
表明異常時正在運行GCTaskThread
垃圾回收線程欧引,再看到后面還有一段:
VM Arguments:
jvm_args: -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8 -Duser.country=CN -Duser.language=zh -Duser.variant
java_command: org.gradle.launcher.daemon.bootstrap.GradleDaemon 2.10
Launcher Type: SUN_STANDARD
似乎是內(nèi)存不足引起的。
問題解決
一次解決
嘗試將 HeapSize 調(diào)大恳谎,在 app level的build.gradle中配置:
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g" // 調(diào)大 HeapSize
}
很遺憾,問題依然憋肖! 那還原此修改因痛,防止二次事故。
二次解決
實在沒辦法岸更,那嘗試重啟大法
吧鸵膏!
當(dāng)然,不是簡單的重啟怎炊,先要清除緩存再重啟Android Studio谭企。
Android Studio -> File -> Invalidate Caches / Restart ..
最后,發(fā)現(xiàn)重啟大法
果然好用评肆,居然順利跑起來了债查,目前為止沒有再出現(xiàn)該問題。
問題結(jié)果
通過清除Android Studio緩存來解決該問題:
在 Android Studio 的 File
菜單中選擇 Invalidate Caches / Restart ..
來清理緩存并重啟Android Studio瓜挽。
Android Studio -> File -> Invalidate Caches / Restart ..
但個中緣由卻并不清楚盹廷,暫且記錄下來,望知情人士指教久橙!
That's all!