Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core.gradle-plugin): 当Shadow dimension被覆盖时报错提示 #875

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.tencent.shadow.core.gradle

import com.android.build.gradle.AppExtension
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.api.ApplicationVariant
import com.tencent.shadow.core.gradle.extensions.PackagePluginExtension
import com.tencent.shadow.core.manifest_parser.generatePluginManifest
import com.tencent.shadow.core.transform.ShadowTransform
Expand Down Expand Up @@ -100,12 +101,16 @@ class ShadowPlugin : Plugin<Project> {

private fun createGeneratePluginManifestTasks(project: Project) {
val appExtension: AppExtension = project.extensions.getByType(AppExtension::class.java)
appExtension.applicationVariants.filter { variant ->
val pluginVariants = appExtension.applicationVariants.filter { variant ->
variant.productFlavors.any { flavor ->
flavor.dimension == ShadowTransform.DimensionName &&
flavor.name == ShadowTransform.ApplyShadowTransformFlavorName
}
}.forEach { pluginVariant ->
}

checkPluginVariants(pluginVariants, appExtension, project.name)

pluginVariants.forEach { pluginVariant ->
val output = pluginVariant.outputs.first()
val processManifestTask = agpCompat.getProcessManifestTask(output)
val manifestFile = agpCompat.getManifestFile(processManifestTask)
Expand Down Expand Up @@ -137,6 +142,29 @@ class ShadowPlugin : Plugin<Project> {
}
}

private fun checkPluginVariants(
pluginVariants: List<ApplicationVariant>,
appExtension: AppExtension,
projectName: String
) {
if (pluginVariants.isEmpty()) {
val errorMessage = StringBuilder()
errorMessage.appendLine("在${projectName}中找不到Shadow所添加的Dimension flavor")
errorMessage.appendLine("当前所有flavor打印如下:")
appExtension.applicationVariants.forEach { variant ->
errorMessage.appendLine("variant.name:${variant.name}")
variant.productFlavors.forEach { flavor ->
errorMessage.appendLine(
"flavor.name:${flavor.name} flavor.dimension:${flavor.dimension} "
)
}
}
errorMessage.appendLine("提示:添加flavorDimension时,不要覆盖已有flavorDimension")
errorMessage.appendLine("示例:flavorDimensions(*flavorDimensionList, 'new')")
throw Error(errorMessage.toString())
}
}

private fun addFlavorForTransform(baseExtension: BaseExtension) {
agpCompat.addFlavorDimension(baseExtension, ShadowTransform.DimensionName)
try {
Expand Down