Android Studio常用设置及常见问题

作为Android开发者,使用Android Studio是不可避免的, 目前此篇博客主要记录Android Studio使用中的一些基本设置和常见问题,以便以后在使用中方便查找。

基本设置:

主题颜色设置、修改字体、增加代码悬浮、代码提示不区分大小写、修改注释颜色、禁用插件、更新代码提示框不显示。


1.修改主题颜色

File---->Setting---->Editor---->Colors & Fonts---->General---->Scheme---->选择Darcula即可切换灰色主题。

2.修改字体

File---->Setting---->Editor---->Colors & Fonts---->Font 可修改字体样式、大小、行距等.


3.增加代码悬浮提示

File---->Setting---->Editor---->General---->Other---->Show quick documentation on mouse move 勾选即可。


4.代码提示不区分大小写(默认是区分大小写的)

File---->Setting---->Editor---->General---->Code Completion---->Match case 复选框取消选中即可。


5.Android studio中注释的颜色太浅,如何修改

File -->Setting-->Editor --->Colors Scheme--->Language Deaults--->Comments(右侧界面),进行对应注释颜色设置;


6.禁用插件

File-->Settings --> Plugins ,右侧会显示出已经安装的插件列表,取消勾选即可禁用插件。


7. Android studio使用窗口栏目更新图标,更新代码时,不小心点击到了不再显示对话框

解决办法:File -->Setting-->Version Control --->Comfirmation--->Update--->复选框勾选即可。


8.迁移Eclipse项目,并转换为Studio项目结构

解决办法:Eclipse-->Export-->Android-->Generate Gradle Build files-->使用Android studio导入,此时可能会出现项目结构没有变化,退出项目,进入项目根目录删除掉 .idea文件夹(看不到是因为隐藏了,让其显示隐藏文件),删除之后,重新打开项目即可。


9.代码自动生成作者签名注释

File -->Setting-->Editor --->File and Code Templates--->File Header---> 输入模板即可。


