invertase / react-native-firebase

πŸ”₯ A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.68k stars 2.21k forks source link

[πŸ›] πŸ”₯ Version Upgrade from 17.3.1 to 19.1.2 causing compilation issues on Android #7732

Closed dooamindshine closed 6 months ago

dooamindshine commented 6 months ago

πŸ”₯ Version Upgrade from 17.3.1 to 19.1.2 causing compilation issues on Android

I have recently upgraded to firebase libraries to 19.1.2 from 17.3.1. While it is working perfectly fine on IOS but on Android i am getting this error and android project is unable to compile:

Universal firebase module package android.content does not exist can not find symbol class Context can not find symbol class Context can not find symbol class Context Similar not found issues are appearing in other classes as well. I have attached screenshots for further clarification


Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "zyx", "version": "1.0.0", "private": true, "scripts": { "android": "react-native run-android", "start-android": "react-native run-android && react-native start", "ios": "react-native run-ios", "start": "react-native start", "dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' --files src/index.ts", "test": "jest", "lint": "eslint src/", "tslint": "tslint --project tsconfig.json", }, "dependencies": { "@react-native-firebase/analytics": "^19.1.2", "@react-native-firebase/app": "^19.1.2", "@react-native-firebase/auth": "^19.1.2", "@react-native-firebase/crashlytics": "^19.1.2", "@react-native-firebase/messaging": "19.1.2", "@react-native-firebase/perf": "^19.1.2", "lottie-ios": "3.4.0", "lottie-react-native": "^5.1.5", "react": "17.0.2", "react-native": "0.67.4", "react-native-fbsdk-next": "11.1.0", "react-native-i18n": "^2.0.15", "react-native-iap": "^12.10.8", "react-redux": "^7.2.3", "reanimated-bottom-sheet": "^1.0.0-alpha.16", "redux": "^4.0.5", "redux-enhancer-react-native-appstate": "^0.3.1", "redux-persist": "^6.0.0", "redux-saga": "^1.1.3", "reselect": "^4.0.0", "rn-fetch-blob": "^0.12", }, "devDependencies": { "@babel/core": "^7.17.8", "@babel/runtime": "^7.17.8", "@react-native-community/eslint-config": "^1.1.0", "@types/react": "^16.9.2", "@types/react-native": "^0.64.4", "@types/react-native-fbsdk": "^3.0.2", "@types/react-redux": "^7.1.16", "@types/rn-fetch-blob": "^1.2.1", "@types/semver": "^6.0.1", "@typescript-eslint/eslint-plugin": "^4.29.0", "@typescript-eslint/parser": "^4.29.0", "babel-eslint": "^10.0.1", "babel-jest": "^25.1.0", "babel-plugin-inline-import": "^3.0.0", "eslint": "^7.32.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-plugin-import": "^2.23.4", "eslint-plugin-jsx-a11y": "^6.2.1", "eslint-plugin-react": "^7.13.0", "eslint-plugin-react-hooks": "^4.2.0", "eslint-plugin-react-native": "^3.7.0", "jest": "^25.1.0", "jetifier": "^1.6.6", "jsc-android": "^250230.2.1", "metro-react-native-babel-preset": "^0.66.2", "react-native-svg-transformer": "^1.0.0", "react-native-typescript-transformer": "^1.2.13", "react-test-renderer": "17.0.2", "reactotron-react-native": "^5.0.0", "reactotron-redux": "^3.1.3", "reactotron-redux-saga": "^4.2.3", "schedule": "^0.4.0", "ts-jest": "^24.0.2", "tslib": "^1.10.0", "tslint": "^5.19.0", "tslint-eslint-rules": "^5.4.0", "tslint-react": "^4.0.0", "typescript": "^4.6.3" }, "resolutions": { "@types/react": "17.0.43" }, "jest": { "preset": "react-native", "transform": { "^.+\\.(js|ts|tsx)$": "/node_modules/react-native/jest/preprocessor.js" }, "transformIgnorePatterns": [], "moduleDirectories": [ "node_modules", "." ], "moduleFileExtensions": [ "ts", "tsx", "js" ], "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$", "verbose": true, "setupFiles": [ "./setupTests.js" ] }, "rnpm": { "assets": [ "assets/fonts/DMSerifDisplay/", "assets/fonts/DMSans/" ] } } ``` #### `firebase.json` for react-native-firebase v6: ```json { "react-native": { "crashlytics_auto_collection_enabled": true, "crashlytics_debug_enabled": false, "crashlytics_ndk_enabled": true, "crashlytics_is_error_generation_on_js_crash_enabled": true, "crashlytics_javascript_exception_handler_chaining_enabled": false } } ```


Android

Click To Expand

#### Have you converted to AndroidX? - [x] my application is an AndroidX application? - [x] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [x] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 googlePlayServicesAuthVersion = "16.0.1" supportLibVersion = "28.0.0" facebookSdkVersion = "12.3.0" kotlin_version = "1.8.0" ndkVersion = "21.4.7075529" } repositories { google() mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath("com.android.tools.build:gradle:4.2.2") classpath 'com.google.gms:google-services:4.3.8' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.1' classpath ('com.google.firebase:perf-plugin:1.4.0') // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } subprojects { afterEvaluate {project -> // if (project.hasProperty("android")) { // android { // compileSdkVersion 33 // buildToolsVersion "33.0.0" // } // } } if (project.name.contains('react-native-image-picker')) { buildscript { repositories { jcenter() maven { url "https://dl.bintray.com/android/android-tools/" } } } } } allprojects { repositories { google() // should be at the top to make push notifications library compilation successful mavenLocal() jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../node_modules/react-native/android") } maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } maven { url 'https://maven.google.com' } mavenCentral { // We don't want to fetch react-native from Maven Central as there are // older versions over there. content { excludeGroup "com.facebook.react" } } maven { url('https://www.jitpack.io') } } } ``` #### `android/app/build.gradle`: ```groovy apply plugin: "com.android.application" apply plugin: 'com.google.firebase.firebase-perf' apply plugin: 'com.google.gms.google-services' import com.android.build.OutputFile project.ext.react = [ enableHermes: false, entryFile: "index.js" ] apply from: "../../node_modules/react-native/react.gradle" def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = false def jscFlavor = 'org.webkit:android-jsc:+' def useIntlJsc = true def enableHermes = project.ext.react.get("enableHermes", false); android { lintOptions { disable 'InvalidPackage' checkReleaseBuilds false //<- add this line } compileSdkVersion rootProject.ext.compileSdkVersion packagingOptions { pickFirst '**/*.so' pickFirst '**/libjsc.so' pickFirst '**/libc++_shared.so' } defaultConfig { applicationId "xyz" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 10 versionName "1.0.0" multiDexEnabled true missingDimensionStrategy 'store', 'play' } signingConfigs { } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" } } signingConfigs { debug { // if (nativeArchitectures) { // ndk { // abiFilters nativeArchitectures.split(',') // } // } } } buildTypes { debug { signingConfig signingConfigs.debug } release { // Caution! In production, you need to generate your own keystore file. // see https://reactnative.dev/docs/signed-apk-android. minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" signingConfig signingConfigs.release } } // applicationVariants are e.g. debug, release applicationVariants.all { variant -> variant.outputs.each { output -> // For each separate APK per architecture, set a unique version code as described here: // https://developer.android.com/studio/build/configure-apk-splits.html def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } } dependencies { implementation "org.webkit:android-jsc:r241213" implementation "com.google.android.gms:play-services-gcm:17.0.0" implementation 'com.google.android.gms:play-services-base:16.0.1' implementation 'com.android.support:design:28.0.0' //Mandatory for App Inbox implementation "com.android.support:appcompat-v7:28.0.0" //Mandatory for App Inbox // Import the Firebase BoM implementation(platform("com.google.firebase:firebase-bom:32.8.0")) implementation("com.google.firebase:firebase-analytics") implementation("com.google.firebase:firebase-messaging") implementation("com.google.firebase:firebase-crashlytics") implementation("com.google.firebase:firebase-crashlytics-gradle") implementation("com.google.firebase:firebase-crashlytics-ndk") implementation("com.google.firebase:firebase-inappmessaging") implementation("com.google.firebase:firebase-inappmessaging") implementation("com.google.firebase:firebase-inappmessaging-display") implementation("com.google.firebase:firebase-perf") implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.android.support:multidex:1.0.3" implementation "com.facebook.react:react-native:+" // From node_modules implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { exclude group:'com.facebook.fbjni' } debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' exclude group:'com.squareup.okhttp3', module:'okhttp' } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' } if (enableHermes) { def hermesPath = "../../node_modules/hermes-engine/android/"; debugImplementation files(hermesPath + "hermes-debug.aar") releaseImplementation files(hermesPath + "hermes-release.aar") } else { implementation jscFlavor } implementation project(":react-native-fbsdk-next") implementation 'com.android.support:customtabs:28.0.0' } // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.implementation into 'libs' } apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) ``` #### `android/settings.gradle`: ```groovy rootProject.name = 'zyx' include ':@react-native-firebase_messaging' project(':@react-native-firebase_messaging').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/messaging/android') include ':react-native-fbsdk-next' project(':react-native-fbsdk-next').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk-next/android') apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Screenshot 2024-04-04 at 11 42 06β€―PM Screenshot 2024-04-04 at 11 42 15β€―PM Screenshot 2024-04-04 at 11 42 26β€―PM

Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 14.1.2 CPU: (8) arm64 Apple M1 Memory: 79.30 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.10.0 - ~/.nvm/versions/node/v16.10.0/bin/node Yarn: 1.22.19 - ~/.yarn/bin/yarn npm: 7.24.0 - ~/.nvm/versions/node/v16.10.0/bin/npm Watchman: 2023.11.20.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 23.4, iOS 17.4, macOS 14.4, tvOS 17.4, visionOS 1.1, watchOS 10.4 Android SDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9123335 Xcode: 15.3/15E204a - /usr/bin/xcodebuild Languages: Java: 11.0.20 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.67.4 => 0.67.4 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [x] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `19.1.2` - **`Firebase` module(s) you're using that has the issue:** - `"@react-native-firebase/analytics": "^19.1.2", "@react-native-firebase/app": "^19.1.2", "@react-native-firebase/auth": "^19.1.2", "@react-native-firebase/crashlytics": "^19.1.2", "@react-native-firebase/messaging": "19.1.2", "@react-native-firebase/perf": "^19.1.2", ` - **Are you using `TypeScript`?** - `Y` & `4.6.3` - **Gradle Version** - distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists


