第一章 Android Studio常用快捷键

  • ctrl + shift + (+-) 代码伸展收缩

第二章 Android Studio常用插件

快速添加依赖

1
地址:https://github.com/wuyr/GoogleLibraryVersionQuerier

第三章 常用配置

3.1 基础配置

1. AndroidStudio打开的类显示多行

右击类-去掉 Show Tabs In single Row
http://blog.csdn.net/shayubuhuifei/article/details/78281220

2. code template模板个性化

1
2
3
4
5
6
7
8
9
10
参考博客地址:https://blog.csdn.net/denglxsc/article/details/51188444
step1: 点击 setting>>Editor>>File and code Templates
step2: 选中includes标签
step3: 选中File Header
step4: 黏贴以下内容
/**
* author: ${USER}
* created on: ${DATE} ${TIME}
* description:
*/

第四章 错误集锦

AndroidStudio 编译异常

异常信息:java.lang.OutOfMemoryError: GC overhead limit exceeded

1
2
3
4
5
在build.gradle中的android{}添加如下脚本就可以顺利编译了 
dexOptions {
incremental true
javaMaxHeapSize “4g”
}

Android studio中 SVN新建文件,没有弹出添加到SVN

1
2
3
4
解决办法:
问题是由于在SVN下的某些目录的属性忽略文件导致的,根据以下步骤去掉就可以了。 在你的SVN库的根目录下,右键空白处,选择Properties
单击Remove按钮,选择Recursive干掉这个属性,单击Ok就可以了。
参考博客: https://blog.csdn.net/yujiayinshi/article/details/51381942

解决支持库版本兼容问题

异常信息:all com.android.support libraries must use the exact same version specification

1
2
3
4
5
6
7
8
9
10
11
12
在app build.gradle中添加:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.3.1'
}
}
}
}
参考链接:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2017/0910/8491.html

安卓项目更名

无法通过shift + F6 来重命名项目名,要修改,只能先关闭Android Studio,然后才在文件路径中找到项目,去修改文件夹的名称,
修改完成后,记得删除APP的build目录,否则无法编译安装到手机上
参考地址:https://blog.csdn.net/benbenxiongyuan/article/details/52125899

Android studio 使用多种BuildTypes时候报错

1
2
3
4
5
6
7
8
9
10
11
12
13
Unable to resolve dependency for ':app@dev/compileClasspath': Could not resolve project :baselibrary.
Open File
Show Details
Unable to resolve dependency for ':app@dev/compileClasspath': Could not resolve project :upplayer.
Open File
Show Details

Unable to resolve dependency for ':app@devUnitTest/compileClasspath': Could not resolve project :baselibrary.
Open File
Show Details
Unable to resolve dependency for ':app@devUnitTest/compileClasspath': Could not resolve project :upplayer.
Open File
Show Details

​ 报错原因:app中buildTypes集合不是library的buildTypes集合子集,即app中buildType属性preview在依赖的library中找不到。

​ 解决方案:http://www.jcodecraeer.com/a/anzhuokaifa/Android_Studio/2017/1026/8646.html
​ 在自己构建的BuildType类型中,包含library中已有的buildType
​ 如:matchingFallbacks = [‘release’, ‘debug’]

模拟器无法启动

提示:Emulator: emulator: ERROR: Not enough**space to create userdata partition

解决:模拟器所在硬盘空间不足,释放空间后,可成功启动模拟器

Android Studio 3.5编译问题

编译后,无法请求网络,在Android Q手机上,加了网络权限还是不行,报错信息如下:

1
OkHttp: <-- HTTP FAILED: java.net.SocketException: socket failed: EPERM (Operation not permitted)

解决办法:卸载重新安装即可

参考地址:https://stackoverflow.com/questions/56266801/java-net-socketexception-socket-failed-eperm-operation-not-permitted

编译失败

异常信息:Preview is unavailable until a successful build

1
解决办法:rebuild project

打包报错

安卓打包报错:Execution failed for task ‘xxx:verifyReleaseResources’

解决参考链接:https://www.jianshu.com/p/6729bca200ea

当时打包的时候,总是报错,library中的AndroidManifest.xml,但是直接编译运行则不会报错

参考文档上的方法,将library中的环境改为和APP的一致,仍然报错,最后发现APP中开启了混淆,library中minifyEnabled = false ,删掉这段代码后,打包成功

1
2
3
4
5
6
//    buildTypes {
// release {
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// }
// }
  1. 报错Command line is too long. Shorten command line for *** or also for Spring Boot default configuration

    解决方案!
    修改项目下 .idea\workspace.xml,找到标签 , 在标签里加一行

中文乱码

Eclipse项目导入Android studio 中,中文乱码问题

解决方案:因为以前Eclipse项目的默认编码是GBK,android studio 项目默认是Utf-8,所以需要修改编码

打开Settings-Editor - File Encoding,将Project encoding改为GBK,此时项目代码中中文会正常显示,但是编译的时候,仍然会报错,提示中文乱码,还需要配置一下:

1
2
3
compileOptions  {
encoding "GBK"
}

support和androidx兼容问题

参考博客:https://blog.csdn.net/weixin_41618522/article/details/87165593

1、Refactor–>Migrate to AndroidX

2、向gradle.properties添加以下内容:

1
2
android.enableJetifier=true
android.useAndroidX=true

编译抽疯

异常信息:windows CreateProcess error=206, 文件名或扩展名太长

解决办法:百度搜索的各种方法都不行,最后删除项目,重新clone

adb wifi offline问题

当adb wifi连接后,有时候会出现offline,如何解决呢?在开发者模式中,关闭开发者,再开启,然后连接远程设备

1
adb connect ip地址 //如:adb connect 192.168.3.19

第五章 版本升级问题

版本3.5

1.AndroidStudio 3.5格式化xml

问题:文件出现自动改变xml元素位置问题

解决办法:https://blog.csdn.net/yinxing2008/article/details/99991545