From 534329d87d6908fdc698bbc4afb44bb1f34c276b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 05:40:30 +0000 Subject: [PATCH 1/5] Initial plan From d997f5d20aed7b9aa2b43ccfe5ba79ba77ad4e1a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 05:46:49 +0000 Subject: [PATCH 2/5] Update AAR detection to check actual file content instead of extension Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com> --- .../gradle/plugins/shadow/JavaPluginsTest.kt | 25 ++++++++++++++++++- .../gradle/plugins/shadow/tasks/ShadowJar.kt | 15 ++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt index 4d3b2cb6b..a5e79b239 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt @@ -853,7 +853,30 @@ class JavaPluginsTest : BasePluginTest() { @Test fun failBuildIfProcessingAar() { - val fooAarPath = path("foo.aar") + val fooAarPath = buildJar("foo.aar") { + insert("AndroidManifest.xml", "") + } + + projectScript.appendText( + """ + dependencies { + ${implementationFiles(fooAarPath)} + } + """ + .trimIndent() + ) + + val result = runWithFailure(shadowJarPath) + + assertThat(result.output) + .contains("Shadowing AAR file is not supported.", "Please exclude dependency artifact:") + } + + @Test + fun failBuildIfProcessingAarWithJarExtension() { + val fooAarPath = buildJar("foo.jar") { + insert("AndroidManifest.xml", "") + } projectScript.appendText( """ diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt index 913d12e36..ccfb2e471 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt @@ -26,6 +26,8 @@ import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransf import java.io.File import java.io.IOException import java.util.jar.JarFile +import java.util.zip.ZipException +import java.util.zip.ZipFile import javax.inject.Inject import kotlin.reflect.full.hasAnnotation import org.apache.tools.zip.Zip64Mode @@ -451,7 +453,7 @@ public abstract class ShadowJar : Jar() { file.isDirectory -> { from(file) } - file.extension.equals("aar", ignoreCase = true) -> { + file.isAar() -> { val message = """ Shadowing AAR file is not supported. @@ -666,3 +668,14 @@ public abstract class ShadowJar : Jar() { } } } + +/** + * Returns true if the file is an AAR (Android Archive) by inspecting its contents. + * An AAR is a ZIP file that contains an `AndroidManifest.xml` entry at the root. + */ +private fun File.isAar(): Boolean = try { + ZipFile(this).use { zip -> zip.getEntry("AndroidManifest.xml") != null } +} catch (_: ZipException) { + // File is not a valid ZIP, so it cannot be an AAR. + false +} From fcf0a98da8d0e48eba532a1ffa8507860259c574 Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Thu, 19 Mar 2026 13:53:01 +0800 Subject: [PATCH 3/5] Update JavaPluginsTest.kt --- .../gradle/plugins/shadow/JavaPluginsTest.kt | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt index a5e79b239..5cc1a8385 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt @@ -872,27 +872,6 @@ class JavaPluginsTest : BasePluginTest() { .contains("Shadowing AAR file is not supported.", "Please exclude dependency artifact:") } - @Test - fun failBuildIfProcessingAarWithJarExtension() { - val fooAarPath = buildJar("foo.jar") { - insert("AndroidManifest.xml", "") - } - - projectScript.appendText( - """ - dependencies { - ${implementationFiles(fooAarPath)} - } - """ - .trimIndent() - ) - - val result = runWithFailure(shadowJarPath) - - assertThat(result.output) - .contains("Shadowing AAR file is not supported.", "Please exclude dependency artifact:") - } - @Test fun addExtraFilesViaFrom() { val mainClassEntry = writeClass() From f75a91ca12eafc42ff31e881573dd4f98d011a32 Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 19 Mar 2026 13:55:48 +0800 Subject: [PATCH 4/5] Reformat --- .../gradle/plugins/shadow/JavaPluginsTest.kt | 4 +--- .../gradle/plugins/shadow/tasks/ShadowJar.kt | 17 +++++++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt index 5cc1a8385..7123ba48a 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt @@ -853,9 +853,7 @@ class JavaPluginsTest : BasePluginTest() { @Test fun failBuildIfProcessingAar() { - val fooAarPath = buildJar("foo.aar") { - insert("AndroidManifest.xml", "") - } + val fooAarPath = buildJar("foo.aar") { insert("AndroidManifest.xml", "") } projectScript.appendText( """ diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt index ccfb2e471..bb5d2d5fb 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt @@ -669,13 +669,10 @@ public abstract class ShadowJar : Jar() { } } -/** - * Returns true if the file is an AAR (Android Archive) by inspecting its contents. - * An AAR is a ZIP file that contains an `AndroidManifest.xml` entry at the root. - */ -private fun File.isAar(): Boolean = try { - ZipFile(this).use { zip -> zip.getEntry("AndroidManifest.xml") != null } -} catch (_: ZipException) { - // File is not a valid ZIP, so it cannot be an AAR. - false -} +private fun File.isAar(): Boolean = + try { + ZipFile(this).use { zip -> zip.getEntry("AndroidManifest.xml") != null } + } catch (_: ZipException) { + // File is not a valid ZIP, so it cannot be an AAR. + false + } From d1ea52b88455ac96b0fdf01b0de759d192f65291 Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 19 Mar 2026 13:56:47 +0800 Subject: [PATCH 5/5] Check extension as well --- .../github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt index bb5d2d5fb..3bb828c73 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt @@ -453,7 +453,7 @@ public abstract class ShadowJar : Jar() { file.isDirectory -> { from(file) } - file.isAar() -> { + file.extension.equals("aar", ignoreCase = true) && file.isAar() -> { val message = """ Shadowing AAR file is not supported.