mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(gradle-plugin): add LogSender dependency to all debuggable builds in project
This commit is contained in:
@@ -25,6 +25,7 @@ description = "Gradle Plugin for projects that are built with AndroidIDE"
|
||||
|
||||
dependencies {
|
||||
implementation(projects.buildInfo)
|
||||
compileOnly(libs.tooling.agp)
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package com.itsaky.androidide.gradle
|
||||
|
||||
import com.android.build.api.variant.AndroidComponentsExtension
|
||||
import com.android.build.gradle.AppExtension
|
||||
import com.itsaky.androidide.buildinfo.BuildInfo
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
@@ -29,6 +31,7 @@ import org.gradle.api.Project
|
||||
class LogSenderPlugin : Plugin<Project> {
|
||||
|
||||
companion object {
|
||||
|
||||
private const val LOGSENDER_DEPENDENCY_ARTIFACT = "logsender"
|
||||
private const val LOGSENDER_DEPENDENCY =
|
||||
"${BuildInfo.MVN_GROUP_ID}:${LOGSENDER_DEPENDENCY_ARTIFACT}:${BuildInfo.VERSION_NAME_DOWNLOAD}"
|
||||
@@ -40,12 +43,35 @@ class LogSenderPlugin : Plugin<Project> {
|
||||
"${javaClass.simpleName} can only be applied to Android application projects."
|
||||
}
|
||||
|
||||
val extension = extensions.create("logsender", LogSenderPluginExtension::class.java)
|
||||
val debuggableBuilds = hashSetOf<String>()
|
||||
|
||||
configurations
|
||||
.getByName("${extension.variant}RuntimeOnly")
|
||||
.dependencies
|
||||
.add(dependencies.create(LOGSENDER_DEPENDENCY))
|
||||
val appExtension = extensions.getByType(AppExtension::class.java)
|
||||
appExtension.buildTypes.forEach {
|
||||
if (it.isDebuggable) {
|
||||
logger.debug("Found debuggable build type : '${it.name}'")
|
||||
debuggableBuilds.add(it.name)
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Found ${debuggableBuilds.size} debuggable builds in project '${project.path}': $debuggableBuilds")
|
||||
|
||||
if (debuggableBuilds.isEmpty()) {
|
||||
logger.warn("No debuggable builds found in project '${project.path}'")
|
||||
return@run
|
||||
}
|
||||
|
||||
val androidComponents = extensions.getByType(AndroidComponentsExtension::class.java)
|
||||
androidComponents.onVariants { variant ->
|
||||
val buildType = variant.buildType ?: return@onVariants
|
||||
if (buildType in debuggableBuilds) {
|
||||
logger.info(
|
||||
"Adding LogSender dependency ('${LOGSENDER_DEPENDENCY}')" +
|
||||
" to variant '${variant.name}' of project '${project.path}'"
|
||||
)
|
||||
|
||||
variant.runtimeConfiguration.dependencies.add(dependencies.create(LOGSENDER_DEPENDENCY))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.gradle
|
||||
|
||||
/**
|
||||
* Extension for [LogSenderPlugin].
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
open class LogSenderPluginExtension {
|
||||
|
||||
/**
|
||||
* The name of the variant to which LogSender dependency should be added.
|
||||
*/
|
||||
var variant: String = "debug"
|
||||
}
|
||||
@@ -113,6 +113,7 @@ tests-mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version =
|
||||
tests-mockk = { module = "io.mockk:mockk", version = "1.13.5" }
|
||||
|
||||
# Tooling
|
||||
tooling-agp = { module="com.android.tools.build:gradle", 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