Android Studio问题记录

在GRADLE 进行DEX的可能会遇到内存不够用的情况,错误信息大概是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 classes

Error: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

官方解决方案:

  1. 修改gradle脚本来产生多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'
    }
  1. 修改manifest 使用MulitDexApplication。
    
        
            ...
        
    

如果有自己的Application,继承MulitDexApplication。如果当前代码已经继承自其它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对应版本即可

buildscript {
    
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
        
}

}

你可能感兴趣的:(Android Studio问题记录)