Status Update
Comments
ha...@google.com <ha...@google.com>
ga...@google.com <ga...@google.com>
sp...@google.com <sp...@google.com> #2
Thanks for the report.
Are you able to upload a toy project reproducing the issue?
Do you know which dependency com/google/android/youtube/player/internal/u.class
is coming from?
mk...@opera.com <mk...@opera.com> #3
Sadly I am not able to reproduce it using toy project. The mentioned dependency comes from some old YouTubePlayer library, that we include as a .jar file. Also this jar was jettified.
Forgot to mention this issue only reproduces when R8 is enabled.
mk...@opera.com <mk...@opera.com> #4
This issues seems to be connected to dynamic feature modules, as when I remove them I can compile. But that's probably because the MergeClassesTask is not needed in that case at all, is it? I still didn't manage to reproduce it in isolation. Is there anything else I can provide to help you narrow the problem?
Also with 8.1.0-alpha11 the project compiles fine, it starts to fail with 8.1.0-beta01. Maybe this can help in finding the cause?
sp...@google.com <sp...@google.com> #5
The mentioned dependency comes from some old YouTubePlayer library, that we include as a .jar file
Can you show how you do this explicitly?
Also with 8.1.0-alpha11 the project compiles fine, it starts to fail with 8.1.0-beta01. Maybe this can help in finding the cause?
That's helpful to know, but unfortunately there are more than 150 commits between those 2 versions, so it'll be difficult to find the culprit. I skimmed the commit messages, but I don't see anything suspicious.
Do you still hit the issue if you try AGP 8.2.0-alpha15 (the latest canary release)?
ma...@gmail.com <ma...@gmail.com> #6
The latest AGP 8.2.0-alpha15 is also affected.
The .jar file lies in the rootProject/libs directory and in :app module Gradle I have implementation rootProject.files('libs/youtube-player-jetified.jar')
But I tried to add this dependency in the toy project with dynamic feature module and it didn't reproduce. Must be related to something else we have in the build files which are quite complex.
sp...@google.com <sp...@google.com> #7
CLASSES
.
What do you think, Amr?
OP, do you hit the issue in your toy project if you also add a transitive dependency on the local jar? I.e., add a new android library that depends on the local jar, and also make the new android library a dependency of your app.
mk...@opera.com <mk...@opera.com> #8
No, sadly this kind of transitive dependency doesn't reproduce the issue. Also unless there is something terribly wrong I wouldn't expect this kind of transitive dependency in our project.
I tried to add this local jar dependency to the dynamic feature module. This failed with different error, though also referencing the same class
ERROR: /Users/mkubiczek/workspace/threekk/agpissue/app/build/intermediates/module_and_runtime_deps_classes/release/base.jar: R8: Type com.google.android.youtube.player.internal.u is defined multiple times: /Users/mkubiczek/workspace/threekk/agpissue/app/build/intermediates/module_and_runtime_deps_classes/release/base.jar:com/google/android/youtube/player/internal/u.class, /Users/mkubiczek/workspace/threekk/agpissue/dynamicfeature/build/intermediates/module_and_runtime_deps_classes/release/feature-dynamicfeature.jar:com/google/android/youtube/player/internal/u.class
that is on a later step though minifyReleaseWithR8
. But regardless that also looks like a regression in 8.1.0, as this kind of setup works in 8.0.2
am...@google.com <am...@google.com> #9
I've merged a
The fix will be included in AGP 8.2 beta 2 and 8.3 alpha 2.
It would be helpful if you can try a nightly build of AGP and report if the issue indeed is fixed. You can do so by adding the following repository to your projects' repos and plugin manangement repos definitions
maven {
url = uri("https://androidx.dev/studio/builds/10694597/artifacts/artifacts/repository")
}
and setting the gradle plugin version to 8.3.0-dev
.
mk...@opera.com <mk...@opera.com> #10
Sorry, but I couldn't check it as I am getting error like this:
Execution failed for task ':app:processReleaseResources'.
> Could not isolate parameters com.android.build.gradle.internal.dependency.AarResourcesCompilerTransform$Parameters_Decorated@5e71bf48 of artifact transform AarResourcesCompilerTransform
> Could not isolate value com.android.build.gradle.internal.dependency.AarResourcesCompilerTransform$Parameters_Decorated@5e71bf48 of type AarResourcesCompilerTransform.Parameters
> Could not resolve all files for configuration ':app:detachedConfiguration2'.
> Could not find com.android.tools.build:aapt2:8.3.0-dev-10154469.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/com/android/tools/build/aapt2/8.3.0-dev-10154469/aapt2-8.3.0-dev-10154469.pom
- https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/8.3.0-dev-10154469/aapt2-8.3.0-dev-10154469.pom
Required by:
project :app
am...@google.com <am...@google.com> #11
Make sure that the androidx.dev
repository above is added to the definition of the repositories in that project, whether defined in that project, root build.gradle or settings.gradle.kts
am...@google.com <am...@google.com> #13
Can you add the following task to your build.gradle in the app module
import com.android.build.api.artifact.ScopedArtifact
import com.android.build.api.variant.ScopedArtifacts
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
abstract class PrintClassesJars extends DefaultTask {
private static String PROBLEMATIC_CLASS = "com/google/android/youtube/player/internal/u.class"
@InputFiles
abstract ListProperty<RegularFile> getAllJars()
@InputFiles
abstract ListProperty<Directory> getAllDirectories()
@TaskAction
void findJars() {
getAllJars().get().forEach { file ->
try (ZipFile zipFile = new ZipFile(file.asFile)) {
Enumeration<? extends ZipEntry> zipFileEntries = zipFile.entries()
while (zipFileEntries.hasMoreElements()) {
if (zipFileEntries.nextElement().getName() == PROBLEMATIC_CLASS) {
print("Found a jar packaging the class at " + file.asFile.getAbsolutePath())
}
}
}
}
getAllDirectories().get().forEach { dir ->
dir.asFile.traverse(type: groovy.io.FileType.FILES) { file ->
String relativePath = dir.asFile.toURI().relativize(file.toURI()).getPath()
if (relativePath == PROBLEMATIC_CLASS) {
print("Found a directory containing the class at " + dir.asFile.getAbsolutePath())
}
}
}
}
}
androidComponents {
onVariants(selector().all(), { variant ->
TaskProvider taskProvider = project.tasks.register(
variant.getName() + "PrintJars", PrintClassesJars.class
)
variant.artifacts.forScope(ScopedArtifacts.Scope.ALL)
.use(taskProvider)
.toGet(
ScopedArtifact.CLASSES.INSTANCE,
{ it.allJars },
{ it.allDirectories }
)
})
}
and then run :app:releasePrintJars
and share the finding?
mk...@opera.com <mk...@opera.com> #14
Thanks, there are two paths found. One points to the actual file in the project, the other refers to some gradle cache.
Found a jar packaging the class at (...)/.gradle/caches/transforms-3/609859a5ed3d35b3aad372e65a0712b8/transformed/YouTubeAndroidPlayerApi-jetified.jar
Found a jar packaging the class at (...)/work/mobile/android/libs/YouTubeAndroidPlayerApi-jetified.jar
Running the same on AGP-8.1.0-alpha11 finds only one path in the gradle cache
Found a jar packaging the class at (...).gradle/caches/transforms3/5a0d2eeed7e95fe38c5a827458e0139c/transformed/YouTubeAndroidPlayerApi-jetified.jar
mk...@opera.com <mk...@opera.com> #15
Is the information from
am...@google.com <am...@google.com> #16
Interesting, it seems that the jar is transformed with an artifact transform, but it's not clear which artifact transform is the culprit. Can you run ./gradlew :app:releasePrintJars --debug | grep YouTubeAndroidPlayerApi-jetified.jar
and attach the result?
am...@google.com <am...@google.com> #17
Also you can add the following to your build.gradle as a workaround, it'll make the build a bit slower but it can unblock AGP upgrade.
import com.android.build.api.artifact.ScopedArtifact
import com.android.build.api.variant.ScopedArtifacts
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
abstract class FilterOutTransformedLocalJar extends DefaultTask {
private static String PROBLEMATIC_JAR_SUFFIX =
"transformed/YouTubeAndroidPlayerApi-jetified.jar"
@InputFiles
abstract ListProperty<RegularFile> getAllJars()
@InputFiles
abstract ListProperty<Directory> getAllDirectories()
@OutputFiles
abstract RegularFileProperty getOutput()
@TaskAction
void filterJars() throws IOException {
OutputStream jarOutput = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(
output.get().getAsFile()
)))
allJars.get().forEach { file ->
if (!file.asFile.absolutePath.endsWith(PROBLEMATIC_JAR_SUFFIX)) {
JarFile jarFile = new JarFile(file.asFile)
for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) {
JarEntry jarEntry = e.nextElement()
if (!jarEntry.isDirectory() && !jarEntry.name.startsWith("META-INF")) {
jarOutput.putNextEntry(new JarEntry(jarEntry.name))
jarFile.getInputStream(jarEntry).withCloseable {
jarOutput << it
}
jarOutput.closeEntry()
}
}
jarFile.close()
}
}
allDirectories.get().forEach { directory ->
directory.asFile.traverse(type: groovy.io.FileType.FILES) { file ->
String relativePath = directory.asFile.toURI().relativize(file.toURI()).getPath()
jarOutput.putNextEntry(new JarEntry(relativePath.replace(File.separatorChar, '/' as char)))
new FileInputStream(file).withCloseable { inputStream ->
jarOutput << inputStream
}
jarOutput.closeEntry()
}
}
jarOutput.close()
}
}
androidComponents {
onVariants(selector().all(), { variant ->
TaskProvider taskProvider = project.tasks.register(
variant.getName() + "FilterJar", FilterOutTransformedLocalJar.class
)
variant.artifacts.forScope(ScopedArtifacts.Scope.ALL)
.use(taskProvider)
.toTransform(
ScopedArtifact.CLASSES.INSTANCE,
{ it.getAllJars() },
{ it.getAllDirectories() },
{ it.getOutput() }
)
})
}
mk...@opera.com <mk...@opera.com> #18
Thanks for the potential workaround. Please find the output of the mentioned task with --debug flag.
mk...@opera.com <mk...@opera.com> #19
Does the attached output give you any clue? I see plenty of transformations being done but i don't see any particular task that requests them.
am...@google.com <am...@google.com> #20
Yes, the problem was with the AsmTransform, I assume you're applying hilt in that app project? I was able to reproduce the issue with an app module that contains dynamic feature deps, minification enabled, local jar dependency and an asm transformation that transforms all dependencies. I've also merged a
Can you try with AGP 8.3.0-dev
with the following artifacts repo and see if that fixes the problem?
maven {
url = uri("https://androidx.dev/studio/builds/10746020/artifacts/artifacts/repository")
}
mk...@opera.com <mk...@opera.com> #21
Yes, we do use hilt indeed.I tried to reproduce it by adding hilt to my toy project when I've seen some hilt related transformation along the executed transforms, it didn't reproduce to me but maybe I missed something.
The given fix works! Thanks for the effort put in finding the root cause. Is there any chance there will be an update to 8.1.2 including it anytime soon?
am...@google.com <am...@google.com> #22
Great, thanks for confirming. Unfortunately, it's too late for the change to be included in 8.1.2. But it will be available in 8.2.0-beta04 and 8.3.0-alpha03.
am...@google.com <am...@google.com>
an...@google.com <an...@google.com> #23
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Iguana | 2023.2.1 Canary 3
- Android Gradle Plugin 8.3.0-alpha03
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
an...@google.com <an...@google.com> #24
The fixes for this issue are now also available in:
- Android Studio Hedgehog | 2023.1.1 Beta 4
- Android Gradle Plugin 8.2.0-beta04
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Description
> Task :app:mergeReleaseClasses FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeClassesTask$MergeClassesWorkAction
> Zip file '/Users/.../build/app/intermediates/module_and_runtime_deps_classes/release/base.jar' already contains entry 'com/google/android/youtube/player/internal/u.class', cannot overwrite
The u.class mentioned in the error comes from a .jar file that I have in the libs dir.
I was looking in which AGP it started to break. When I get back to AGP 8.1.0-alpha10 it started to break with different error, this time related to R8 but mentioning the same base.jar file. I found the following issue
------------------
Version of Gradle Plugin: 8.1.0
Version of Gradle: 8.1.1
Version of Java: 17
OS: MacOS Ventura 13.4.1