Android Studio 3.0 升级编译错误分析

android-studio 专栏收录该内容
2 篇文章 0 订阅

今天Google推送了Android Studio 3.0的升级
升级完了以后,AS要求将
gradle tools升级到3.0.0

classpath 'com.android.tools.build:gradle:3.0.0'

gradle也升级到gradle-4.1-all.zip

升级完了以后,编译就出现各种问题

问题1

Error:(130, 0) Cannot set the value of read-only property ‘outputFile’ for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl

原来用来重命名打包后的apk方法不能用了
原来的方法
variant.outputs[0].outputFile = new File(apkDir, filename)
要改成下面的方法
variant.outputs.all {output ->
outputFileName = filename
}

问题2

    2. Error:Cannot choose between the following configurations of project :videoplayer:
      - debugApiElements
      - debugRuntimeElements
      - releaseApiElements
      - releaseRuntimeElements
    All of them match the consumer attributes:
      - Configuration 'debugApiElements':
          - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
          - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
      - Configuration 'debugRuntimeElements':
          - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
          - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.
      - Configuration 'releaseApiElements':
          - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
          - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
      - Configuration 'releaseRuntimeElements':
          - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.

以前Android Studio不会自动匹配Library中的BuildTypes
3.0以后 现在就可以自动匹配了(只要app选择了debug,后面会自动选中debug,release也是一样)
这里写图片描述

当然 需要注意的是 Library中需要添加buildTypes跟app的一样,
比如App中有 release debug debugTest
那么Library中也要有这3个
直接空着也没关系
这里写图片描述

问题3

如果你用了类似butterknife
需要做如下改动
project的build.gradle文件中删除

  • classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’

module的build.gradle文件中删除

  • apply plugin: ‘android-apt’

module的build.gradle文件中替换

//apt 'com.jakewharton:butterknife-compiler:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

问题4

D:\Dev\android\workspace\xxxx\xxxx\videoui\build\intermediates\bundles\debug\res\values\values.xml
Error:(84, 5) error: style attribute '@android:attr/windowEnterAnimation' not found.
Error:(84, 5) error: style attribute '@android:attr/windowExitAnimation' not found.
D:\Dev\android\workspace\xxxxx\xxxx\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Error:(2556) style attribute '@android:attr/windowEnterAnimation' not found.
Error:(2557) style attribute '@android:attr/windowExitAnimation' not found.
Error:failed linking references.
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:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 13s
Information:9 errors
Information:0 warnings
Information:See complete output in console

解决办法:

在Project/gradle.properties中添加 android.enableAapt2=false

  • 3
    点赞
  • 1
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值