问题描述:
同事给了一个项目让我运行,我打开工程后,本地使用的gradle 3.3版本和com.android.tools.builld:gradle:2.3.2版本都要高于项目本身指定的gradle 2.14.1和2.2.3,使用本地自己的版本没有去下载项目原来指定的版本,build项目没有问题,运行项目,发现运行时间很久,半天都没动静,运行结束发现报错了。
错误如下:
1.Warning:warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.tencent.mm.sdk.openapi) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
大量的这种警告,大概意思就是使用的jar版本太老,需要使用新版本,
不过这个是警告,你不去处理也不会影响项目运行,所以虽然很多,但是别慌,可以不用理他。
2.Error:UNEXPECTED TOP-LEVEL ERROR:
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> 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: Error while executing java process with main class……
这个错误才是项目运行不起来的真正原因,其实也很简单解决,第一行是不是看不懂?但是没关系我看得懂第二行,GC了,所以从看得懂的地方入手,先解决GC,打开你项目中的gradle.properties文件,在文件里增加一行
org.gradle.jvmargs=-Xmx2048m
这个配置就好了,系统默认的大小是1024,我们增大就行了。
备注:其实最简单的方法还是去下载项目指定的gradle版本和com.android.tools.builld:gradle版本,这样基本都不会出现什么问题,但是谁让我们可能网不好呢,唉。