在GRADLE 進行DEX的可能會遇到內(nèi)存不夠用的情況赚导,錯誤信息大概是java.lang.OutOfMemoryError: GC overhead limit exceeded锻霎。
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
Error:Execution failed for task ':runtime-starter:transformClassesWithDexFor105Debug'.
com.android.build.api.transform.TransformException: 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.8.0_121\bin\java.exe'' finished with non-zero exit value 3
這個時候只需要配置dexOptions的javaMaxHeapSize大小
dexOptions {
javaMaxHeapSize "4g"
}
切換JAVA 1.7到1.8版本遇到得問題,錯誤信息如下:
Error:Error converting bytecode to dex:
Cause: java.lang.RuntimeException: Exception parsing classesError:Execution failed for task ':runtime-starter:transformClassesWithDexFor105Debug'.
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.8.0_121\bin\java.exe'' finished with non-zero exit value 1
解決方法:在Java Libary工程中
apply plugin: 'java'
jar {
sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
}
}
解決ANDROID dex file cannot exceed 64K問題
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
Error:Execution failed for task ':runtime-starter:transformClassesWithDexFor105Debug'.
com.android.build.api.transform.TransformException: 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.8.0_121\bin\java.exe'' finished with non-zero exit value 2
官方解決方案:
- 修改gradle腳本來產(chǎn)生多dex长已。
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
- 修改manifest 使用MulitDexApplication。
<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>
如果有自己的Application昼牛,繼承MulitDexApplication术瓮。如果當前代碼已經(jīng)繼承自其它Application沒辦法修改那也行,就重寫 Application的attachBaseContext()這個方法贰健。
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
更改ANDROID STUDIO版本胞四,錯誤信息如下
Error:Cause: com/android/build/gradle/internal/model/DefaultAndroidProject : Unsupported major.minor version 52.0
解決方法:
修改build.gradle中得com.android.tools.build:gradle:2.0.0版本改為as對應(yīng)版本即可
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}