2016-08-04 70 views
0

我在應用程序中出現了outofmemory異常錯誤。我在下面的build.gradle應用中添加了這個dexoptions代碼,但它不起作用。OutofMemory錯誤異常與Android Studio 2.1.2中的Gradle解析選項

apply plugin: 'com.android.application' 

    android { 
     compileSdkVersion 23 
     buildToolsVersion "23.0.2" 
     useLibrary 'org.apache.http.legacy' 


     defaultConfig { 
      applicationId "Package name" 
      minSdkVersion 16 
      targetSdkVersion 23 
      versionCode 1 
      versionName "1.0" 

      multiDexEnabled true 

     } 
     buildTypes { 
      release { 
       minifyEnabled false 
       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
      } 
     } 
     sourceSets { 
      main.java.srcDirs += 'src/main/facebooka' 
     } 

     dexOptions { 
      incremental = true; 
      preDexLibraries = false 
      javaMaxHeapSize "2g" // 2g should be also OK 
     } 
     /* dexOptions 
       { 
        incremental true 
        javaMaxHeapSize "2048M" 
        preDexLibraries = false 
       }*/ 
    } 

    dependencies { 
     compile project(':library1') 
     compile project(':facebooka') 

     compile 'com.android.support:support-v4:23.1.1' 
     compile 'com.android.support:appcompat-v7:23.1.1' 
     compile files('libs/YouTubeAndroidPlayerApi.jar') 
     compile 'com.android.support:design:23.1.1' 

     compile 'com.google.android.gms:play-services:8.4.0' 


     compile 'com.android.support:multidex:1.0.1' 
     compile 'com.devfigas:marshmallow-permission:0.0.9' 

    } 

在Android的工作室版本2.1.1此代碼工作正常,但是當我試圖版本相同的代碼2.1.2

dexOptions { 
      incremental = true; 
      preDexLibraries = false 
      javaMaxHeapSize "2g" // 2g should be also OK 
     } 
+1

這意味着你正在使用太多的內存。您應該嘗試減少內存中加載的資源數量。如果設備沒有2G,那麼製作堆2G不會奇蹟般地解決您的問題。 – litelite

+0

請勿全部**添加Google Play服務。看看是否可以解決問題 –

+0

在構建應用程序時,您的應用程序或PC上是否有OutOfMemory?如果在構建過程中發生OOM,則僅適用於Dexoptions。 – Christopher

回答

0

嘗試應用下您的清單中加入這一行:

<application 
    android:largeHeap="true" > 
</application>