Skip to content
Merged
Show file tree
Hide file tree
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 @@ -853,7 +853,7 @@ class JavaPluginsTest : BasePluginTest() {

@Test
fun failBuildIfProcessingAar() {
val fooAarPath = path("foo.aar")
val fooAarPath = buildJar("foo.aar") { insert("AndroidManifest.xml", "<manifest/>") }

projectScript.appendText(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -451,7 +453,7 @@ public abstract class ShadowJar : Jar() {
file.isDirectory -> {
from(file)
}
file.extension.equals("aar", ignoreCase = true) -> {
file.extension.equals("aar", ignoreCase = true) && file.isAar() -> {
val message =
"""
Shadowing AAR file is not supported.
Expand Down Expand Up @@ -666,3 +668,11 @@ public abstract class ShadowJar : Jar() {
}
}
}

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
}