更新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')

圖片.png

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

OK,了解了gradle 3.4的新java plugin library依賴關系,因為android plugin 3.0使用gradle 4.0,所以這些自然也會引入了,下面這張表可以簡單說明:

圖片.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.
<a href="openFile:D:----------------------\build.gradle">Open File</a>

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!

解決問題

圖片.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'    
 }
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容