Android Studio 3.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也是一样)
Android Studio 3.0 升级编译错误分析_第1张图片

当然 需要注意的是 Library中需要添加buildTypes跟app的一样,
比如App中有 release debug debugTest
那么Library中也要有这3个
直接空着也没关系
Android Studio 3.0 升级编译错误分析_第2张图片

问题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

你可能感兴趣的:(android-studio)