facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.06k stars 24.19k forks source link

App could not Build when trying upgrade sdk 33 to 34 (Unexpected error during link, AAPT2 aapt2-4.2.2-7147631-linux Daemon) #45695

Closed jimshidbachu closed 1 month ago

jimshidbachu commented 1 month ago

Description

I am using React Native version 0.66.1. When I changed targetSdkVersion from 33 to 34, the app crashed and there was no log. only in Android

and i also tried change MainApplication.java file

buildscript { ext { buildToolsVersion = "34.0.0" minSdkVersion = 23 compileSdkVersion = 34 targetSdkVersion = 34 ndkVersion = "21.4.7075529" kotlinVersion = '1.5.31' } repositories { google() mavenCentral() gradlePluginPortal() jcenter() } dependencies { classpath("com.android.tools.build:gradle:4.2.2") classpath 'com.google.gms:google-services:4.3.10' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }

image

Steps to reproduce

npm run android

i have done these to steps

https://medium.com/@anaz_19473/react-native-app-crashes-on-upgrading-to-targetsdkversion-34-android-14-f8f575da6b45

and i have done patches on

1.react-native-orientation

1.1 _nodemodules/react-native-orientation/android/build.gradle

`apply plugin: 'com.android.library'

android { compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : 23 buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : "23.0.1"

defaultConfig {
    minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : 16
    targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : 22
    versionCode 1
    versionName "1.0"
    // ndk {
    //     abiFilters "armeabi-v7a", "x86"
    // }
}

}

dependencies { implementation "com.facebook.react:react-native:+" }`

1.2 _nodemodules/react-native-orientation/android/src/main/java/com/github/yamill/orientation/OrientationModule.java

-        activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged"));
+        if(Build.VERSION.SDK_INT >= 34 && activity.getApplicationInfo().targetSdkVersion >= 34) {
+            activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged"), Context.RECEIVER_EXPORTED);
+        } else {
+            activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged"));
+        }

2 rn-fetch-blob

2.1 _nodemodules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

-                appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
+                if (Build.VERSION.SDK_INT >= 34 && appCtx.getApplicationInfo().targetSdkVersion >= 34) {
+                  appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), Context.RECEIVER_EXPORTED);
+                }else{
+                  appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
+                }
                 return;
             }

2.2

android { compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : 28 buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : "28.0.3" defaultConfig { minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : 16 targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : 22 versionCode 1 versionName "1.0" } .... }

3.react-native-screens

faced the issue of

Execution failed for task ':react-native-screens:compileDebugKotlin'.

after trying solve, re-installed react-native-screens its gone show how

React Native Version

0.66.1

Affected Platforms

Runtime - Android

Output of npx react-native info

System:
    OS: Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 5.65 GB / 15.46 GB
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.20.0 - ~/.nvm/versions/node/v16.20.0/bin/node
    Yarn: Not Found
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.0/bin/npm
    Watchman: 4.9.0 - /usr/bin/watchman
  SDKs:
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 17.0.11 - /usr/bin/javac 
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^17.0.2 => 17.0.2 
    react-native: ^0.66.1 => 0.66.1 
  npmGlobalPackages:
    *react-native*: Not Found

Stacktrace or Logs

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
   > AAPT2 aapt2-4.2.2-7147631-linux Daemon #0: Unexpected error during link, attempting to stop daemon.
     This should not happen under normal circumstances, please file an issue if it does.

* 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

BUILD FAILED in 54s

Reproducer

not public

Screenshots and Videos

image

react-native-bot commented 1 month ago
:warning: Too Old Version of React Native
:information_source: It looks like your issue or the example you provided uses a Too Old Version of React Native.

Due to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please upgrade to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on StackOverflow to get further community support.
react-native-bot commented 1 month ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
react-native-bot commented 1 month ago
:warning: Too Old Version of React Native
:information_source: It looks like your issue or the example you provided uses a Too Old Version of React Native.

Due to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please upgrade to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on StackOverflow to get further community support.
react-native-bot commented 1 month ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either: