com.android.build.api.dsl.ApplicationExtension val extension = project.extensions.getByType(ApplicationExtension::class.java) extension.onVariantProperties { variant -> val manifest = variant.artifacts.get(ArtifactType.MERGED_MANIFEST) // Do something with the manifest }
com.android.build.api.dsl.ApplicationExtension val extension = project.extensions.getByType(ApplicationExtension::class.java) extension.onVariantProperties { variant -> val manifest = variant.artifacts.get(ArtifactType.MERGED_MANIFEST) // Do something with the manifest }
com.android.build.api.dsl.ApplicationExtension val extension = project.extensions.getByType(ApplicationExtension::class.java) extension.onVariantProperties { variant -> val manifest = variant.artifacts.get(ArtifactType.MERGED_MANIFEST) // Do something with the manifest }
com.android.build.api.dsl.ApplicationExtension val extension = project.extensions.getByType(ApplicationExtension::class.java) extension.onVariantProperties { variant -> val manifest = variant.artifacts.get(ArtifactType.MERGED_MANIFEST) // Do something with the manifest }
com.android.build.api.extension.AndroidComponentsExtension val extension = project.extensions.getByType(AndroidComponentsExtension::class.java) extension.onVariants { variant -> val manifest = variant.artifacts.get(ArtifactType.MERGED_MANIFEST) // Do something with the manifest }
com.android.build.api.extension.AndroidComponentsExtension val extension = project.extensions.getByType(AndroidComponentsExtension::class.java) extension.onVariants { variant -> val manifest = variant.artifacts.get(ArtifactType.MERGED_MANIFEST) // Do something with the manifest }
com.android.build.api.variant.AndroidComponentsExtension val extension = project.extensions.getByType(AndroidComponentsExtension::class.java) extension.onVariants { variant -> val manifest = variant.artifacts.get(SingleArtifact.MERGED_MANIFEST) // Do something with the manifest }
com.android.build.api.variant.AndroidComponentsExtension val extension = project.extensions.getByType(AndroidComponentsExtension::class.java) extension.onVariants { variant -> val manifest = variant.artifacts.get(SingleArtifact.MERGED_MANIFEST) // Do something with the manifest }
Version.ANDROID_GRADLE_PLUGIN_VERSION // 7.0.0 return VersionNumber.parse(version) // In your build.gradle.kts compileOnly("com.android.tools:common:30.0.0")
val buildscript = project.rootProject.buildscript val config = buildscript.configurations.getByName("classpath") val artifacts = config.resolvedConfiguration.resolvedArtifacts // Find the Android Gradle plugin dependency val androidGradlePlugin = artifacts.singleOrNull { it.moduleVersion.id.toString().startsWith("com.android.tools.build:gradle:") } ?: error("Could not determine Android Gradle plugin version") // Extract the resolved Android Gradle plugin version val version = androidGradlePlugin.moduleVersion.id.version // 7.0.0 return VersionNumber.parse(version)
val buildscript = project.rootProject.buildscript val config = buildscript.configurations.getByName("classpath") val artifacts = config.resolvedConfiguration.resolvedArtifacts // Find the Android Gradle plugin dependency val androidGradlePlugin = artifacts.singleOrNull { it.moduleVersion.id.toString().startsWith("com.android.tools.build:gradle:") } ?: error("Could not determine Android Gradle plugin version") // Extract the resolved Android Gradle plugin version val version = androidGradlePlugin.moduleVersion.id.version // 7.0.0 return VersionNumber.parse(version)
val buildscript = project.rootProject.buildscript val config = buildscript.configurations.getByName("classpath") val artifacts = config.resolvedConfiguration.resolvedArtifacts // Find the Android Gradle plugin dependency val androidGradlePlugin = artifacts.singleOrNull { it.moduleVersion.id.toString().startsWith("com.android.tools.build:gradle:") } ?: error("Could not determine Android Gradle plugin version") // Extract the resolved Android Gradle plugin version val version = androidGradlePlugin.moduleVersion.id.version // 7.0.0 return VersionNumber.parse(version)
val buildscript = project.rootProject.buildscript val config = buildscript.configurations.getByName("classpath") val artifacts = config.resolvedConfiguration.resolvedArtifacts // Find the Android Gradle plugin dependency val androidGradlePlugin = artifacts.singleOrNull { it.moduleVersion.id.toString().startsWith("com.android.tools.build:gradle:") } ?: error("Could not determine Android Gradle plugin version") // Extract the resolved Android Gradle plugin version val version = androidGradlePlugin.moduleVersion.id.version // 7.0.0 return VersionNumber.parse(version)
manifest -> // Do something with the manifest } // Call the correct code depending on the available version val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) }
manifest -> // Do something with the manifest } // Call the correct code depending on the available version val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) }
manifest -> // Do something with the manifest } // Call the correct code depending on the available version val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) }
manifest -> // Do something with the manifest } // Call the correct code depending on the available version val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) }
manifest -> // Do something with the manifest } // Call the correct code depending on the available version val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) }
manifest -> // Do something with the manifest } // Call the correct code depending on the available version val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) }
manifest -> // Do something with the manifest } // Call the correct code depending on the available version val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) }
manifest -> // Do something with the manifest } // Call the correct code depending on the available version val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) } compileOnly("com.android.tools.build:gradle:4.1.0")
manifest -> // Do something with the manifest } // Call the correct code depending on the available version val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) } compileOnly("com.android.tools.build:gradle:4.2.0")
// Include dependencies in the Groovy classpath tasks.withType<GroovyCompile> { classpath = sourceSets.main.get().compileClasspath } // Include compiled Groovy classes in the Kotlin classpath tasks.withType<KotlinCompile> { classpath += files(sourceSets.main.get().groovy.classesDirectory) }
// Include dependencies in the Groovy classpath tasks.withType<GroovyCompile> { classpath = sourceSets.main.get().compileClasspath } // Include compiled Groovy classes in the Kotlin classpath tasks.withType<KotlinCompile> { classpath += files(sourceSets.main.get().groovy.classesDirectory) } groovy
manifest -> // Do something with the manifest } // Call the correct code depending on the available version val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) } compileOnly("com.android.tools.build:gradle:4.1.0")
compat4Dot1 by sourceSets.creating val compat4Dot2 by sourceSets.creating val compat7Dot0 by sourceSets.creating dependencies { compat4Dot1.compileOnlyConfigurationName("com.android.tools.build:gradle:4.1.0") compat4Dot2.compileOnlyConfigurationName("com.android.tools.build:gradle:4.2.0") compat7Dot0.compileOnlyConfigurationName("com.android.tools.build:gradle:7.0.0") ...
by sourceSets.creating val compat7Dot0 by sourceSets.creating dependencies { compat4Dot1.compileOnlyConfigurationName("com.android.tools.build:gradle:4.1.0") compat4Dot2.compileOnlyConfigurationName("com.android.tools.build:gradle:4.2.0") compat7Dot0.compileOnlyConfigurationName("com.android.tools.build:gradle:7.0.0") ... 3. Compile against multiple versions compat4Dot2 compat4Dot1 compat7Dot0
val version = getAndroidGradlePluginVersion(project) when { version < VersionNumber.parse("4.1.0") -> error("Unsupported AGP version") version < VersionNumber.parse("4.2.0") -> handle4Dot1(project, callback) version < VersionNumber.parse("7.0.0") -> handle4Dot2(project, callback) else -> handle7Dot0(project, callback) }
-> plugin.foo.Dependency foo.bar.Other -> plugin.foo.bar.Other your plugin dependency See https://github.com/johnrengelman/shadow or https://github.com/GradleUp/gr8 for more details your plugin dependency
it can be a problem • Determining the AGP version ◦ Fields from AGP ◦ Gradle APIs • Writing compatible code ◦ Reflection ◦ Groovy ◦ Compiling against multiple versions
it can be a problem • Determining the AGP version ◦ Fields from AGP ◦ Gradle APIs • Writing compatible code ◦ Reflection ◦ Groovy ◦ Compiling against multiple versions • Non-plugin dependencies
it can be a problem • Determining the AGP version ◦ Fields from AGP ◦ Gradle APIs • Writing compatible code ◦ Reflection ◦ Groovy ◦ Compiling against multiple versions • Non-plugin dependencies • Testing
it can be a problem • Determining the AGP version ◦ Fields from AGP ◦ Gradle APIs • Writing compatible code ◦ Reflection ◦ Groovy ◦ Compiling against multiple versions • Non-plugin dependencies • Testing See https://github.com/simonschiller/manifestprinter for a sample project