最近公司项目上线了,有一段比较空闲的时间,想着studio 现在已经都在3以上了,以前害怕冒然升级出现问题没有时间修改,趁这次机会更新下我的studio 到目前的最新版本。下面说说我更新的流程以及遇到的各种填坑过程~
一、升级
1、 studio的升级我们可以在studio 的 File | Settings | Appearance & Behavior | System Settings | Updates 里可以查看最新版的studio 并且 下载升级。
2、下载后安装就不用说了,升级后打开studio会提示更新gradle,需要我们下载新的gradle ,流程参考这篇博客
https://blog.csdn.net/aqi00/article/details/82850562
修改project 的 gradle 的配置:主要是添加google() 并且升级gradle的版本号
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
3、应用新的依赖配置
compile变成implementation,在一个module中,例如app,中使用`implementation添加的依赖,其他module是 访问不到的;
provided变成compileOnly 表示依赖仅在编译时可见
apk变成runtimeOnly 表示依赖仅在运行时可见
api 使用此依赖配置的话,其他module也是可以引用到的,但编译时间将会加长
二、填坑之旅
1、升级 gradle 的过程中老是报这个错误: Android Studio Connection refused: connect
网上也搜了好多博客,有的说代理问题,有的说 HTTP Proxy 问题,但是感觉没啥卵用~哎,纠结。 最后直接下载了本地的gradle ,设置本地的gradle ,这个问题解决了。
gradle.properties 文件中添加:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
2、Error:All flavors must now belong to a named flavor dimension. Learn more at ... 渠道打包gradle配置问题:
以前的渠道包配置:
productFlavors {
shb{}
yingyongbao{}
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
升级后需要设置 flavorDimensions "xx"
flavorDimensions "chanel"
productFlavors {
yingyongbao {
dimension "chanel"
}
shb {
dimension "chanel"
}
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
3、The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin.
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
instrumentTest.setRoot('tests')
}
是 instrumentTest.setRoot(‘tests’) 出问题了,当前gradle版本 instrumentTest 已被弃用,可以使用androidTest 替用。
4、org.gradle.api.resources.ResourceException: Could not get resource
5、Android Output: error: invalid configuration '480x800'
这个问题是布局适配问题,以前项目layout_480x800 直接用这个文件适配分辨率为480x800的机型,但是studio 3.0以上好像不能直接用分辨率来进行布局适配,改成layout_hdpi就可以了。
6、java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception:
资源文件问题,最后发现是 ids 设置
<item name="recycler_id" type="id">home_layout</item>
改成
<item name="recycler_id" type="id"></item>
就解决了。
7、Android java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
这个问题知道是清单列表的问题,根据merged manifest 错误提示也更改了错误,可是改来改去还是报这个错误,我也是没辙了,最后直接清除缓存给解决了,现在也不知道问题出在哪里,估计就是缓存垃圾造成的错误。哎~
8、:rent:mergeYingyongbaoShbDebugResources
运行项目的时候老是编译不通过,报这个错误,以为jar包或者依赖重复了,检查了没有,又觉得会不会是缓存问题,删除build 文件重新编译,还是不行,又关了studio 重启还是没辙,我也没法子了,撤了。~~ 结果第二天来打开电脑重新运行,竟然通过了,没有这个问题了,呜呜,我也搞不懂studio 的这波操作是什么意思了。