升级到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 details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error: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遇到的问题及解决方案的更多相关文章

  1. 【Android Studio安装部署系列】三十、从Android studio2.2.2升级到Android studio3.0之路

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 Android Studio 3.0的新功能 https://mp.weixin.qq.com/s/2XmVG4mKEDX6-bvZ ...

  2. 【Android Studio安装部署系列】三十五、从Android studio3.0.1升级到Android studio3.1.4【以及创建android p模拟器的尝试(未成功)】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 因为想要使用Android P模拟器,所以需要将Android Studio升级到3.1版本以上. Android P模拟器的最低版 ...

  3. 【Android Studio安装部署系列】三十六、从Android Studio3.1.4升级到Android studio3.2【以及创建android p模拟器(未成功)】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 因为想要使用Android P模拟器,所以需要将Android Studio升级到3.2版本以上. 按照官网的说法:参考<ht ...

  4. 【Android Studio安装部署系列】三十七、从Android Studio3.2升级到Android Studio3.4【以及创建Android Q模拟器】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 保持Android Studio开发环境的最新版本. 下载Android Studio3.4 使用Android Studio自带的 ...

  5. 升级完Android Studio3.2后,打包release出现的错误

    升级完Android Studio2.3后,打包release出现的错误 Error:Execution failed for task ':qq:lintVitalRelease'.> Lin ...

  6. 【Android Studio安装部署系列】三十一、从Android studio3.0.0升级到Android studio3.0.1

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 突然想要升级到较高版本.要跟随潮流嘛,不然就落后了. 下载IDE http://www.wanandroid.com/tools/i ...

  7. 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 ...

  8. Android Studio3.1.0升级问题记录

    每次升级Android Studio时,一般情况下Gradle版本的也会相应的升级,我之前Android Studio 3.0.1.Gradle 是4.1升级后为:Android Studio 3.1 ...

  9. Android Studio3.0 新特性 ~ New Features in Android Studio Preview (译文)

    原文地址:https://developer.android.google.cn/studio/preview/features/index.html 最新Android Studio版本是Andro ...

随机推荐

  1. PHP点击按钮拷贝

    一.PHP中点击按钮拷贝文本,我一个页面有多个按钮,相同颜色的标注代表了相同的列或ID 二.这是HTML代码 <tr> <td>直播流地址(延时60秒)</td> ...

  2. Python学习记录7-继承

    面向对象的三大特性 封装 继承 多态 封装 封装就是对对象的成员进行访问限制 封装的三个级别: 公开,public 受保护的,protected 私有的,private public,private, ...

  3. 微信小程序开发(八)获取手机ip地址

    // succ.wxml <view>手机IP:{{motto.query}}</view> // succ.js var app = getApp() Page({ data ...

  4. C#实现10进制转2进制

    这几天在复习计算机原理,看到二进制忽然想到二进制转10进制的公式,然后转念一想10进制转二进制的公式好像没印象,那索性自己写出来. 结果学渣的我发现,并不能写出来!什么数列,对数,xx函数忘得一干二净 ...

  5. 按照教程自动安装RFNoC时.在使用pip安装pybombs时出现报错,解决办法

    $ sudo apt-get install git $ sudo apt-get install python-setuptools python-dev python-pip build-esse ...

  6. Linux文件系统之目录管理mkdir命令

    mkdir命令 mkdir命令mkdir命令简介mkdir命令用来创建指定的名称的空目录,要求创建用户在当前目录具有权限,并且制定的目录名不能是当前目录中已有的目录. 命令格式mkdir [选项] [ ...

  7. Xftp6 和 Xshell 6 下载与安装使用

    官网地址:https://www.netsarang.com/zh/all-downloads/ 然后进行安装吧,基本没有什么配置. 打开 xftp 连接 Linux,进行文件操作. 然后 名称:随意 ...

  8. MySQL剖析单条查询

    使用SHOW PROFILE SHOW PROFILE命令默认是禁用的,可以通过以下命令修改 SET profiling=1; 当一条查询提交给服务器时,,此工具会记录剖析信息到一张临时表,并且给查询 ...

  9. MyEclipse6.5的速度性能优化大提速(转)

    MyEclipse是Eclipse的插件,也是一款功能强大的J2EE集成开发环境,支持代码编写.配置.测试以及除错.现在看一下MyEclipse6.5版本的速度性能优化大提速.优化MyEclipse6 ...

  10. Comet OJ - Contest #11 D isaster 重构树+倍增+dfs序+线段树

    发现对于任意一条边,起决定性作用的是节点编号更大的点. 于是,对于每一条边,按照节点编号较大值作为边权,按照最小生成树的方式插入即可. 最后用线段树维护 dfs 序做一个区间查询即可. Code: # ...