我是Android的新手并尝试在Telegram上为Android运行GitHub源代码,但我遇到了一些可怕的错误,经过几天的谷歌搜索,我什么都没发现!
我只是按照说明操作,但它不起作用。错误说' s Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
但即使在增加最大堆大小之后,它也会抛出相同的错误但内存更多。
BuildVars.java:
public class BuildVars {
public static boolean DEBUG_VERSION = false;
public static int BUILD_VERSION = 821;
public static String BUILD_VERSION_STRING = "3.10";
public static String APP_HASH = "94706fdc9f5d86e2c3749bd8d0a2559e"; //obtain your own APP_HASH at https://core.telegram.org/api/obtaining_api_id
public static String HOCKEY_APP_HASH = "f7a81fd2b9cd40d3a8687311defcfe88";
public static String HOCKEY_APP_HASH_DEBUG = "f7a81fd2b9cd40d3a8687311defcfe88";
public static String GCM_SENDER_ID = "760348033672";
public static String SEND_LOGS_EMAIL = "ssiasoft@gmail.com";
public static String BING_SEARCH_KEY = "afb6312cb4ed4e78b8dfd177c6d174af"; //obtain your own KEY at https://www.bing.com/dev/en-us/dev-center
public static String FOURSQUARE_API_KEY = "HNRPHATHVHEBKXMVVLNTYXOGGUHPUSGVMB33TP2XNOFWMGGV"; //obtain your own KEY at https://developer.foursquare.com/
public static String FOURSQUARE_API_ID = "A9ABCD"; //obtain your own API_ID at https://developer.foursquare.com/
public static String FOURSQUARE_API_VERSION = "20150326";
}
并且这里是完整的错误消息日志:
:TMessagesProj:transformClasses_enhancedWithInstant+reloadDexForArmDebug UP-TO-DATE
:TMessagesProj:incrementalArmDebugTasks
:TMessagesProj:prePackageMarkerForArmDebug
:TMessagesProj:fastDeployArmDebugExtractor
:TMessagesProj:generateArmDebugInstantRunAppInfo
:TMessagesProj:transformClassesWithDexForArmDebug
To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html
Error:UNEXPECTED TOP-LEVEL ERROR:
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
:TMessagesProj:transformClassesWithDexForArmDebug FAILED
Error:Execution failed for task ':TMessagesProj:transformClassesWithDexForArmDebug'.
> 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_40\bin\java.exe'' finished with non-zero exit value 3
Information:BUILD FAILED
Information:Total time: 13 mins 5.264 secs
Information:3 errors
Information:0 warnings
任何人都知道为什么会这样,以及如何让它运行?
我非常感谢那些有电信项目工作的人与我共享该代码。
答案 0 :(得分:3)
正如在日志消息中所说,Gradle需要更多内存,因为它使用Dex In Process功能。
要在进程中运行dex,Gradle守护程序需要更大的堆。 它有大约910 MB。为了更快的构建,增加 Gradle守护程序的最大堆大小超过2048 MB。要做 在项目中设置org.gradle.jvmargs = -Xmx2048M gradle.properties。
Gradle本身是用Java编写的,和任何其他Java程序一样,它的内存量受堆大小的限制。
Heapsize, Stacksize and Garbage Collection Fundamentals
要增加堆大小,请增加堆的最大可用量 - 设置 JVM选项 -Xmx
。尝试设置2GB作为日志消息建议:-Xmx2048M
。在Gradle中,通过在项目 gradle.properties 中编写org.gradle.jvmargs=-Xmx2048M
来完成。此文件位于build.gradle旁边。如果没有,请手动创建一个。
之后,如果错误仍然存在,请尝试明确告诉Dex In Process功能现在有多少内存 - 将其添加到 build.gradle (应用模块)。请注意,它应该小于Gradle可用的内存总量,即如果Gradle有2GB,则为Dex In Process设置1GB:
android {
....
dexOptions {
// To prevent OutOfMemory
javaMaxHeapSize "1G"
}
}
尝试更大的值,实际值取决于项目。
虽然没有此功能可以说构建速度较慢,但请尝试将其关闭。
android {
// ...
dexOptions {
dexInProcess = false
}
}