簡體   English   中英

Android build.gradle問題

[英]Android build.gradle issue

我有這個build.gradle文件:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.example.---"
        minSdkVersion 16
        targetSdkVersion 24
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.android.support:design:24.1.1'
    compile 'com.jpardogo.materialtabstrip:library:1.1.0'
    compile 'com.android.support:support-v4:24.1.1'
    compile 'com.google.android.gms:play-services:9.4.0'
}

加載后構建gradle時,出現以下錯誤:

    Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Error:2 errors; aborting
:app:transformClassesWithDexForDebug FAILED
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> 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_77\bin\java.exe'' finished with non-zero exit value 1

我該如何解決?

嘗試將以下內容添加到您的build.gradle android中:

dexOptions {
    javaMaxHeapSize "4g"
}

另請參閱此處以獲取更多信息。

在API級別11+上運行的應用程序可以在清單中的元素上使用android:largeHeap =“ true”來請求大於正常的堆大小,而ActivityManager上的getLargeMemoryClass()會告訴您該堆有多大。 但是:這僅適用於API級別11+(即Honeycomb及更高版本)。無法保證大堆將達到多大。用戶將感知到您的大堆請求,因為這將迫使其其他應用程序退出RAM終止其他應用程序釋放系統內存以供大堆使用的進程由於#3,而且我希望android:largeHeap被濫用,因此將來可能會放棄對此的支持,或者可能會警告用戶在安裝時進行此設置(例如,您將需要特殊權限)目前,此功能已被輕松記錄在案

查看項目中的gradle.properties文件,您可以看到:

指定用於守護進程的JVM參數。 該設置對於調整內存設置特別有用。 默認值:-Xmx10248m -XX:MaxPermSize = 256m

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

您可以更改它以避免內存不足

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM