当前位置:   article > 正文

Android Studio中报错的问题_android studio error: could not create the java vi

android studio error: could not create the java virtual machine.

(1)

在32位系统下,往Android Studio中导入一个已有的项目后,如果运行时报错如下:

  1. Error: Could not create the Java Virtual Machine.
  2. Error: A fatal exception has occurred. Program will exit.
  3. Invalid maximum heap size: -Xmx4g
  4. The specified size exceeds the maximum representable size.
  5. Error:Execution failed for task ':MyProject:dexDebug'.

原因可能是该项目中有JVM的定义超出了32位系统所能支持的最大内存,在项目的各级build.gradle中查找javaMaxHeapSize关键字,你将会看到:

  1. dexOptions {
  2. javaMaxHeapSize "4g"
  3. }

只要将4g改为1g:

  1. dexOptions {
  2. javaMaxHeapSize "1g"
  3. }

或者直接删除此3行。
保存后,重新运行即可。

(2)

往Android Studio中导入一个已有的项目后,如果同步时报错如下:

Error:Configuration with name 'default' not found.

可能原因是gradle没有找到相应的模块,请查看settings.gradle文件中的配置是否正确,以及目录是否存在。

(3)

如果出现如下错误:

  1. Error:Unable to load class 'org.codehaus.groovy.runtime.StringGroovyMethods'.
  2. Possible causes for this unexpected error include:<ul><li>You are using JDK version 'java version "1.7.0_71"'. Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause class loading errors in Gradle.
  3. Please update to a newer version (e.g. 1.7.0_67).
  4. <a href="open.project.structure">Open JDK Settings</a></li><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
  5. <a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
  6. <a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

原因可能是项目根目录的gradle/wrapper/gradle-wrapper.properties文件中的distributionUrl定义与jdk版本不符。
比如原先定义如下:

distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip

修改为:

distributionUrl=http\://services.gradle.org/distributions/gradle-2.4-all.zip

(4)

运行时出现如下错误:

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

可能原因是项目引入了重复的jar包,或者因为引入的jar包中包含相同的文件。解决方法是删除冗余的jar包或者删除jar包中冗余的文件。

(5)

运行时出现如下错误:

  1. Error:Execution failed for task ':Uplus:dexDebug'.
  2. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files (x86)\Java\jdk1.7.0\bin\java.exe'' finished with non-zero exit value 1

可能原因是在64位系统上使用了32位的jdk,换用64位的jdk可能会解决此问题。

(6)

编译时,如果出现如下错误:

java.lang.OutOfMemoryError: GC overhead limit exceeded

原因可能是内存不够,可以在build.gradle中的android{}添加如下内容就可以顺利编译了 

  1. dexOptions {
  2. javaMaxHeapSize "4g"
  3. }

(7)

运行时出现如下错误弹窗:

ADB not responding. If you'd like to retry, then please manually kill "adb.exe" and click 'Restart'

可能原因是系统中的其他程序占用了5037端口,在cmd中,运行:netstat -ano | findstr "5037",就可以看到类似如下的信息:

TCP    127.0.0.1:5037         0.0.0.0:0              LISTENING       5252

这说明PID为5252的程序占用了5037端口,所以在cmd中,运行:tasklist,即可看到类似如下的信息:

  1. 映像名称 PID 会话名 会话# 内存使用
  2. ========================= ======== ================ =========== ============
  3. System Idle Process 0 Services 0 24 K
  4. System 4 Services 0 4,572 K
  5. smss.exe 280 Services 0 900 K
  6. csrss.exe 412 Services 0 4,344 K
  7. adb.exe 5252 Console 1 5,988 K

我们看到此处PID为5252的进程是一个adb.exe,这说明另外一个adb实例占用了5037端口,所以运行:taskkill /im adb.exe /f,会看到类似如下的信息:

成功: 已终止进程 "adb.exe",其 PID 为 5252

至此,已经将PID为5252的进程关闭,此时可以点击'Restart'按钮重新启动Android Studio中的adb了。

(8)

当执行:Build->Generate Signed APK...,进行签名打包时报错:

  1. Error:org.gradle.api.internal.changedetection.state.FileCollectionSnapshotImpl cannot be cast to org.gradle.api.internal.changedetection.state.OutputFilesCollectionSnapshotter$OutputFilesSnapshot
  2. Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
  3. <a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
  4. <a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

可能原因是gradle的问题。解决方法是清空项目根目录下.gradle目录下的所有文件和目录,然后重新编译、打包即可。

(9)

当执行:Build->Generate Signed APK...,进行签名打包时报错:

  1. Error:Execution failed for task ':UplusTV:lintVitalRelease'.
  2. > Lint found fatal errors while assembling a release target.
  3. To proceed, either fix the issues identified by lint, or modify your build script as follows:
  4. ...
  5. android {
  6. lintOptions {
  7. checkReleaseBuilds false
  8. // Or, if you prefer, you can continue to check for errors in release builds,
  9. // but continue the build even when errors are found:
  10. abortOnError false
  11. }
  12. }
  13. ...
  14. Error:(1) Error: In Gradle projects, always use http://schemas.android.com/apk/res-auto for custom attributes [ResAuto]

可能原因是代码不规范,但是如果修改代码的话,可能需要修改很多地方,费时费力。比较简单的解决方法是在build.gradle文件中添加:

  1. lintOptions {
  2. checkReleaseBuilds false
  3. abortOnError false
  4. }

(10)

编译运行时出现如下错误:

  1. Error:FAILURE: Build failed with an exception.
  2. * What went wrong:
  3. Execution failed for task ':MyModule:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug'.
  4. > java.io.IOException: Failed to delete E:\workspace\Pro-test\MyModule\build\intermediates\intermediate-jars\debug\classes.jar
  5. * Try:
  6. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
  7. * Get more help at https://help.gradle.org
  8. BUILD FAILED in 3s

原因不明,解决方法可以试试:
依次选择菜单:Build->Rebuild Project,然后重新编译运行。
如果上述操作不起作用,可以重启Android Studio。

(11)

编译运行时出现如下错误:

Error:No such property: GradleVersion for class: JetGradlePlugin

可能原因是Android Studio版本(GradlePlugin)和Gradle版本不匹配。
解决方法有2种:
1.编辑项目中的文件:gradle/wrapper/gradle-wrapper.properties
修改这一行:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip
改成当前支持的版本(具体版本根据Android Studio的版本而定):
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
2.如果上述方法不行,就要考虑更换Android Studio版本了。

(12)

编译运行时出现如下错误:

Caused by: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details

可能原因是资源定义没找到,可以在Terminal中输入:gradlew compileDebugSources,查看具体错误。

(13)

编译运行时出现如下错误:

No slave process to process jobs, aborting

原因不明,解决方法可以试试重启Android Studio。

(14)

编译运行时出现如下错误:

Dex archives: setting .DEX extension only for .CLASS files

原因不明,解决方法可以试试:
依次选择菜单:Build->Rebuild Project,然后重新编译运行。
如果上述操作不起作用,可以重启Android Studio。

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/235371
推荐阅读
相关标签
  

闽ICP备14008679号