10. 调整堆大小以匹配所需的容量,提升IDE的性能(分配过多内存会降低性能,注意电脑配置与IDE提醒

默认情况下,Android Studio 的最大堆大小为 1280MB。如果您处理的是大项目,或者您的系统有大量 RAM 可用,您可以通过增大 Android Studio 进程(例如核心 IDE、Gradle 守护进程和 Kotlin 守护进程)的最大堆大小来提升性能。

Android Studio 会自动检查可采取的堆大小优化措施,并在检测到性能可以提升时通知您。

如果您使用的是 64 位系统并配有不少于 5 GB 的 RAM,您还可以手动调整项目的堆大小。为此,请按以下步骤操作:

  1. 从菜单栏中依次点击 File > Settings(或在 macOS 上,依次点击 Android Studio > Preferences
  2. 依次点击 Appearance & Behavior > System Settings > Memory Settings
  3. 调整堆大小以匹配所需的容量 ,点击 Apply

更改了 Android Studio 的堆大小,则必须重启 Android Studio 才能让新的内存设置生效。


11.Android Studio重写类方法时,默认引用org.jetbrains.annotations.Nullable包,烦

File -->Setting-->Editor --->Inspection--->Java--->Probable bugs--->

Nullability--->@NotNull/@Nullable problems--->选中--->右侧菜单栏的Configure Annotations---> 在上下的两个选择框中都选择androidx.annotation.NonNull包,然后打上对勾--->

OK--->Apply--->OK即可。


常见问题:

1.导入Android studio结构的项目时,为了保证gradle正常运行或不被卡死,可以采取以下方法:

创建一个新项目,确保其可以编译运行通过,将其( gradle 、 build.gradle)两个文件复制下来,覆盖新的项目中,再进行导入.


2.使用studio更新代码,出现skip : Android studio svn Node remains in conflict

解决办法: 右键出现问题的文件,选择revert ,再使用update即可正常.


3 .Android编译ndk出现以下错误:APP_STL gnustl_static is no longer supported

Error:(xxx) *** Android NDK: APP_STL gnustl_static is no longer supported. Please switch to either c++_static or c++_shared. See https://developer.android.com/ndk/guides/cpp-support.html for more information.    .  Stop.

解决办法:下载最新版的ndk,我的是android-ndk-r16b,找到studio的local.properties文件,将其ndk路径调换掉,然后同步即可解决问题。


4.Android studio升级3.3,项目出现 updating indices Scanning file to index...一直不动的情况,经常卡死,电脑都感觉GG了,重启很多遍,对于网友说的 File -> Invalidate Caches / Restart ,一点用处也没有.

解决办法: 重新下载Android studio 3.2.1或者之前版本,运行项目就ok了. 感觉studio刚出3.3还不稳定,建议使用3.2.1.


5. Android studio打开项目出现警告:External file changes sync may be slow: The current inotify(7) watch limit is too low. More details. 

解决办法:点击more details会跳转一个网站,按照上面的教程一步一步来即可。详细步骤如下:

Ubuntu开发环境下,新建一个文件idea.conf文件,将此内容: fs.inotify.max_user_watches = 524288写入文件,保存;

使用命令行,将文件移动到目标文件目录/etc/sysctl.d下,命令为sudo mv + idea.conf文件路径 + /etc/sysctl.d/ ;

移动完成后,在命令行输入:sudo sysctl -p --system;

重启Android studio即可消除此警告信息。详情参考:https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit


6.升级Android3.4后导入项目,出现错误: Re-download dependencies and sync project (requires network)

解决办法:将gradle-wrapper.properties文件中的  gradle下载版本改为 5.5.5-all.zip即可;


7.AndroidManifest文件中出现代码警告: App is not indexable by Google Search; consider adding at least one Activity with an ACTION-VIEW in...

分析: Activity可以添加ACTION-VIEW来支持Google的deep links,点击链接可以打开我们的App并跳转到相应的界面,还可以传递数据显示具体的页面。

解决办法:

第一种:(逃避) 直接在代码警告区域,Ctrl + Enter键,直接添加以下代码,警告自然消失

tools:ignore="GoogleAppIndexingWarning"
第二种:(继续逃避)
build.gradle(app)--> android 标签内 ,defaultConfig标签之外,加入:

lintOptions {
    disable 'GoogleAppIndexingWarning'
}
第三种:(安排它) 网上教程:添加深度链接: 

https://blog.csdn.net/yingaizhu/article/details/80748688#commentBox

8. Android Studio升级3.6之后,之前项目中的AndroidManifest文件的中的属性ScreenOrientation标签报错;

android:screenOrientation="portrait"

原因分析: 

报错提示为:Expecting 'android:screenOrientation="unspecified"' or '"fullSensor"' for this activity so the user can use the application in any  orientation and provide a great experience on Chrome OS devices.根据提示,意思是:需要将属性的值设置为unspecified或'“ fullSensor,以便用户可以在任何方向使用该程序,并在Chrome OS 设备上提供出色的体验。

但是,我的项目中的已经有很多Activity已经设置为固定方向(横屏或者竖屏),看着红色的警告,十分难受;

解决办法:

第一种:适配横竖屏显示,不限制屏幕方向

第二种:消除红色警告,忽略当前的建议(日后项目再适配,哈哈哈哈,此计甚妙...)

消除红色警告操作:

File-->Settings-->Editor-->Inspections-->Android-->Lint-->Correctness-->Chrome OS-->

将Activity is locked to an orientation 的两个选项取消勾选-->Apply-->OK ;(突然发觉,错误警告没有了,666)


9. Android Studio升级到3.6,xml中的控件出现Lint错误异常(红色下划线),具体错误提示为:MissingConstraints

This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime
 unless you add the constraints  The layout editor allows you to place widgets anywhere on the canvas,
 and it records the current position with designtime attributes (such as layout_editor_absoluteX). 
These attributes are not applied at runtime, so if you push your layout on a device, the widgets may 
appear in a different location than shown in the editor. To fix this, make sure a widget has both 
horizontal and vertical constraints by dragging from the edge connections.  
Issue id: MissingConstraints

原因分析:Studio的Lint代码检查,会检查在使用约束布局时, 视图控件是否添加约束,如果没有会出现红色警告,

上述警告信息即: 建议手动为控件添加约束 或者使用 拖动控件的方式,让视图具有约束;

解决办法:消除红色警告

第一种:为控件添加约束,例如: (为控件添加 左上右的约束) ---------建议使用

    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"

第二种:忽略警告 (不建议直接使用Alt+Enter单独忽略此警告)

    bind:ignore="MissingConstraints"

10. Android Studioand Gradle are using different locations forthe JDK

原因分析:

这种情况是由于使用不同的JDK位置可能会导致Gradle产生多个守护进程 ,首先Android Studio默认下使用的下载时自带的jre,这种jre的功能显然达不到jdk的标准,这会使得开发时可能产生不兼容的问题,当然也可以选择忽略这个警告;

解决方法:

将下载好的jdk重命名为jre,替换掉原来studio总是默认引用的jre,并重新设置jdk路径以及环境变量,同步studio即可。



上述资料来自于网上收集,如果小伙伴发现书写中出现错误,或者有更好的办法解决此问题,欢迎留言和私信。

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值