I just spent the last 3 days wrestling with this “Sequence contains more than one matching element” Android build error:
> Task :react-native-device-country:prepareLintJarForPublish
> Task :react-native-device-info:createFullJarRelease
> Task :react-native-device-info:extractProguardFiles
> Task :react-native-device-info:generateReleaseLintModel
> Task :react-native-device-info:prepareLintJarForPublish
> Task :react-native-fbsdk-next:createFullJarRelease
> Task :react-native-fbsdk-next:extractProguardFiles
> Task :app:stripReleaseDebugSymbols
> Task :react-native-fbsdk-next:generateReleaseLintModel
> Task :app:buildReleasePreBundle FAILED
> Task :app:uploadCrashlyticsMappingFileRelease
[Incubating] Problems report is available at: file:///Users/dev/Documents/app/android/build/reports/problems/problems-report.html
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:buildReleasePreBundle'.
> Sequence contains more than one matching element.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.14.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 1h 6m 21s
1222 actionable tasks: 1208 executed, 14 up-to-date
node:child_process:966
throw err;
^
Error: Command failed: ./gradlew bundleRelease
at genericNodeError (node:internal/errors:984:15)
at wrappedFn (node:internal/errors:538:14)
at checkExecSyncError (node:child_process:891:11)
at Object.execSync (node:child_process:963:15)
at /Users/dev/Documents/app/buildscripts/buildserv/build/build-android.js:8:23
at Object.<anonymous> (/Users/dev/Documents/app/buildscripts/buildserv/build/build-android.js:11:3)
at Module._compile (node:internal/modules/cjs/loader:1529:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1613:10)
at Module.load (node:internal/modules/cjs/loader:1275:32)
at Module._load (node:internal/modules/cjs/loader:1096:12) {
status: 1,
signal: null,
output: [ null, null, null ],
pid: 22055,
stdout: null,
stderr: null
}
Node.js v20.19.3
Cleaning up project directory and file based variables 00:00
ERROR: Job failed: exit status 1
If you noticed from the stack trace above, this is a React Native app. I tried deleting my node_modules
folder, deleting my build folders, running ./gradlew clean
. I would run the build again and again, but nothing worked. The same error kept popping up every time, right near the end of the build.
No amount of –debug or –stacktrace was giving me any sort of additional information. The most information I could get from this error had already been given to me.
ChatGPT and Copilot were no help, suggesting that this is a Kotlin error and most likely resides in a native library I’m using within the app.
But this didn’t make sense, because I was able to build the project on my local system with the latest dependencies just fine. It was only once I sent the build to my GitLab instance, which runs the build on a macOS VM with gitlab-runner, that I started getting this error.
So is the error with the build process, or one of the build tools itself?
Narrowing Down the Cause
After a ton of googling of this error, I finally came across this Google IssueTracker post that pointed me in the right direction. This person describes the exact same issue I’m having.
This person also says that this error started happening after an upgrade to AGP 8.9.0.
Now we’re getting somewhere. It doesn’t look like they’re using React Native, but at this point I was confident the issue isn’t stemming from anything to do with React Native.
AGP is an Android build tool. It’s possible that my macOS VM has a newer version of AGP than my local system does. This would explain why it’s only happening once I send the app to build in the macOS VM.
So, what’s the problem?
Well, it can be traced back to this section here in the app’s build.gradle
:
...
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
...
This section of the build.gradle
file tells gradle to output different APK files for different CPU architectures.
When this part of the build.gradle
file is encountered by running the bundleRelease
gradle task, the “sequence contains more than one matching element” exception is thrown because bundleRelease
expects to be generating a single universal AAB file instead of separate APK files, that can then be uploaded to the Google Play Store.
The Fix
All I did was remove this section from our build.gradle
file:
...
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
...
And it resolved the issue! We weren’t using the multiple APKs anyways, so I’m not even sure why we had this in our build.gradle
file. We only upload the single universal AAB to the Play Store.
Additional Notes
In the issue tracker linked above, Google states that they do not plan on fixing this, since they don’t officially support creating multiple APKs when running bundleRelease
. However, if you still need multiple APK support, someone on the issue tracker suggests the following fix:
splits {
abi {
// Detect app bundle and conditionally disable split abis
// This is needed due to a "Sequence contains more than one matching element" error
// present since AGP 8.9.0, for more info see:
// https://issuetracker.google.com/issues/402800800
// AppBundle tasks usually contain "bundle" in their name
val isBuildingBundle = gradle.startParameter.taskNames.any { it.lowercase().contains("bundle") }
// Disable split abis when building appBundle
isEnable = !isBuildingBundle
reset()
//noinspection ChromeOsAbiSupport
include("armeabi-v7a", "arm64-v8a", "x86_64")
isUniversalApk = true
}
}
This enables APK splitting while disabling APK splitting for the bundleRelease
task, preventing the “sequence contains more than one matching element” error.
Leave a Reply