mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(gradle-plugin): add support for AGP 7.2.0 in LogSenderPlugin
This commit is contained in:
@@ -67,8 +67,8 @@ configurations {
|
||||
dependencies {
|
||||
implementation(projects.buildInfo)
|
||||
|
||||
add("androidBuildTool", libs.tooling.builderModel)
|
||||
add("androidBuildTool", libs.tooling.agpApi)
|
||||
// use the AGP APIs from the minimum supported AGP version
|
||||
add("androidBuildTool", "com.android.tools.build:gradle:${AGP_VERSION_MINIMUM}")
|
||||
|
||||
testImplementation(gradleTestKit())
|
||||
testImplementation(libs.tests.junit.jupiter)
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
package com.itsaky.androidide.gradle
|
||||
|
||||
import com.android.build.api.AndroidPluginVersion
|
||||
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
|
||||
import com.android.build.api.variant.ApplicationVariant
|
||||
import com.android.build.api.variant.impl.ApplicationVariantImpl
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
@@ -57,7 +57,7 @@ class LogSenderPlugin : Plugin<Project> {
|
||||
val debuggableBuilds = hashSetOf<String>()
|
||||
|
||||
beforeVariants { variantBuilder ->
|
||||
logger.debug(
|
||||
logger.info(
|
||||
"Variant :'${variantBuilder.name}' isDebuggable: ${variantBuilder.debuggable}")
|
||||
if (variantBuilder.debuggable) {
|
||||
debuggableBuilds.add(variantBuilder.name)
|
||||
@@ -75,7 +75,7 @@ class LogSenderPlugin : Plugin<Project> {
|
||||
}
|
||||
|
||||
if (variant.name in debuggableBuilds) {
|
||||
withRuntimeConfiguration(variant) {
|
||||
variant.withRuntimeConfiguration {
|
||||
resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
|
||||
|
||||
val logsenderDependency = project.dependencies.ideDependency(
|
||||
@@ -95,16 +95,10 @@ class LogSenderPlugin : Plugin<Project> {
|
||||
}
|
||||
}
|
||||
|
||||
private fun ApplicationAndroidComponentsExtension.withRuntimeConfiguration(
|
||||
variant: ApplicationVariant,
|
||||
private fun ApplicationVariant.withRuntimeConfiguration(
|
||||
action: Configuration.() -> Unit
|
||||
) {
|
||||
val versionWithConfigsApi = AndroidPluginVersion(7, 3)
|
||||
if (pluginVersion < versionWithConfigsApi) {
|
||||
// The version of AGP that the project uses doesn't provide access to the configurations
|
||||
TODO("Find a way to fetch configurations or drop support for such version")
|
||||
}
|
||||
|
||||
variant.runtimeConfiguration.action()
|
||||
this as ApplicationVariantImpl
|
||||
variantDependencies.runtimeClasspath.action()
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -37,6 +37,12 @@ class AndroidIDEInitScriptPluginTest {
|
||||
assertBasics(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test behavior on minimum supported version`() {
|
||||
val result = buildProject(agpVersion = BuildInfo.AGP_VERSION_MININUM)
|
||||
assertBasics(result)
|
||||
}
|
||||
|
||||
private fun buildProject(
|
||||
agpVersion: String = BuildInfo.AGP_VERSION_LATEST,
|
||||
vararg plugins: String
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/build.gradle.kts
|
||||
|
||||
# Built application files
|
||||
*.apk
|
||||
*.aar
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id("com.android.application") version "8.1.0" apply false
|
||||
id("com.android.library") version "8.1.0" apply false
|
||||
|
||||
}
|
||||
|
||||
tasks.register<Delete>("clean") {
|
||||
delete(rootProject.buildDir)
|
||||
}
|
||||
@@ -116,7 +116,6 @@ tests-mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version =
|
||||
tests-mockk = { module = "io.mockk:mockk", version = "1.13.5" }
|
||||
|
||||
# Tooling
|
||||
tooling-agpApi = { module = "com.android.tools.build:gradle-api", version.ref = "agp-tooling" }
|
||||
tooling-builderModel = { module = "com.android.tools.build:builder-model", version.ref = "agp-tooling" }
|
||||
tooling-gradleApi = { module = "org.gradle:gradle-tooling-api", version.ref = "gradle-tooling" }
|
||||
tooling-slf4j = { module = "org.slf4j:slf4j-api", version = "2.0.7" }
|
||||
|
||||
Reference in New Issue
Block a user