org.gradle.jvmargs=-Xmx1024m 每次打开AndroidStudio的巨坑

本文记录了一位开发者在长时间未使用Android Studio后遇到的问题:Gradle项目同步失败,运行按钮灰显。错误信息显示为无法启动Java虚拟机,原因可能是分配给JVM的内存超过了系统可用内存。通过修改`gradle.properties`文件,降低`org.gradle.jvmargs`的内存分配值,解决了这个问题。然而,随后又遇到了`Execution failed for task ':app:transformClassesWithDexForDebug'`的错误,最终通过清理并重建项目,以及检查和适配SDK版本解决了所有问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一次用androidstudio的时候觉得还行就是这么操作繁琐了点没想eclipse那样的 快捷键的提示,所以一般尘封不用,有项目需要再打开呗
这里就比较尴尬了

大概两周没再使用android studio ,那时没出现什么问题没怎么去管,后来新建 了工程 发现报错,这心情不好了,运行按钮都灰了

Gradle project sync failed. Basic functionality (eg. editing, debugging)  will not work properly


最直接的方式去打开android studio里的log看里面说了什么

2016-10-13 15:33:15,426 [  18187]   WARN -  radle.project.ProjectSetUpTask -  
2016-10-13 15:33:15,427 [  18188]    INFO - radle.project.ProjectSetUpTask - Unable to start the daemon  process.
This problem might be caused by incorrect configuration of the  daemon.
For example, an unrecognized jvm option is used.
Please refer to  the user guide chapter on the daemon at  
https://docs.gradle.org/2.8/userguide/gradle_daemon.html
Please read the  following process output to find out more:
-----------------------
Error  occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.


Consult IDE log for more details (Help | Show Log) 
2016-10-13  15:33:15,427 [  18188]   INFO - ls.idea.gradle.GradleSyncState - Sync  with Gradle for project 'demo' failed: Unable to start the daemon  process.
This problem might be caused by incorrect configuration of the  daemon.
For example, an unrecognized jvm option is used.
Please refer to  the user guide chapter on the daemon at  
https://docs.gradle.org/2.8/userguide/gradle_daemon.html
Please read the  following process output to find out more:
-----------------------
Error  occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.


Consult IDE log for more details (Help | Show Log) 
2016-10-13  15:33:15,649 [  18410]   INFO -       #com.jetbrains.cidr.lang -  Clearing symbols finished in 0 s. 
2016-10-13 15:33:15,651 [  18412]    INFO -       #com.jetbrains.cidr.lang - Loading symbols finished in 0 s. 
2016-10-13 15:33:15,653 [  18414]   INFO -        #com.jetbrains.cidr.lang - Building symbols finished in 0 s. 
2016-10-13  15:33:15,653 [  18414]   INFO -       #com.jetbrains.cidr.lang - Saving  symbols finished in 0 s. 
2016-10-13 15:40:01,465 [ 424226]   INFO -  indexing.UnindexedFilesUpdater - Indexable files iterated in 907 ms 
2016-10-13 15:40:01,465 [ 424226]   INFO -  indexing.UnindexedFilesUpdater - Unindexed files update started: 1 files  to update 
2016-10-13 15:40:01,480 [ 424241]   INFO -  indexing.UnindexedFilesUpdater - Unindexed files update done in 15 ms 
2016-10-13 15:53:10,841 [1213602]   INFO -  lij.tasks.impl.TaskManagerImpl - Updating issues cache (every 20 min) 



在E启动时为Java虚拟机(JVM)分配的内存大于系统可用内存数,所以没有足够的 空间分配给JVM来创建Object。


这下麻烦大了,我电脑是4G运行内存怎么可能会没内存了呢!!!






在工程下面 有一个报错

没有连接上gradle  org.gradle.jvmargs=-Xmx1024m


这时候 改动下工程里的gradle.properties 文件 在最下面 加上一行

 org.gradle.jvmargs=-Xmx512m


关闭工程 再重新打开android studio ,静静等上2分钟  好了  这时候的demo可 以运行了 不再像是之前运行按钮都是灰色的了

点击运行……没成功~~~~   来……接着往下分析


Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException:  org.gradle.process.internal.ExecException: Process 'command 'D:\Program  Files\Java\bin\java.exe'' finished with non-zero exit value 1



不能创建JVM???大概

10-13 16:47:01.186 2285-2285/yiw 
E/memtrack: Couldn't load memtrack module  (No such file or directory)
10-13 16:47:01.186 2285-2285/yiw
 E/android.os.Debug: failed to load  memtrack module: -2


解决方式 Build > Clean Project  然后再 Rebuild Project  

检测架包和sdk版本问题

最后 发现在 build.gradle里minSdkVersion 和targetSdkVersion 都是23 真机测 试是4.2 所以minSdkVersion 改成了19  这时候我的apk能运行成功了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值