React-native-notifications: error building on android : constructor RNNotificationsPackage in class RNNotificationsPackage cannot be applied to given types

Created on 2 Jul 2018  路  11Comments  路  Source: wix/react-native-notifications

Hi I'm trying to build the app on android , but I''m getting the follwoing error :
error: constructor RNNotificationsPackage in class RNNotificationsPackage cannot be applied to given types;
required: Application
found: no arguments
reason: actual and formal argument lists differ in length
the error is located in the android\app\src\mainjava\com\test\MainApplication.java :
`import android.app.Application;

import com.facebook.react.ReactApplication;
import com.oblador.keychain.KeychainPackage;
import com.bitgo.randombytes.RandomBytesPackage;
import com.wix.reactnativenotifications.RNNotificationsPackage;
import com.ibeacon.simulator.BeaconBroadcastPackage;
import com.mackentoch.beaconsandroid.BeaconsAndroidPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
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() {
  return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
        new KeychainPackage(),
        new RandomBytesPackage(),
        new RNNotificationsPackage(),
        new BeaconBroadcastPackage(),
        new BeaconsAndroidPackage()
  );
}

@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

in your MainApplication.java
replace: new RNNotificationsPackage(),
with: new RNNotificationsPackage(MainApplication.this),

All 11 comments

in your MainApplication.java
replace: new RNNotificationsPackage(),
with: new RNNotificationsPackage(MainApplication.this),

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

The issue has been closed for inactivity.

I got this error with react-native 0.61.2 and react-native-notifications 2.1.5. It was fixed by making 2 changes.

Change#1:
Applying the following change in the file \android\app\src\mainjava....\MainApplication.java

......
@Override
protected List<ReactPackage> getPackages() {
  @SuppressWarnings("UnnecessaryLocalVariable")
  List<ReactPackage> packages = new PackageList(this).getPackages();
  // packages.add(new RNNotificationsPackage()); // REMOVE this 
  packages.add(new RNNotificationsPackage(MainApplication.this)); // ADD this
  return packages;
}
.....

Change#2:
Creating a file in the project's root folder (the folder where package.json is)

The file name:
react-native.config.js

File contents:

module.exports = {
  dependencies: {
    'react-native-notifications': {
      platforms: {
        android: null
      },
    },
  },
}

I'm still getting:
constructor RNNotificationsPackage in class RNNotificationsPackage cannot be applied to given types; new RNNotificationsPackage(), ^ required: Application found: no arguments reason: actual and formal argument lists differ in length

Even after those changes :(

Try the following:
packages.add(new RNNotificationsPackage(MainApplication.this));

instead of the following:
packages.add(new RNNotificationsPackage(this.getApplication()));

Try the following:
packages.add(new RNNotificationsPackage(MainApplication.this));

instead of the following:
packages.add(new RNNotificationsPackage(this.getApplication()));

Thanks @Bilal-Abdeen, I've tried that too, same error :(

@matheusbaumgart I am sorry, mate. I am not sure what could be the reason for this. I suggest you double-check "Change#2" in my post (above).

@Bilal-Abdeen I've recreated the file and it now works, mysteriously. I'm going back to another PN library as this one doesn't have Android Scheduled PN :(

Thanks for your help

@matheusbaumgart It is great that you got it to work.
I am not sure what functionality does Android Scheduled PN entail, and you don't need to tell me (as it is outside the scope of this issue)!
However, I just thought of letting you know that I am using Google Cloud Functions to "send" notifications, and this library (React-Native-Notifications) to "receive" these notifications. I do NOT need scheduling. If I did, I would probably investigate doing it using Google Cloud Functions. If you could not find a library that does what you need, you might want to consider the combination of Google Cloud Functions and this library.

I am having this issue after trying all the solutions mentioned above but it still does not work, i am on
react-native: 0.60.6
react-native-notifications: 1.1.17
Anyone know how to solve this ?

error: constructor RNNotificationsPackage in class RNNotificationsPackage cannot be applied to given types; new RNNotificationsPackage(), ^ required: Application found: no arguments reason: actual and formal argument lists differ in length

Was this page helpful?
0 / 5 - 0 ratings