Android Studio 使用技巧

初次使用 Android Studio(后文用 AS 替代),会碰到和 Eclipse 不一样的问题,此外还会踩到这样或那样的“坑”。本文作长期的更新,记录使用 AS IDE 过程遇到的问题。

0. 启动 AS 时,报错“Failed to create JVM: error code -4.”

原因:安装时配置的内存过大,导致内存不够用。

解决办法:找到安装目录的 bin 目录,编辑其中的 studio.ext.vmoptions 文件,设置: -Xmx750m 为: -Xmx512m 即可。保存文件,重新启动。

1. 创建 Project 和 Module

1

Minimum SDK 选择为 API 16:Android 4.1版本

2

新创建的 Project 时,默认的 Module 为 app,上图为该 Module 设置 Activity Name 和 Layout Name。注意:若勾选“Backwords Compatibility (AppCompat)”,则新建的 MainActivity 会继承自 AppCompatActivity。

3

上图为创建新的 Module 。其中 Application/Library name 指应用程序名称,也就是显示在设备上的App名称;Module name 指的是该 Project 中的模块名称。

2. 启动 Android Studio 报错,环境如下:JDK 1.8.xx 32bit

Error: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/3.3/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 1572864KB object heap

解决办法:修改 Project的 gradle.properties内容:org.gradle.jvmargs=-Xmx1536m为:1024即可正常运行。(前者为1.5GB内存空间,修改为后者的1.0GB)

原文地址:https://www.cnblogs.com/CVstyle/p/6556099.html