Describe your issue here
I am currently moving my Android project to RN 0.60.0, and trying to take care along the way.
I have got to a point where my project will build and run on my device, and then crashes because of missing Firebase libraries (this makes sense, because at this point I haven't included the libraries yet in my Android project.
But, as soon as I include the implementation project(':react-native-firebase')
in my build.gradle
file, my build fails with the error
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ':app:mergeLibDexDevDebug'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Program type already present: io.invertase.firebase.BuildConfig
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
I am unsure how to overcome this issue, or why its exactly happening. From what the help in the errors tell me, its due to a 'duplicate class' (potentially) but Im not sure why or how at this point.
Click To Expand
#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like:
# N/A
#### `AppDelegate.m`:
// N/A
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`:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compileSdkVersion = 28
buildToolsVersion = '28.0.3'
minSdkVersion = 21
targetSdkVersion = 26
supportLibVersion = "27.1.1"
googlePlayServicesVersion = "16.+"
firebaseVersion = "17.6.0"
}
repositories {
google()
maven {
url 'https://maven.fabric.io/public'
}
maven {
url 'https://plugins.gradle.org/m2/'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.1'
classpath 'io.fabric.tools:gradle:1.28.1'
classpath 'com.google.firebase:perf-plugin:1.2.1'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.5'
}
}
allprojects {
repositories {
mavenLocal()
maven {
url "$rootDir/../node_modules/react-native/android"
}
maven {
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
subprojects { subproject ->
afterEvaluate{
if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
wrapper {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
#### `android/app/build.gradle`:
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: "com.android.application"
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: "io.fabric"
project.ext.envConfigFiles = [
devdebug: ".env.debug",
devrelease: ".env.debug",
productionrelease: ".env.production",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
import com.android.build.OutputFile
import com.google.gms.googleservices.GoogleServicesPlugin
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
//apply from: "../../node_modules/react-native-sentry/sentry.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
def useIntlJsc = false
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
flavorDimensions "versionCode"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.app"
resValue "string", "build_config_package", "com.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 132
versionName "1.2.0"
ndk {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
}
testBuildType System.getProperty('testBuildType', 'debug')
missingDimensionStrategy "minReactNative", "minReactNative46"
testInstrumentationRunner "android .support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
resValue "string", "app_name", "app"
signingConfig signingConfigs.release
buildConfigField "String", "CODEPUSH_KEY", '"xxxx"'
buildConfigField "String", "ADYEN_PUBLIC_KEY", '"xxxxx"'
}
debug {
resValue "string", "app_name", "app DEV"
debuggable true
buildConfigField "String", "CODEPUSH_KEY", '"xxxx"'
buildConfigField "String", "ADYEN_PUBLIC_KEY", '"xxxxx"'
}
}
flavorDimensions "standard"
productFlavors{
dev {
applicationId "com.app.development"
dimension "standard"
}
production {
applicationId "com.app"
dimension "standard"
}
}
dexOptions {
preDexLibraries = false
}
// 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:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
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 project(':react-native-code-push')
implementation project(':react-native-splash-screen')
implementation project(':react-native-firebase')
// implementation "com.google.firebase:firebase-core:17.2.0"
// implementation "com.google.firebase:firebase-database:19.0.0"
// implementation ("com.google.firebase:firebase-auth:19.0.0") {
// exclude group: "com.google.android.gms"
// }
// implementation "com.google.firebase:firebase-perf:19.0.0"
// implementation "com.google.firebase:firebase-functions:19.0.1"
// implementation "com.google.firebase:firebase-messaging:20.0.0"
// implementation "com.google.firebase:firebase-storage:19.0.0"
// implementation "com.google.firebase:firebase-firestore:21.0.0"
// implementation "com.google.firebase:firebase-dynamic-links:19.0.0"
// implementation "com.google.firebase:firebase-invites:17.0.0"
implementation "com.adyen.checkout:drop-in:3.1.1"
implementation "com.adyen.checkout:card-ui:3.1.1"
implementation "com.adyen.checkout:ideal-ui:3.1.1"
implementation 'com.facebook.react:react-native:0.60.0'
implementation "com.google.android.gms:play-services-base:17.1.0"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
if (useIntlJsc) {
implementation 'org.webkit:android-jsc-intl:+'
} else {
implementation 'org.webkit:android-jsc:+'
}
}
// 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.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle")
applyNativeModulesAppBuildGradle(project)
googleServices { disableVersionCheck = true }
#### `android/settings.gradle`:
rootProject.name = 'app'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesSettingsGradle(settings)
include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
include ':react-native-firebase'
project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android')
include ':react-native-config'
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
include ':react-native-splash-screen'
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
include ':app'
#### `MainApplication.java`:
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.facebook.react.PackageList;
import org.devio.rn.splashscreen.SplashScreenReactPackage;
import com.microsoft.codepush.react.CodePush;
import com.klikkie.shareManager.SharePackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.klikkie.adyenReactNative.AdyenPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add(new SplashScreenReactPackage());
packages.add(new CodePush("xxxxx", MainApplication.this, BuildConfig.DEBUG));
return packages;
}
@Override
protected String getJSMainModuleName() {
return "index";
}
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
#### `AndroidManifest.xml`:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:largeHeap="true"
android:testOnly="false"
android:theme="@style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="app" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
<service android:name=".adyenReactNative.AdyenDropInService" android:permission="android.permission.BIND_JOB_SERVICE"/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="xxxx" />
<meta-data
android:name="firebase_performance_collection_enabled"
android:value="true" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:grantUriPermissions="true"
tools:replace="android:authorities"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths"
tools:replace="android:resource" />
</provider>
</application>
</manifest>
Click To Expand
**`react-native info` output:**
System:
OS: macOS 10.14.6
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 3.44 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.15.0 - ~/.nvm/versions/node/v11.15.0/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.7.0 - ~/.nvm/versions/node/v11.15.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5791312
Xcode: 10.3/10G8 - /usr/bin/xcodebuild
npmPackages:
@react-native-community/cli: ^2.9.0 => 2.9.0
react: ^16.8.6 => 16.8.6
react-native: ^0.60.0 => 0.60.5
- **Platform that you're experiencing the issue on**:
- [ ] iOS
- [x] Android
- [ ] **iOS** but have not tested behavior on Android
- [x] **Android** but have not tested behavior on iOS
- [ ] Both
- **`react-native-firebase` version you're using that has this issue:**
- `5.1.0`
- **`Firebase` module(s) you're using that has the issue:**
- `firebase`
- **Are you using `TypeScript`?**
- `Y`
Think react-native-firebase
is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]
React Native Firebase
and Invertase
on Twitter for updates on the library.I seem to have fixed the issue.
The com.google.firebase:perf-plugin:1.2.1
was causing the problem for me. I've removed it, and Im no longer getting that issue. :)
okay, but then you will lost performance monitoring I think - my best bet helping people is to forget troubleshooting and just demonstrate how to build rn60 + react-native-firebase from scratch - https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh
Thanks @mikehardy .
Yeah I spoke too soon. The build was working in debug variant, but as soon as I tried a release version, I got the same error again. So now debug build works without problem, but release has the problem.
(I haven't added the perf-plugin
back, but added a couple other of firebase libraries.)
I will fiddle around a little more to understand what's going on, and why, and if I just keep getting stuck I will try the 'from scratch' approach.
The reason I made it a script is so you can just scan it to see what the process looks like. I wouldn't advocate actually nuking your app, just the script shows you the exact steps for react-native-firebase integration. If I were having problems, I might revert to before I started, then follow the script along, applying the same changes to my project. Would be the work of maybe 30 mins
Actually I take that back - I just re-read that is an rn59 to rn60 move - took me a couple days! The 'upgrade-helper' (googleable) was very useful for that. But cleaning up my .xcodeproj by unlinking things and then trashing Xcode objects to make way for auto-linking was painful
I think I found my ultimate error here.
In my package.json
file I had, at some point earlier, installed both the @react-native-firebase/app
and the react-native-firebase
packages.
It seems like the clever auto-importing/linking was bringing both these into the Android project (as it should) which was causing the duplicate class errors. I removed the @react-native-firebase/
packages and now most of my issues have been resolved. :)
Like @simon-klikkie said, this error still persist
The command yarn add @react-native-firebase/app (in >= 0.60.x version off react-native) Install two packages:
@react-native-firebase/app
react-native-firebase <-- Old version for 0.59.x of react-native
This issue shold be mentioned in the documentation.
Thanks for this package.
My issue solved with this code in android/app/build.gradle
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
implementation 'androidx.multidex:multidex:2.0.1'
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
Hi, there
I have just face the issues above.
I am going to use @react-native-firebase/crashlytics.
In my project, I have already imported react-native-firebase.
And the @react-native-firebase/crashylytics needs @react-native-firebase/app.(in this document: https://invertase.io/oss/react-native-firebase/v6/crashlytics/quick-start)
So I have imported it too.
BTW, I can build my project. (failed in 'react-native run-android')
the issues like below:
Task :app:transformClassesWithMultidexlistForDebug FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See
https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
164 actionable tasks: 8 executed, 156 up-to-date
D8: Program type already present: io.invertase.firebase.BuildConfig
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
. com.android.build.api.transform.TransformException: Error while generating the main dex list:
Error while merging dex archives:
Program type already present: io.invertase.firebase.BuildConfig
Learn how to resolve the issue at
https://developer.android.com/studio/build/dependencies#duplicate_classes.
- 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 5s
what is my mistakes?
I think I found my ultimate error here.
In my
package.json
file I had, at some point earlier, installed both the@react-native-firebase/app
and thereact-native-firebase
packages.
It seems like the clever auto-importing/linking was bringing both these into the Android project (as it should) which was causing the duplicate class errors. I removed the@react-native-firebase/
packages and now most of my issues have been resolved. :)
How can i use in-app-messaging module along firebase v5?
As I realized, firebase v5 doesn't have any doc about that.
Note: I want both notification and in-app-messaging modules together and firebase v6 doesn't support notification module yet
@HessiPard you are asking questions in an off-topic way - this was mentioned in the v6 notifications tracker. This is a closed unrelated issue. If there are no docs in v5 for a feature that means it is not implemented. You can also search the source if you like - that's what open source lets you do. You won't find an in-app messaging package in v5. And v5 and v6 don't work together so there's not a solution. Asking questions on unrelated issues won't solve that unfortunately. You likely want v6 with one of the other notifications packages available in the react-native ecosystem.
Sorry @mikehardy .
I integrated in-app-messaging module with firebase v5 with help of this thread.
It just need adding the SDK and it should better mentioned in the firebase v5 doc.
@HessiPard Hey! now that is useful! You can add a new module to the rnfirebase.io sidebar with an edit to this page: https://github.com/invertase/react-native-firebase-docs/blob/v5.x.x/docs/_sidebar.yaml and create a new in-app-messaging directory with a short getting-started.md file and just point the link from sidebar to '/getting-started' and I think it will all hook up and you can save the hassle for all the other people looking for this?
Sure.
I will do that ...
@threeq1818
what is my mistakes?
After going through the upgrade guide, I was still getting this error as well:
Error while merging dex archives:
Program type already present: io.invertase.firebase.BuildConfig
Once manually removing the ./node_modules/react-native-firebase
folder, I was able to successfully run: npx react-native run-android
I'm facing this error right now. Here is my package.json
"@react-native-firebase/app": "^6.2.0",
"@react-native-firebase/database": "^6.2.0",
"react-native-firebase": "^5.6.0",
I need to use Crashlytics and Database. Any solution, please?
you can't mix v5 and v6 of react-native-firebase @ThanhQuang1410
@mikehardy Thank you for your support. I've removed v5 and it's work. Thanks a lots.
@simon-klikkie Thanks for your post, I got the same issue as well, but I am not quit clear about your solution here. Do you mean if you have installed react-native-firebase
, then you do not need to install @react-native-firebase/app
?
I am currently working on an existing project installed with
"react-native-firebase": "^5.1.1",
I try to add new features with ml-natural-language, so the following package is installed with npm -i
@react-native-firebase/app": "^0.5.0,
@react-native-firebase/ml-natural-language": "^0.5.0",
As ml-natural-language documentation specically indicates @react-native-firebase/app is required. then I encountered the error:
Program type already present: io.invertase.firebase.BuildConfig
Because it is an existing project, I can not simply remove react-native-firebase
, so what I can do here?
Remove the @react-native-firebase/app": "^0.5.0"
in package.json
and npm install
again?
Or start from the scratch, only install and link @react-native-firebase/ml-natural-language": "^0.5.0
?
BTW, the react-native version is 0.59.10. I used npx jetifier
and enabled AndroidX support.
PS: @mikehardy How the version of @react-native-firebase/(app | ml-natural-language)
is correlate with react-native-firebase
version?
@gitathrun that can't work, you're mixing react-native-firebase v5 and v6. They don't mix. If you want ML stuff you'll need to get modern -- meaning react-native 0.60+ and react-native-firebase v6, and all the updated google firebase Pods and Android libraries.
react-native run-android
was throwing this error for me. I opened the android
directory from Android Studio and ran it from there, and everything worked fine.
Hi All, I have the same issue here,
I have been using,
Package.json ->
"@react-native-firebase/app": "^6.3.4",
"@react-native-firebase/crashlytics": "^6.3.4",
"react-native-firebase": "^5.6.0",
Error - >
com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Program type already present: io.invertase.firebase.BuildConfig
@chamilacnb looks like you're mixing v5 & v6. From reading above, it seems like you can't do that.
see: https://github.com/invertase/react-native-firebase/issues/2561#issuecomment-582422061
I think I found my ultimate error here.
In my
package.json
file I had, at some point earlier, installed both the@react-native-firebase/app
and thereact-native-firebase
packages.
It seems like the clever auto-importing/linking was bringing both these into the Android project (as it should) which was causing the duplicate class errors. I removed the@react-native-firebase/
packages and now most of my issues have been resolved. :)
thank you sir... thank youuu
I now have this error too:
D8: Program type already present: io.invertase.firebase.messaging.BuildConfig
I am not mixing v5 and v6 nor do I reference react-native-firebase
anywhere instead of
@react-native-firebase
.
After cleaning the project in Android Studio I get the error: Program type already present: io.invertase.firebase.messaging.ReactNativeFirebaseMessagingHeadlessService
I use these in my package.json:
"@react-native-firebase/app": "^6.4.0",
"@react-native-firebase/auth": "^6.4.0",
"@react-native-firebase/firestore": "^6.4.0",
"@react-native-firebase/messaging": "^6.4.0",
and this is in my package-lock.json
:
"@react-native-firebase/app": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/@react-native-firebase/app/-/app-6.4.0.tgz",
"integrity": "sha512-QCV+SY0hdx3OTR+KQngvF/ejuPkEP8V5pr0ie8hic/yV6vcGtrMEN/NGSvgILjbPYRhspYDZSi4HdTgc70WUIA==",
"requires": {
"@react-native-firebase/app-types": "6.4.0",
"opencollective-postinstall": "^2.0.1",
"superstruct": "^0.6.2"
}
},
"@react-native-firebase/app-types": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/@react-native-firebase/app-types/-/app-types-6.4.0.tgz",
"integrity": "sha512-c8rYdh4DJReKjTl/jUjPNrCwhbAlNcgCch3n3rCOuATjYleiSt3zhskn37aRQeCOKohvNzuxvYy5ZYtzAxMYmw=="
},
"@react-native-firebase/auth": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/@react-native-firebase/auth/-/auth-6.4.0.tgz",
"integrity": "sha512-OobhjpdcH/qcENKQjZE7I7y03SezU3ZOVmKFItesWovfPqlqFdRHTYQ18jqZsDC6YhrlxiIDE40ra8xRPCN5KA=="
},
"@react-native-firebase/firestore": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/@react-native-firebase/firestore/-/firestore-6.4.0.tgz",
"integrity": "sha512-iiR0hJ1d1Ka6n23fczfWHjfX0j7mLAFqSJFBA252yKKcOxN7Z7fe8rx/Ueq+gDwquc3lWo7aITzWHrE1u1TQxw=="
},
"@react-native-firebase/messaging": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/@react-native-firebase/messaging/-/messaging-6.4.0.tgz",
"integrity": "sha512-Ko+jAF7jgNZnGu697RE+o4RUB1Rqsqfk6+p+K2xuGFlorWLHFYrpqWuKyMZ13jieMp+NGg2C19PWzUJ0ozcdNg=="
},
I am using React Native v0.61.4
I have now rolled back to a stable version of my app that compiles, but anytime I install and link any package (I have just tried react-native-linear-gradient
for example) the app will not build and I get the error: Program type already present: io.invertase.firebase.messaging.BuildConfig
.
I was able to resolve this issue by disabling auto-linking for the analytics module (and all other modules used in the project). Since the links to manual integration in the migration docs are deadlinks (might be useful to change those, btw), it's a bit hard to find out how to manually integrate the analytics module without auto-linking.
Anyway, here are the steps required for fixing this in the analytics module - depending on your error messages, you might be required to do similar steps for your other react-native-firebase
modules:
android/settings.gradle
: Make sure you include Analytics moduleinclude ':@react-native-firebase_analytics'
project(':@react-native-firebase_analytics').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/analytics/android')
android/app/build.gradle
: Make sure you include Analytics moduleimplementation project(':@react-native-firebase_analytics')
android/app/src/.../MainApplication.java
: Make sure you import Analytics package and add it to getPackages()
:import io.invertase.firebase.analytics.ReactNativeFirebaseAnalyticsPackage;
// to find out the correct imports for other packages, just go to your node_modules/@react-native-firebase folder and follow the according path structure for Android
// (...)
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// your other packages that haven't been auto-linked
packages.add (new ReactNativeFirebaseAnalyticsPackage());
// ..
return packages;
}
react-native-config.js
(in you app's root folder): Make sure you disable auto-linking for the Analytics module:module.exports = {
dependencies: {
["@react-native-firebase/analytics"]: {platforms: {android: null}},
},
}
Clean gradle: cd android && ./gradlew clean && cd ..
Run Android project, the error Program type already present: io.invertase.firebase.messaging.BuildConfig
should not pop up any more.
In my project, I had to repeat this steps for all react-native-firebase
packages I used, so for the sake of completeness, here are the other imports I'm using in my MainApplication.java
file:
import io.invertase.firebase.app.ReactNativeFirebaseAppPackage;
import io.invertase.firebase.analytics.ReactNativeFirebaseAnalyticsPackage;
import io.invertase.firebase.auth.ReactNativeFirebaseAuthPackage;
import io.invertase.firebase.database.ReactNativeFirebaseDatabasePackage;
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage;
import io.invertase.firebase.storage.ReactNativeFirebaseStoragePackage;
In my case, with android unlink firebase/app, firebase/messaging.
rm -rf android/.gradle
fixed the issue for me
I think I found my ultimate error here.
In my
package.json
file I had, at some point earlier, installed both the@react-native-firebase/app
and thereact-native-firebase
packages.
It seems like the clever auto-importing/linking was bringing both these into the Android project (as it should) which was causing the duplicate class errors. I removed the@react-native-firebase/
packages and now most of my issues have been resolved. :)
I need to keep both in my project. Then what is the solution?
@PrantikMondal that will never be a supported configuration, sorry. The idea of mixing pre-v6 and post-v6 react-native-firebase is unsupportable for reasons exactly like this
i am using @react-native-firebase/dynamic-links library that need @react-native-firebase/app library for support. Also i am using firebase notification and firebase auth for signInAnonymously. For these support need react-native-firebase library. So how can i deal with?
@PrantikMondal that will never be a supported configuration, sorry. The idea of mixing pre-v6 and post-v6 react-native-firebase is unsupportable for reasons exactly like this
i am using @react-native-firebase/dynamic-links library that need @react-native-firebase/app library for support. Also i am using firebase notification and firebase auth for signInAnonymously. For these support need react-native-firebase library. So how can i deal with?
@PrantikMondal migrate to a full-featured notification package separate from react-native-firebase then upgrade all the remaining react-native-firebase packages to their equivalent in the @react-native-firebase
namespace. This topic is covered all over, but options are react-native-push-notification react-native-notifications and notifee for full coverage of local device notification APIs
@PrantikMondal migrate to a full-featured notification package separate from react-native-firebase then upgrade all the remaining react-native-firebase packages to their equivalent in the
@react-native-firebase
namespace. This topic is covered all over, but options are react-native-push-notification react-native-notifications and notifee for full coverage of local device notification APIs
Thanks man for quick reply. It helped. Again thanks a lot. Have a nice day.
"@react-native-community/masked-view": "^0.1.10",
"@react-native-firebase/app": "^8.4.5",
"@react-native-firebase/auth": "^9.3.0",
"@react-native-firebase/messaging": "^7.9.0",
"@react-navigation/native": "^5.7.6",
"@react-navigation/stack": "^5.9.3",
"react": "16.13.1",
"react-native": "0.63.3",
"react-native-gesture-handler": "^1.8.0",
"react-native-push-notification": "^6.1.1",
"react-native-safe-area-context": "^3.1.8",
"react-native-screens": "^2.11.0"
in my package.json:
I resolved it by just remove react-native-firebase because it's make conflict with @react-native-firebase/app
I seem to have fixed the issue.
Thecom.google.firebase:perf-plugin:1.2.1
was causing the problem for me. I've removed it, and Im no longer getting that issue. :)
where is the location of that file
Most helpful comment
I think I found my ultimate error here.
In my
package.json
file I had, at some point earlier, installed both the@react-native-firebase/app
and thereact-native-firebase
packages.It seems like the clever auto-importing/linking was bringing both these into the Android project (as it should) which was causing the duplicate class errors. I removed the
@react-native-firebase/
packages and now most of my issues have been resolved. :)