React-native-push-notification: RNPushNotification tried to override RNPushNotification

Created on 22 Oct 2019  路  8Comments  路  Source: zo0r/react-native-push-notification

Why this happen ?

`package com.awesomefyp;

import android.app.Application;
import android.util.Log;

import com.facebook.react.PackageList;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;

import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import io.invertase.firebase.firestore.RNFirebaseFirestorePackage;
import io.invertase.firebase.functions.RNFirebaseFunctionsPackage;
//import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;

import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;

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() {
        @SuppressWarnings("UnnecessaryLocalVariable")
        List<ReactPackage> packages = new PackageList(this).getPackages();
        // Packages that cannot be autolinked yet can be added manually here, for example:
        // packages.add(new MyReactNativePackage());
        packages.add(new RNFirebaseAuthPackage());
        packages.add(new RNFirebaseFirestorePackage());
        packages.add(new RNFirebaseFunctionsPackage());
        // packages.add(new RNFirebaseMessagingPackage());
        packages.add(new ReactNativePushNotificationPackage());
        return packages;
    }

    @Override
    protected String getJSMainModuleName() {
        return "index";
    }
};

@Override
public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
}

@Override
public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
}

}
`

Stale

Most helpful comment

Hey, probably, autolinking is enough, so you can just remove this line:
packages.add(new ReactNativePushNotificationPackage());

All 8 comments

Same problem existed, after remove duplicated import.

`package com.awesomefyp;

import android.app.Application;
import android.util.Log;

import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.facebook.react.PackageList;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;

import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import io.invertase.firebase.firestore.RNFirebaseFirestorePackage;
import io.invertase.firebase.functions.RNFirebaseFunctionsPackage;

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() {
        @SuppressWarnings("UnnecessaryLocalVariable")
        List<ReactPackage> packages = new PackageList(this).getPackages();
        // Packages that cannot be autolinked yet can be added manually here, for example:
        // packages.add(new MyReactNativePackage());
        packages.add(new RNFirebaseAuthPackage());
        packages.add(new RNFirebaseFirestorePackage());
        packages.add(new RNFirebaseFunctionsPackage());
        packages.add(new ReactNativePushNotificationPackage());
        return packages;
    }

    @Override
    protected String getJSMainModuleName() {
        return "index";
    }
};

@Override
public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
}

@Override
public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
}

}
`

can some teach me how to set canOverrideExistingModule = true. Thank you. This will more faster to solve my problem first.

I am also facing same issue..

Hey, probably, autolinking is enough, so you can just remove this line:
packages.add(new ReactNativePushNotificationPackage());

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

I agree with @kaaoo that autolinking is enough, but in my case I also had to do the following as listed below, and then the whole thing worked again. I hope this works for you as well.

For a clean android project run the following commands. Just change the directories to suit yours. (I use a Windows laptop so if using Mac/Linux commands just change it.)

In your project root dir run the commands below:

cd android

gradlew clean

cd ../

npm cache clean --force

npx react-native start --reset-cache

npx react-native run-android

In v 7.x.x i had to create a channel. Working with default channel didn't worked.

Hi @sudhiryadav

Yes, it's explained in the CHANGELOG.

Regards

Was this page helpful?
0 / 5 - 0 ratings