升级到Android Studio3.x遇到的问题及解决方案
- 升级到Android Studio3.x遇到的问题及解决方案
- 转 https://www.2cto.com/kf/201711/695736.html
升级到Android Studio3.0遇到的问题及解决方案,前些天,google正式发布了Android Studio3.0。看这个版本号,这次是个大更新。升级后发现编译确实有很大的提升,还有最新的错误调试工具,总之,这次的更新google还是很有诚意的。
下载
Andriod Studio3.0下载
遇到的问题
1.flavorDimensions
错误日志
|
1
|
Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html |
原因:gradle3.0需要使用flavorDimensions做多版本打包,修改如下:
|
1
2
3
4
5
6
7
|
android { //... defaultConfig { //... flavorDimensions "dimen" }} |
然后在productFlavors中做相应的修改
|
1
2
3
4
|
productFlavors { productA { dimension "dimen" } productB { dimension "dimen" }} |
配置多个flavorDimensions
|
1
2
3
4
5
6
7
8
9
10
11
12
|
android { //... defaultConfig { //... flavorDimensions "dimenA","dimenB" }}productFlavors { productA { dimension "dimenA" } productB { dimension "dimenB" } productC { dimension "dimenA" }} |
2.apk命名
错误日志
|
1
|
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=busDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl. Open File |
之前的代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) { def fileName = "XXX-${defaultConfig.versionCode}-${defaultConfig.versionName}-${releaseTime()}-${productFlavors.name[0]}" if (variant.buildType.name == 'release') { fileName += '.apk' } else if (variant.buildType.name == 'debug') { fileName += '_debug.apk' } else { fileName += '_other.apk' } output.outputFile = new File(outputFile.parent, fileName) } } } |
gradle3.0 each替换为all,output.outputFile替换为outputFileName,不需要new File了,修改后的代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
applicationVariants.all { variant -> variant.outputs.all { def fileName = "XXX-${defaultConfig.versionCode}-${defaultConfig.versionName}-${releaseTime()}-${productFlavors.name[0]}" if (variant.buildType.name == 'release') { fileName += '.apk' } else if (variant.buildType.name == 'debug') { fileName += '_debug.apk' } else { fileName += '_other.apk' } outputFileName = fileName } } |
需要注意的是,使用Build->Generate Signed APK…的时候,生成的apk包会放在一个以渠道名命名的文件夹下
3.Annotation processors must be explicitly declared now.Please add them to the annotationProcessor configuration.
错误日志
|
1
2
3
4
5
|
Error:Execution failed for task ':app:javaPreCompilePreProductDebug'.> Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration. - butterknife-7.0.1.jar (butterknife-7.0.1.jar) Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future. See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details. |
修复方案
|
1
2
3
4
5
6
7
8
9
10
11
|
android { //... defaultConfig { //... javaCompileOptions { annotationProcessorOptions { includeCompileClasspath true } } }} |
4.Aapt2Exception
错误日志
|
1
2
3
4
5
6
7
8
|
Error:(113, 5) error: style attribute '@android:attr/windowEnterAnimation' not found.Error:(113, 5) error: style attribute '@android:attr/windowExitAnimation' not found....Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for detailsError:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for detailsError:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for detailsError:Execution failed for task ':app:processPreProductDebugResources'.> Failed to execute aapt |
解决方案 在gradle.properties中添加如下代码,禁用aapt2编译
|
1
|
android.enableAapt2=false |
5.其他
新版本gradle不需要配置buildToolsVersion
dependencies 引入包的时候是这样的
|
1
2
3
4
5
6
7
8
|
dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') androidTestImplementation ... implementation project ... implementation files ... implementation ... testImplementation 'junit:junit:4.12'}
|
升级到Android Studio3.x遇到的问题及解决方案的更多相关文章
- 【Android Studio安装部署系列】三十、从Android studio2.2.2升级到Android studio3.0之路
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 Android Studio 3.0的新功能 https://mp.weixin.qq.com/s/2XmVG4mKEDX6-bvZ ...
- 【Android Studio安装部署系列】三十五、从Android studio3.0.1升级到Android studio3.1.4【以及创建android p模拟器的尝试(未成功)】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 因为想要使用Android P模拟器,所以需要将Android Studio升级到3.1版本以上. Android P模拟器的最低版 ...
- 【Android Studio安装部署系列】三十六、从Android Studio3.1.4升级到Android studio3.2【以及创建android p模拟器(未成功)】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 因为想要使用Android P模拟器,所以需要将Android Studio升级到3.2版本以上. 按照官网的说法:参考<ht ...
- 【Android Studio安装部署系列】三十七、从Android Studio3.2升级到Android Studio3.4【以及创建Android Q模拟器】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 保持Android Studio开发环境的最新版本. 下载Android Studio3.4 使用Android Studio自带的 ...
- 升级完Android Studio3.2后,打包release出现的错误
升级完Android Studio2.3后,打包release出现的错误 Error:Execution failed for task ':qq:lintVitalRelease'.> Lin ...
- 【Android Studio安装部署系列】三十一、从Android studio3.0.0升级到Android studio3.0.1
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 突然想要升级到较高版本.要跟随潮流嘛,不然就落后了. 下载IDE http://www.wanandroid.com/tools/i ...
- Android Studio3.1.2升级问题:Configuration 'compile' is obsolete and has been replaced with 'implementation'.
每次升级Android Studio时,一般情况下Gradle版本的也会相应的升级,我之前Android Studio 3.0.1.Gradle 是4.1升级后为:Android Studio 3.1 ...
- Android Studio3.1.0升级问题记录
每次升级Android Studio时,一般情况下Gradle版本的也会相应的升级,我之前Android Studio 3.0.1.Gradle 是4.1升级后为:Android Studio 3.1 ...
- Android Studio3.0 新特性 ~ New Features in Android Studio Preview (译文)
原文地址:https://developer.android.google.cn/studio/preview/features/index.html 最新Android Studio版本是Andro ...
随机推荐
- 微信小程序html(wxml)传参
欢迎加入前端交流群交流知识:749539640 习惯了vue.angular用微信小程序有时候真感觉非人类..需要用data-xxx 先说下我们在vue.angular里事件传参 //html < ...
- Oracle笔记(十六) 数据库设计范式
数据库设计范式是一个很重要的概念,但是这个重要程度只适合于参考.使用数据库设计范式,可以让数据表更好的进行数据的保存,因为再合理的设计,如果数据量一大也肯定会存在性能上的问题.所以在开发之中,唯一可以 ...
- LintCode上的一道算法面试题: 数字的统计
说到数字的统计,小时候的数学课大家都应该有学过,但数字太多太复杂的,手动肯定耗时间不说还很容易出错.所以今天分享一下如何用程序来完成. Have you met this question in a ...
- kubernetes之node隔离与恢复
需求: 在硬件升级, 硬件维护等情况下, 我们需要将某些node隔离, kubectl cordon <node_name> #禁止pod调度到该节点上, 在其上运行的pod并不会自动停止 ...
- git远程分支创建,本地分支关联远程分支,第一次发布、更新分支
git远程分支创建,本地分支关联远程分支,第一次发布.更新分支 github托管服务器地址为https://github.com git提交更新代码示意图: 本地与远程进行免密码配置(本地与远程关联) ...
- 一个线程相关的高CPU占用问题的定位
最近在重构项目代码时,发现两个线程同时访问一个加锁的std::list队列时,会出现恶性竞争锁的现象. 具体现象是A线程总是拿不到锁,B线程抢占几次后,A才抢占到. 由于是重构项目,也无法通过回滚代码 ...
- 域知识深入学习一:Active Directory 域服务
AD DS用来组织,管理,控制网络资源 1.1 Active Directory 域服务概述 AD内的directorydatabase(目录数据库)用来存储用户账户,计算机账户,打印机与共享文件 ...
- iOS RAC使用补充
1 延迟执行 [[RACScheduler mainThreadScheduler] afterDelay: schedule:^{ NSLog(@"延迟执行.."); }]; ...
- 理解SqlMapConfig.xml文件
SqlMapConfig.xml mybatis的全局配置文件SqlMapConfig.xml,配置内容如下: properties(属性) settings(全局配置参数) typeAliases( ...
- SQL拼串--小问题大毛病
用字符串拼接SQL串实现动态SQL语句,经常使用. 不过在拼接SQL串中有许多技巧和小陷阱 1.遗漏""和'' 错误案例: 错误结果: 发现没有数据产生..我还以为是连接错了数据库 ...