更新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')
2 Error:(18, 24) 錯誤: 程序包xxx.xxx.xxx不存在
OK,了解了gradle 3.4的新java plugin library依賴關系庐镐,因為android plugin 3.0使用gradle 4.0肴熏,所以這些自然也會引入了,下面這張表可以簡單說明:
注意:compile,provided,apk 這些過時的依賴現(xiàn)在可以使用,但是在下個版本會移除,所以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!
解決問題
// 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'
}