haozhutw commented 6 months ago

Same issue for me when I upgrade from 18.3.1 to 19.1.2, 18.3.1 works well, gradle sync successfully when upgrade to 19.1.2, but build apk failed.

haozhutw commented 6 months ago

I finally got my android app build successfully. Here's the process of how I resolve this issue, maybe others can refer to this.

I checked the code change history of react-native-firebase, found that the errors are caused by this commit, the JavaVersion was changed from VERSION_1_8 to VERSION_11 in all the components. I was using react-native-firebase v18.3.1, after upgrading to v18.3.2 the build errors started to happen, I change the JavaVersion back to VERSION_1_8 in all components and build APK successfully.

But I need to upgrade react-native-firebase to v19.2.0 which Firebase iOS SDK has a crash fix for Xcode 15.3+ and they fixed this issue, with v19.2.0 change JavaVersion can make the gradle sync successfully but still failed to build the APK. I got errors like this:

> Task :app:compileDevDebugKotlin
e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
e: /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/META-INF/kotlinx-coroutines-core.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/MyName/.gradle/caches/transforms-2/files-2.1/3b725eff63b16c939f46a22ad5112d43/jetified-ads-adservices-1.0.0-beta05-api.jar!/META-INF/ads-adservices_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/MyName/.gradle/caches/transforms-2/files-2.1/61a7257026bc40fdbc184e590ad1f814/jetified-kotlinx-coroutines-play-services-1.7.1.jar!/META-INF/kotlinx-coroutines-play-services.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/MyName/.gradle/caches/transforms-2/files-2.1/c97403e593c8225d56f69cc56ede319d/jetified-play-services-measurement-api-21.6.1-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.measurement_api_measurement_api.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.
e: /Users/MyName/.gradle/caches/transforms-2/files-2.1/e91f20d32b00d4a5295b53d346aff52d/jetified-kotlinx-coroutines-android-1.7.1.jar!/META-INF/kotlinx-coroutines-android.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/MyName/.gradle/caches/transforms-2/files-2.1/fa9d3ffece947b3cd920f6ba90343828/jetified-ads-adservices-java-1.0.0-beta05-api.jar!/META-INF/ads-adservices-java_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (20, 27): Class 'kotlinx.coroutines.CoroutineScope' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/CoroutineScope.class
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (21, 27): Class 'kotlinx.coroutines.Dispatchers' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/Dispatchers.class
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (22, 27): Unresolved reference: SupervisorJob
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (23, 27): Unresolved reference: launch
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (38, 28): Unresolved reference: SupervisorJob
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (39, 30): Class 'kotlinx.coroutines.CoroutineScope' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/CoroutineScope.class
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (39, 30): Interface CoroutineScope does not have constructors
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (39, 45): Class 'kotlinx.coroutines.Dispatchers' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/Dispatchers.class
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (39, 57): Class 'kotlinx.coroutines.MainCoroutineDispatcher' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/MainCoroutineDispatcher.class
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (39, 62): Using 'plus(CoroutineDispatcher): CoroutineDispatcher' is an error. Operator '+' on two CoroutineDispatcher objects is meaningless. CoroutineDispatcher is a coroutine context element and `+` is a set-sum operator for coroutine contexts. The dispatcher to the right of `+` just replaces the dispatcher to the left.
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (39, 62): Class 'kotlinx.coroutines.CoroutineDispatcher' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/CoroutineDispatcher.class
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/MediaService.kt: (199, 18): Suspend function 'buildMediaList' should be called only from a coroutine or another suspend function
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/data/DataSource.kt: (14, 27): Class 'kotlinx.coroutines.Dispatchers' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/Dispatchers.class
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/data/DataSource.kt: (15, 27): Unresolved reference: withContext
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/data/DataSource.kt: (38, 5): Unresolved reference: withContext
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/data/DataSource.kt: (38, 17): Class 'kotlinx.coroutines.Dispatchers' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/Dispatchers.class
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/data/DataSource.kt: (38, 29): Class 'kotlinx.coroutines.CoroutineDispatcher' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/CoroutineDispatcher.class
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/data/DataSource.kt: (94, 7): Unresolved reference: withContext
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/data/DataSource.kt: (94, 19): Class 'kotlinx.coroutines.Dispatchers' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/Dispatchers.class
e: /Users/MyName/Documents/subfolder/project-name/android/app/src/main/java/com/appname/media/data/DataSource.kt: (94, 31): Class 'kotlinx.coroutines.MainCoroutineDispatcher' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /Users/MyName/.gradle/caches/transforms-2/files-2.1/2a09f10c0acdea7fc57bde7c837e486c/jetified-kotlinx-coroutines-core-jvm-1.7.1.jar!/kotlinx/coroutines/MainCoroutineDispatcher.class

