Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android build fails for new project with latest version #36685

Closed
jordibuj opened this issue Mar 28, 2023 · 5 comments
Closed

Android build fails for new project with latest version #36685

jordibuj opened this issue Mar 28, 2023 · 5 comments
Labels
Needs: Triage 🔍 Platform: Android Android applications. Platform: Linux Building on Linux. Resolution: Answered When the issue is resolved with a simple answer

Comments

@jordibuj
Copy link

Description

Created a new project using the latest react-native version
npx react-native@latest init rnApp

Started the app
yarn start

And clicked on 'a' to run in Android.
The emulator is launched, but build fails with the following:

r - reload the app
d - open developer menu
i - run on iOS
a - run on Android

info Opening the app on Android...
info JS server already running.
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
> Task :react-native-gradle-plugin:compileKotlin
> Task :react-native-gradle-plugin:compileJava NO-SOURCE
> Task :react-native-gradle-plugin:pluginDescriptors
> Task :react-native-gradle-plugin:processResources
> Task :react-native-gradle-plugin:classes
> Task :react-native-gradle-plugin:inspectClassesForKotlinIC
> Task :react-native-gradle-plugin:jar
> Task :app:buildCodegenCLI SKIPPED
> Task :app:generateCodegenSchemaFromJavaScript SKIPPED
> Task :app:generateCodegenArtifactsFromSchema SKIPPED
> Task :app:generatePackageList
> Task :app:preBuild
> Task :app:preDebugBuild
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:generateDebugBuildConfig
> Task :app:javaPreCompileDebug
> Task :app:checkDebugAarMetadata FAILED
9 actionable tasks: 9 executed

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform react-android-0.71.4-debug.aar (com.facebook.react:react-android:0.71.4) to match attributes {artifactType=android-aar-metadata, com.android.build.api.attributes.BuildTypeAttr=debug, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for JetifyTransform: /home/jordi/.gradle/caches/modules-2/files-2.1/com.facebook.react/react-android/0.71.4/8091e960d61eb74178e3ff707c0a426c31b29893/react-android-0.71.4-debug.aar.
         > Java heap space

* 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.
==============================================================================

I can build other apps using older React Native versions, problem started happening when upgrading one of those applications to the latest React Native version. Then I realized that just creating a new project from scratch reproduces the issue.

React Native Version

0.71.4

Output of npx react-native info

System:
    OS: Linux 5.19 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 183.50 MB / 15.33 GB
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
    Watchman: 20230326.214747.0 - /usr/local/bin/watchman
  SDKs:
    Android SDK:
      API Levels: 31, 33, 33
      Build Tools: 29.0.2, 30.0.2, 30.0.3, 33.0.0, 33.0.2
      System Images: android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: AI-221.6008.13.2211.9619390
  Languages:
    Java: 11.0.18 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.4 => 0.71.4 
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. Create a new project using the latest react-native version
    npx react-native@latest init rnApp

  2. Start the app
    yarn start

  3. Click on 'a' to run in Android.

Snack, code example, screenshot, or link to a repository

https://github.com/jordibuj/rnApp

@react-native-bot react-native-bot added Platform: Android Android applications. Platform: Linux Building on Linux. labels Mar 28, 2023
@cresenciof
Copy link

it works for me, I cloned your repo.

this is the npx react-native info output:

System:
    OS: macOS 13.2.1
    CPU: (20) x64 Intel(R) Xeon(R) W-2150B CPU @ 3.00GHz
    Memory: 13.04 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
    Watchman: 2023.02.27.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK:
      API Levels: 28, 29, 30, 31, 32, 33
      Build Tools: 28.0.3, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.1
      System Images: android-31 | Android TV ARM 64 v8a, android-31 | Android TV Intel x86 Atom, android-31 | ARM 64 v8a, android-31 | Intel x86 Atom_64, android-31 | Google TV ARM 64 v8a, android-31 | Google TV Intel x86 Atom, android-31 | Google APIs ARM 64 v8a, android-31 | Google APIs Intel x86 Atom_64, android-31 | Google Play ARM 64 v8a, android-31 | Google Play Intel x86 Atom_64
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9123335
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.17 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.4 => 0.71.4 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
d - open developer menu
i - run on iOS
a - run on Android

info Opening the app on Android...
info JS server already running.
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :react-native-gradle-plugin:compileKotlin
> Task :react-native-gradle-plugin:compileJava NO-SOURCE
> Task :react-native-gradle-plugin:pluginDescriptors
> Task :react-native-gradle-plugin:processResources
> Task :react-native-gradle-plugin:classes
> Task :react-native-gradle-plugin:inspectClassesForKotlinIC
> Task :react-native-gradle-plugin:jar
Checking the license for package Android SDK Platform 33 in /Users/cresenciof/Library/Android/sdk/licenses
License for package Android SDK Platform 33 accepted.
Preparing "Install Android SDK Platform 33 (revision: 2)".
"Install Android SDK Platform 33 (revision: 2)" ready.
Installing Android SDK Platform 33 in /Users/cresenciof/Library/Android/sdk/platforms/android-33
"Install Android SDK Platform 33 (revision: 2)" complete.
"Install Android SDK Platform 33 (revision: 2)" finished.
> Task :app:buildCodegenCLI SKIPPED
> Task :app:generateCodegenSchemaFromJavaScript SKIPPED
> Task :app:generateCodegenArtifactsFromSchema SKIPPED
> Task :app:generatePackageList
> Task :app:preBuild
> Task :app:preDebugBuild
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:generateDebugBuildConfig
> Task :app:javaPreCompileDebug
> Task :app:checkDebugAarMetadata
> Task :app:generateDebugResValues
> Task :app:mapDebugSourceSetPaths
> Task :app:generateDebugResources
> Task :app:createDebugCompatibleScreenManifests
> Task :app:extractDeepLinksDebug
> Task :app:mergeDebugResources
> Task :app:processDebugMainManifest
> Task :app:processDebugManifest
> Task :app:mergeDebugShaders
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets
> Task :app:compressDebugAssets
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:checkDebugDuplicateClasses
> Task :app:mergeDebugJavaResource
> Task :app:desugarDebugFileDependencies
> Task :app:mergeDebugJniLibFolders
> Task :app:mergeLibDexDebug
> Task :app:validateSigningDebug
> Task :app:writeDebugAppMetadata
> Task :app:writeDebugSigningConfigVersions
> Task :app:processDebugManifestForPackage
> Task :app:mergeDebugNativeLibs
> Task :app:mergeExtDexDebug

> Task :app:stripDebugDebugSymbols
Unable to strip the following libraries, packaging them as they are: libc++_shared.so, libcxxcomponents.so, libevent-2.1.so, libevent_core-2.1.so, libevent_extra-2.1.so, libfabricjni.so, libfb.so, libfbjni.so, libflipper.so, libfolly_runtime.so, libglog.so, libglog_init.so, libhermes.so, libhermes_executor.so, libimagepipeline.so, libjsi.so, libjsijniprofiler.so, libjsinspector.so, liblogger.so, libmapbufferjni.so, libnative-filters.so, libnative-imagetranscoder.so, libreact_codegen_rncore.so, libreact_config.so, libreact_debug.so, libreact_nativemodule_core.so, libreact_newarchdefaults.so, libreact_render_animations.so, libreact_render_attributedstring.so, libreact_render_componentregistry.so, libreact_render_core.so, libreact_render_debug.so, libreact_render_graphics.so, libreact_render_imagemanager.so, libreact_render_leakchecker.so, libreact_render_mapbuffer.so, libreact_render_mounting.so, libreact_render_runtimescheduler.so, libreact_render_scheduler.so, libreact_render_telemetry.so, libreact_render_templateprocessor.so, libreact_render_textlayoutmanager.so, libreact_render_uimanager.so, libreact_utils.so, libreactnativeblob.so, libreactnativejni.so, libreactperfloggerjni.so, librrc_image.so, librrc_root.so, librrc_scrollview.so, librrc_text.so, librrc_textinput.so, librrc_unimplementedview.so, librrc_view.so, libruntimeexecutor.so, libturbomodulejsijni.so, libyoga.so.

> Task :app:processDebugResources
> Task :app:compileDebugJavaWithJavac
> Task :app:dexBuilderDebug
> Task :app:mergeProjectDexDebug
> Task :app:packageDebug
> Task :app:createDebugApkListingFileRedirect

> Task :app:installDebug
Installing APK 'app-debug.apk' on 'Powerfull_API_31(AVD) - 12' for :app:debug
Installed on 1 device.

BUILD SUCCESSFUL in 2m 26s
38 actionable tasks: 38 executed
info Connecting to the development server...
8081
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.rnapp/.MainActivity }
 BUNDLE  ./index.js 

 LOG  Running "rnApp" with {"rootTag":11}

