Android Studio 使用入门及问题汇总

声明:转载自http://blog.csdn.net/wei_chong_chong/article/details/56280383

之前一直用eclipse+adt做Android开发。曾经尝试使用androidstudio发现内存占用很大,电脑太卡了。现在进入公司了,公司项目使用android studio开发的。现在着手androidstudio吧。

写在前面:使用androidstudio 不要打开360杀毒软件

有人安装androidstudio会发现很卡,可以退出杀毒软件或者直接卸载比如360什么的,或者添加为信任软件,(但是我发现添加为信任软件后提升不明显,后来直接卸载了)

使用入门:

常用快捷键:http://www.cnblogs.com/zyw-205520/p/5231843.html

常用查找快捷键:http://blog.csdn.NET/huangxiaominglipeng/article/details/52525996

(1)字体及样式设置

http://jingyan.baidu.com/article/d8072ac463c406ec95cefd23.html

  (2)删除project或module

http://jingyan.baidu.com/article/359911f542736957fe030687.html

(3)新建项目gradle很慢

手动下载对于的gradle放在本地http://services.gradle.org/distributions

如果上面的网址下载比较慢可以使用下面的网址

国内镜像:第二步,在https://dsx.bugly.qq.com/repository/1 下载Android SDK,这是国内的镜像。速度快。
https://dsx.bugly.qq.com/repository/8 下载Gradle的包。

然后配置:

http://anforen.com/wp/2016/08/dev_install_andorid_studio_gradle_eclipse/

http://anforen.com/wp/2015/11/android-studio-gradle-build-running-slowly/

(4)如何设置每次启动as不自动打开项目

http://jingyan.baidu.com/article/03b2f78c1974d25ea237aef1.html

问题汇总

问题一:真机运行项目提示:

Installation failed with message INSTALL_FAILED_USER_RESTRICTED. It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.
WARNING: Uninstalling will remove the application data!
Do you want to uninstall the existing application?

解决:发现是手机内存不足了,清理一下内存或者卸载几个软件就行了

问题二:布局样式报错

(ps我是接手的老项目,之前没有用过androidstudio,导入后布局样式出错)

 

设计界面布局时显示的错误:

Rendering Problems  Missing styles. Is the correct theme chosen for this layout?   Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.   Failed to find style 'buttonStyle' in current theme (8 similar errors not shown)

预览时控件非常小,而且有些控件无法显示

解决方法如下:

layout预览界面(Graphic Layout),右上角有个Theme的选择项,默认为notitle,根据喜好随意设定值,我们这里设定为android以前默认的Theme.black.(有的同学这样改了还是不行,可以试一下NOTitleBar主题,貌似这里设定的时候一定要和配置文件activity中的主题一致才行,或者这里设置了之后配置文件也要设置一下,不然重启后还是会变回原来的主题,建议clean project一下)或者看一下配置文件中的主题。

配置文件Activity节点和application节点都要看看,我的application节点主题没有设置,只是设置了Activity的主题

问题三:布局显示问题Couldn't resolve resource @dimen/y35    

 

NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts.
Or: Automatically add all missing attributes
Couldn't resolve resource @dimen/y35     

这个跟你选择的设备有关系

这里你应该选择正确的设备,如果是android开发就选android设备,不然可能识别不了px单位的数据

 

问题4:真机调试run debug的时候 Gradle窗口出现下面的提示

android Gradle build finished with 800 error(s) in 3m 4s 218ms

有时候可能可以安装成功,有时候会安装失败

 

解决:

大概原因:build-tool版本低了,比sdk版本低。于是升级了build-tool工具。那么如何升级了,打开sdkManager.exe工具,找到tool项下的build-tool,对其进行升级,试了一下好像没效果。之后升级了as版本到2.3才行了。

 

问题5.rundebug真机调试提示

To do this set org.gradle.jvmargs=-Xmx1536M in the project gradle.properties.

按照提示设置项目下gradle.properties.文件的jvmargs大小就行了。

解决:发现我项目下没有gradle.properties文件。在其它工程下面拷贝一个过来就行了。

 

参考:http://blog.csdn.Net/asmcvc/article/details/30225365

http://blog.csdn.net/romaticxiaoyu/article/details/7241512

原文地址:https://www.cnblogs.com/mochaMM/p/6890834.html