更新android studio3.0后 更新gradle-4.1-milestone-1-all遇到的坑..

更新gradle版本
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip
和插件
dependencies {
// classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.0.0-alpha7' //distributionUrl=https:
}
后遇到的问题

1 implementation Error:Cannot choose between the following configurations of project :xxxlib:

Error:Cannot choose between the following configurations of project :baselib:

  • 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 'for compile' 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 'for 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 'for compile' 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 'for runtime' but wasn't required.

android studio 3.0以后 添加 本地项目 依赖的方式 compile project(':xxxlib') 改为 implementation project(':xxxlib')
implementation project(':xxxlib')

更新android studio3.0后 更新gradle-4.1-milestone-1-all遇到的坑.._第1张图片
图片.png

2 Error:(18, 24) 错误: 程序包xxx.xxx.xxx不存在

OK,了解了gradle 3.4的新java plugin library依赖关系,因为android plugin 3.0使用gradle 4.0,所以这些自然也会引入了,下面这张表可以简单说明:

更新android studio3.0后 更新gradle-4.1-milestone-1-all遇到的坑.._第2张图片
图片.png

注意:compile,provided,apk 这些过时的依赖现在可以使用,但是在下个版本会移除,所以Google给我们一些时间使用。

3 Cannot set the value of read-only property 'outputFile' for

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

5 All flavors must now belong to a named flavor dimension
Error:A problem occurred configuring project ':app'.

Failed to notify project evaluation listener.
All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
Must apply 'com.android.application' first!

解决问题

更新android studio3.0后 更新gradle-4.1-milestone-1-all遇到的坑.._第3张图片
图片.png
  //    applicationVariants.all { variant ->
    //        variant.outputs.each { output ->
   //            output.outputFile = new File(output.outputFile.parent,
   //                   "xxx" + "_V" +
    //                    defaultConfig.versionName + "_" + defaultConfig.versionCode + "_"
    //                    + "${variant.buildType.name}" + "_" + "${variant.productFlavors[0].name}" +
     //                    ".apk");
    //        }
    //    }

改为

android.applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = "${variant.name}-${variant.versionName}-$
                      {variant.buildType.name}-${variant.productFlavors[0].name}.apk"
    }
}

https://stackoverflow.com/questions/44039762/android-studio-3-0-canary-1-project-refresh-failed
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html?utm_source=android-studio#variant_aware

4 注解更新 Warning:android-apt plugin is incompatible with future version of Android Gradle plugin. Please use 'annotationProcessor' configuration instead.

使用annotationPorcessor代替apt

      dependencies {
                   ...
               annotationProcessor 'com.google.dagger:dagger-compiler:2.2'
               }

5.More than one file was found with OS independent path 'META-INF/rxjava.properties'

   packagingOptions {
       ...
           exclude('META-INF/rxjava.properties')

}

6.ButterKnife 失效

https://github.com/JakeWharton/butterknife/issues/963
https://github.com/JakeWharton/butterknife/issues/999

   dependencies {
       //ButterKnife
      // compile 'com.jakewharton:butterknife:8.2.1'
      // apt 'com.jakewharton:butterknife-compiler:8.2.1'
     //qtip Release alpha version for 3.0 alphas #999 https://github.com/JakeWharto /butterknife/issues/999
      compile 'com.jakewharton:butterknife:8.7.0'
       annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'    
 }

你可能感兴趣的:(更新android studio3.0后 更新gradle-4.1-milestone-1-all遇到的坑..)