> Task :app:compileDevDebugKotlin FAILED

After research and tried a lot of solutions, I upgraded my kotlin version to 1.8.0, these errors should be caused by Firebase Android SDK, the firebase bom version is 32.8.0 in react-native-firebase v19.2.0, which is very high. I followed this doc to upgrade my gradle version to 6.8.3 in gradle-wrapper.properties like this

distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip

finally I got the app built successfully on Android Studio, the apk is running in dev mode.

But another issue happens when I build APK for release, the error log is like this, this happens for several dependencies.

[java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector cannot access class com.sun.tools.javac.code.Symbol$](https://stackoverflow.com/questions/70423297/java-lang-illegalaccesserror-class-org-gradle-internal-compiler-java-classnamec)

And I searched stackoverflow here and followed one of the answer and paste this in my gradle.properties, replaced my old settings of org.gradle.jvmargs

org.gradle.jvmargs=-Xmx4096m --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED

build APK again, finally it worked!! This is quite a long journey to get here. I tried a lot, my project is an old react-native project, and there are many dependencies, it's really hard to get all dependencies upgraded and compiled with higher version build tools, e.g AGP 8.0 or JDK 17+, so I have to make it compatible at the moment. Migrate the project to latest version of react-native takes a huge effort, I believe someone also has such trouble, but we have to do it sooner or later.

haozhutw commented 6 months ago

Shared my environments and configurations here, hope it helps. My project is really old(build with react-native v0.61.5), still using AGP 4.2.2, so anyone has AGP version higher than mine, should ignore my AGP version config.

android/build.gradle

buildscript {
    ext {
        ......
        kotlin_version = '1.8.0'
    }

dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'
         .......
    }

part of the configurations in android/app/build.gradle, force below plugins with the same kotlin version.

force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
force "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"

android/gradle/wrapper/gradle-wrapper.properties, the gradle version should follow this doc.

......
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip

android/gradle.properties

org.gradle.jvmargs=-Xmx4096m --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED

after install react-native-firebase v19.2.0+, we need to change the JavaVersion back to VERSION_1_8 in build.gradle inside each component. It's better to build a patch for each, so there will be several patch files. I use yarn patch-package to build the patches.

haozhutw commented 6 months ago

latest news --- build apk successfully, but build .aab failed... πŸ˜‚πŸ˜‚πŸ˜‚

dooamindshine commented 6 months ago

I am also facing lots of problem with this, we deploy everything with .aab , If anyone got any solutions might be very helpfull.

mikehardy commented 6 months ago

This looks harder than upgrading to a supported version, the versions mentioned aren't workable I don't think. In general react-native ecosystem supports current version and 2 older versions of react-native

Java 17 is best now, moving to 21 soon

haozhutw commented 6 months ago

Good news! I tried again to build my Android app bundle and it's successful! I didn't change anything since I posted here except my mac was crashed and restarted after that. I run ./gradlew clean bundleRelease to build the app bundle, and I have built the app bundle by Jenkins on the other mac, it's also successful. So it doesn't make sense that apk can be built successfully but aab failed. I encountered an error like this when I build aab failed last time, but nothing was changed on my end and now everything works well(after the mac was restarted). I thought that might be an issue related to JDK version, so I downloaded OpenJDK 17+ today and ready to test again. It's just successful before I change the JDK version, I'm using JDK 11 now.

image

@dooamindshine maybe you can have a try with my steps above. Good luck!

mikehardy commented 6 months ago

I'm going to close this as it does not seem actionable here, but do feel free to continue collaborating amongst yourselves (we don't lock issues normally, so you can comment no problem). We can reopen if there is some actual change needed in the repo