Fix Android AP in Kapt (KT-30632), run Android Kapt IT with AGP 3.3.2

Fixes a bug introduced by the commit 6fa610156e, which led to Kapt
options being imported from Android AP options too early (immediately at
creation time for each Android variant, while the Android plugin added
the options only afterwards).

Move Android subplugin options configuration to the time & scope where
it was prior to 6fa610156e.
This commit is contained in:
Sergey Igushkin
2019-03-27 01:08:04 +03:00
parent ca49e17157
commit 7aed9fd592
5 changed files with 43 additions and 3 deletions
@@ -20,6 +20,14 @@ open class Kapt3Android32IT : Kapt3AndroidIT() {
get() = GradleVersionRequired.AtLeast("4.6")
}
open class Kapt3Android33IT : Kapt3AndroidIT() {
override val androidGradlePluginVersion: AGPVersion
get() = AGPVersion.v3_3_2
override val defaultGradleVersion: GradleVersionRequired
get() = GradleVersionRequired.AtLeast("5.2")
}
class Kapt3Android31IT : Kapt3AndroidIT() {
override val androidGradlePluginVersion: AGPVersion
get() = AGPVersion.v3_1_0
@@ -21,5 +21,6 @@ class AGPVersion private constructor(private val versionNumber: VersionNumber) {
val v3_0_0 = fromString("3.0.0")
val v3_1_0 = fromString("3.1.0")
val v3_2_0 = fromString("3.2.0")
val v3_3_2 = fromString("3.3.2")
}
}
@@ -1,3 +1,5 @@
import org.gradle.util.VersionNumber
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
@@ -21,4 +23,18 @@ allprojects {
maven { url 'https://maven.google.com' }
jcenter()
}
if (VersionNumber.parse(android_tools_version) >= VersionNumber.parse("3.3.0")) {
// Workaround: the AGP 3.3.2 databinding library depends on these exact versions, and the espresso test library
// transitively brings newer incompatible ones. Force these versions:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:26.1.0'
force 'com.android.support:support-core-utils:26.1.0'
force 'com.android.support:support-compat:26.1.0'
force 'android.arch.lifecycle:common:1.0.3'
force 'android.arch.core:common:1.0.0'
}
}
}
}
@@ -41,6 +41,19 @@ android {
dexOptions {
incremental false
}
packagingOptions {
// Workaround for org.jetbrains.kotlin.gradle.Kapt3Android33IT#testRealm
// Android Plugin 3.3.2 fails with:
// Execution failed for task ':transformResourcesWithMergeJavaResForDebug'.
// com.android.builder.merge.DuplicateRelativeFileException: (these appear one by one if you exclude single files)
// - More than one file was found with OS independent path 'kotlin/reflect/reflect.kotlin_builtins'
// - More than one file was found with OS independent path 'kotlin/coroutines/coroutines.kotlin_builtins'
// - More than one file was found with OS independent path 'kotlin/collections/collections.kotlin_builtins'
// - More than one file was found with OS independent path 'kotlin/internal/internal.kotlin_builtins'
// (maybe more)
exclude '**/*.kotlin_builtins'
}
}
repositories {
@@ -772,12 +772,14 @@ abstract class AbstractAndroidProjectHandler<V>(private val kotlinConfigurationT
(kotlinAndroidTarget.compilations as NamedDomainObjectCollection<in KotlinJvmAndroidCompilation>).add(compilation)
}
val subpluginEnvironment = SubpluginEnvironment.loadSubplugins(project, kotlinConfigurationTools.kotlinPluginVersion)
val compilation = kotlinAndroidTarget.compilations.getByName(getVariantName(variant))
applySubplugins(project, compilation, variant, subpluginEnvironment)
}
project.whenEvaluated {
forEachVariant(project) { variant ->
val subpluginEnvironment = SubpluginEnvironment.loadSubplugins(project, kotlinConfigurationTools.kotlinPluginVersion)
val compilation = kotlinAndroidTarget.compilations.getByName(getVariantName(variant))
applySubplugins(project, compilation, variant, subpluginEnvironment)
}
checkAndroidAnnotationProcessorDependencyUsage(project)
}
}