image

@jordibuj
Copy link
Author

It had to be something related to my local environment.

I wiped out my ~/.gradle folder and now it's working.

It could be that I'm maintaining apps in different React Native versions, and other Java applications that also use Gradle,... whatever, I can't reproduce it anymore

@cortinico
Copy link
Contributor

I wiped out my ~/.gradle folder and now it's working.

Closing as for this.
The problem was a Out of memory exception due to Gradle consuming too much Ram on your machine.

@cortinico cortinico added the Resolution: Answered When the issue is resolved with a simple answer label Mar 31, 2023
@chenop
Copy link

chenop commented Apr 8, 2023

Got the same error after upgrading to react-native 0.71.5
rm -rf ~/.gradle did not resolve the issue.
Any idea?

* What went wrong:
Execution failed for task ':app:mapDebugSourceSetPaths'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform react-android-0.71.5-debug.aar (com.facebook.react:react-android:0.71.5) to match attributes {artifactType=android-res, com.android.build.api.attributes.BuildTypeAttr=debug, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for JetifyTransform: /Users/chen.oppenhaim/.gradle/caches/modules-2/files-2.1/com.facebook.react/react-android/0.71.5/5acc721119cfb59c201e8671e6b867976df1aa85/react-android-0.71.5-debug.aar.
         > Java heap space

@szatkus
Copy link

szatkus commented Feb 27, 2024

Adding org.gradle.jvmargs=-Xmx4096M to gradle.properties resolved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Platform: Android Android applications. Platform: Linux Building on Linux. Resolution: Answered When the issue is resolved with a simple answer
Projects
None yet
Development

No branches or pull requests

6 participants