Status Update
Comments
aa...@google.com <aa...@google.com>
je...@google.com <je...@google.com> #2
Micah, can you file a bug on the internal tooling for AIDL and follow up there. please update this bug with any findings.
mi...@google.com <mi...@google.com> #3
Internal tracking bug:
We need to determine why the file does not contain emptyFileLine
string in
se...@exaring.de <se...@exaring.de> #4
Thanks for having a look.
I've managed to make this somehow reproducible, and created a sample repo for it:
If you run ./gradlew --no-build-cache --no-daemon clean assembleTwoElevenRelease assembleTwoTwelveRelease
against it multiple times, it should eventually fail.
The only change from an empty Android Studio projects (besides the aidl file) are those lines in the build.gradle.kts file:
flavorDimensions.addAll(listOf("dimension1", "dimension2"))
productFlavors {
register("one") {
dimension = "dimension1"
}
register("two") {
dimension = "dimension1"
}
register("eleven") {
dimension = "dimension2"
}
register("twelve") {
dimension = "dimension2"
}
}
buildFeatures {
aidl = true
}
sourceSets {
register("oneEleven") {
aidl.srcDirs(
"src/one/aidl",
"src/eleven/aidl",
"src/oneEleven/aidl",
)
}
register("twoTwelve") {
aidl.srcDirs(
"src/two/aidl",
"src/twelve/aidl",
"src/twoTwelve/aidl",
)
}
}
Having multiple build variants use the same source dir might be the culprit? I'm not sure though, and would appreciate any insights.
I've also attached the Java debugger (with ./gradlew -Dorg.gradle.debug=true ...
) and saw that, before the exception is thrown, the generated Java file is empty, i.e. outputFileContent
== 0.
I hope this helps.
mi...@google.com <mi...@google.com>
se...@exaring.de <se...@exaring.de> #5
What is confusing me, is that the build (of our real world repo) fails sometimes if we just call e.g. ./gradlew :app:assembleAndroidtvInternalStandaloneProdDebug
From my understanding the AIDL task then should only run once. But at least the output prints it twice:
...
> Task :app:preBuild UP-TO-DATE
> Task :app:preAndroidtvInternalStandaloneProdDebugBuild UP-TO-DATE
> Task :app:mergeAndroidtvInternalStandaloneProdDebugNativeDebugMetadata NO-SOURCE
> Task :app:compileAndroidtvInternalStandaloneProdDebugAidl
> Task :app:checkKotlinGradlePluginConfigurationErrors
> Task :app:compileAndroidtvInternalStandaloneProdDebugAidl FAILED
> Task :app:dataBindingMergeDependencyArtifactsAndroidtvInternalStandaloneProdDebug
...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileAndroidtvInternalStandaloneProdDebugAidl'.
> A failure occurred while executing com.android.build.gradle.tasks.AidlCompile$AidlCompileRunnable
> Index 0 out of bounds for length 0
se...@exaring.de <se...@exaring.de> #6
Are there any updates here?
Or can I provide more details?
hu...@google.com <hu...@google.com> #7
Thanks a lot for the sample project in
I've been able to reproduce this issue by running ./gradlew clean :app:compileTwoTwelveReleaseAidl
a few times.
Root cause
The root cause is that your project has the following script:
register("twoTwelve") {
aidl.srcDirs(
"src/two/aidl",
"src/twelve/aidl",
"src/twoTwelve/aidl"
)
}
This doesn't seem necessary because AGP already automatically does that.
That means in the AidlCompile
task, AGP runs the AIDL compiler on those directories twice. Inside that task, we have a logic to inspect the outputs after generating them. Therefore, it is possible that one Gradle worker is reading an output file while another worker is writing to it, hence the above error.
Possible fix
The fix is to de-duplicate source directories in the AildCompile
task or at some other level to make it more general for all the tasks, so that a source directory is processed only once.
Also, we can consider emitting a warning if the users add a source directory that AGP already handles.
Workaround
I believe if you remove that code in your build script, the build will no longer fail.
mi...@google.com <mi...@google.com>
an...@google.com <an...@google.com> #9
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 Jellyfish | 2023.3.1 Canary 10
- Android Gradle Plugin 8.4.0-alpha10
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!
Description
Note: This is a bug in the Android Gradle Plugin, but I am not allowed to create an issue in the Android Gradle Plugin component.
ISSUE:
The
AidlCompile
Android Gradle Plugin task is rarely, and completly randomly, failing with the exceptionIndexOutOfBoundsException: Index 0 out of bounds for length 0
. See also the below stacktrace.Re-runing the same Gradle command, with the same input, always resolves this issue. Sometime we have to re-run multiple times though.
Because this issue appears randomly, and for a while now, it is hard for us to pinpoint the exact versions when this issue first appeared.
Currently we use APG 8.2.0 with Gradle 8.5 and build-tools 34.0.0.
We experience this issue only on our CI where all builds are running inside a separate docker container, and are therefore de-facto clean builds. However we are re-using the Gradle build-cache across our different stages. But the Gradle daemon is alwas spawned anew.
We only have one AIDL file, which is only in the sourceset of our
AndroidTV
flavor:app/src/androidtv/aidl/com/example/FunInterface.aidl
. And our project has a lot of app variants. There are two buildTypes (debug, release) and four product flavor dimensions (one dimension isplatform
whereAndroidTV
is one of the flavors).Even though we enabled AIDL compilation for all variants it only fails when running
assembleAndroidTV...Release
for theAndroidTV
flavor.From what I understand the cause for this issue is that the AIDL output files are seemingly empty. However, after the job failed there is one valid Java file inside
app/build/generated/aidl_source_output_dir/androidtvInternalStandaloneProdRelease/out/com/example/FunInterface.java
.STEPS TO REPRODUCE:
The build failure happens randomly and rarely, therefore I am not able to provide neither steps to reproduce nor an explicit repro-sample project.
VERSIONS:
Version of Gradle Plugin: 8.2.0
Version of Gradle: 8.5
Version of Java: OpenJDK 64-Bit Temurin-17.0.8+7
OS: Ubuntu 22.04.2 LTS