androidreact-nativegradlebuildexpo

A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable


I'm trying to build my expo react native app using eas build -p android but it keeps failing and giving this error:

A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable

I have tried everything to solve it, but I'm unable to, why does Gradle always cause so many issues?

Here's the full error log:

[stderr] 
FAILURE: Build completed with 2 failures.
[stderr] 
1: Task failed with an exception.
[stderr] 
-----------
[stderr] 
* What went wrong:
[stderr] 
Execution failed for task ':app:mergeReleaseResources'.
[stderr] 
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
[stderr] 
   > Android resource compilation failed
[stderr] 
     ERROR:/home/expo/workingdir/build/android/app/build/generated/res/react/release/drawable-mdpi/assets_userbg.png: AAPT: error: file failed to compile.
[stderr] 
         
[stderr] 
* Try:
[stderr] 
> Run with --stacktrace option to get the stack trace.
[stderr] 
> Run with --info or --debug option to get more log output.
[stderr] 
> Run with --scan to get full insights.
[stderr] 
==============================================================================
[stderr] 
2: Task failed with an exception.
[stderr] 
-----------
[stderr] 
* What went wrong:
[stderr] 
java.lang.StackOverflowError (no error message)
[stderr] 
* Try:
[stderr] 
> Run with --stacktrace option to get the stack trace.
[stderr] 
> Run with --info or --debug option to get more log output.
[stderr] 
> Run with --scan to get full insights.
[stderr] 
==============================================================================
[stderr] 
* Get more help at https://help.gradle.org
[stderr] 
BUILD FAILED in 6m 41s
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings
Execution optimizations have been disabled for 3 invalid unit(s) of work during this build to ensure correctness.
Please consult deprecation warnings for more details.
454 actionable tasks: 454 executed
Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.


Solution

  • I was able to figure it out myself. if anyone is having this issue, this is an assets issue, some or one of your assets files will be in the wrong format, for example, the file will be .png but in reality, it won't be a PNG file, fortunately, the log will tell you which file has this issue and you can convert it to the right format and move on.