React-native-push-notification: Android build error with [email protected]

Created on 27 Jul 2016  路  42Comments  路  Source: zo0r/react-native-push-notification

I get this error when building with [email protected]:

node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:64: error: method does not override or implement a method from a supertype
    @Override
    ^
1 error

Quick link to line

Most helpful comment

Rolling back to 2.0.1 fixed it for now, while still being on rn 0.30.0
"react-native-push-notification": "2.0.1"

All 42 comments

I'm having the same error.

Are you using other external packages that require push? Like Firebase?

@rturk, good idea, I disabled all other external packages. Unfortunately the error is still present.

Same. I'm encountering this error with rn 0.30.0 and 2.0.2 of the app. Has anyone gotten this to work correctly?

same here

Rolling back to 2.0.1 fixed it for now, while still being on rn 0.30.0
"react-native-push-notification": "2.0.1"

Had this problem also, had to

npm cache clear
rm -Rf node_modules
npm install

After than 2.0.2 + rn 0.30.0 works properly.

I'm having the same error :( : "react-native": "^0.30.0", "react-native-push-notification": "^2.0.1"

error: method does not override or implement a method from a supertype
@Override
^

Did you guys all upgrade from a previous version of RN? For me the error was fixed after I ran react-native upgrade, and made sure all files in android/ were up-to-date.

I tried [email protected] with 2.0.2 (commit #0b019670) and it requires to remove the @Override keyword and leave the onNewIntent function where it is.

Re-running the upgrade, and ensuring I got everything, worked for me.

Everything is updated and this is the error I get trying to compile it with [email protected]:

:react-native-push-notification:compileReleaseJavaWithJavac ./node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:64: error: method does not override or implement a method from a supertype @Override ^ 1 error :react-native-push-notification:compileReleaseJavaWithJavac FAILED

I found out that my configuration in ./android/build.gradle was not correctly set. It needs to be set to:
url "$rootDir/../node_modules/react-native/android"
instead of
url "$projectDir/../../node_modules/react-native/android"

I have the same issue on 0.33-rc but it works on 0.32. Not sure what it's coming from...

I am getting this with RN0.33.0 and neither rn upgrade nor nuking node_modules solved this.

I've solved this by opening project in Android studio. Open RNPushNotification.java. Hit Ctrl+I (Implement methods). Choose onActivityResult. Delete former onActivityResult and save.

I looked at your commit - as far as I can see, nothing was actually changed except some new lines. Not sure how that is going to fix this issue?

@julienvincent that is actually the strange part. Compiler was complaining about not implementing method onActivityResult. So I've opened Android Studio -> implements method. It created new method onActivityResult and I deleted old declaration. Compiler was happy. And just after that I've realised the method declaration is same, so actually only empty lines were added. Very strange. However when I install module from npm, it happens again.

/Users/finch/dev/mapilary/Courier/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:30: error: RNPushNotification is not abstract and does not override abstract method onActivityResult(Activity,int,int,Intent) in ActivityEventListener
public class RNPushNotification extends ReactContextBaseJavaModule implements ActivityEventListener {
       ^
../node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:168: error: method does not override or implement a method from a supertype
    @Override
    ^
2 errors

Ok. I've found that npm version is not same as master on github (but version numbers are the same). I've only checked build.gradle and it differs. Maybe that is the reason. Installed from github instead of npm and no compilation error occured.

So I would say npm version should be reuploaded.

The github version would differ due to the repo owner doing additional work on the project since last release. But I agree, it would be nice if @zo0r could release a new patch version to fix this problem. In the meantime I have found that using 2.0.1 does indeed fix this as mentioned by @skunkworker.

Ok got you. So the problem is already fixed in master. So publishing new version to npm will also fix this problem.

Yes it would seem so :) I think I will switch to installing from github as well for now.

Just published 2.1.0

@zo0r Thanks! 馃憤

I have v2.0.1 and RN 0.29.1

And same error:

/Users/finch/dev/mapilary/Courier/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:30: error: RNPushNotification is not abstract and does not override abstract method onActivityResult(Activity,int,int,Intent) in ActivityEventListener
public class RNPushNotification extends ReactContextBaseJavaModule implements ActivityEventListener {
       ^
../node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:168: error: method does not override or implement a method from a supertype
    @Override
    ^
2 errors

How can i fix it?

@zo0r just commented saying he published 2.1.0 so give that version a try.

But 2.1.0is for RN >= 0.33. I have RN v0.29.1 and cant upgrade at the moment the RN version

2.1.0 may still work on rn29, though I am not too sure.

I'm in the process of merging a different PR but can look at this after. Think it should be possible to get it working on both 33 and earlier.

I upgrade the RNPN v2.1.0 on same RN v0.29.1. It works on iOS but on Android have the same problem.

@zo0r some idea of can i fix it?

@luisfuertes for RN v0.29.1 try using 2.0.1
npm install [email protected]

I've just pushed PR #172 to master, along with a load of fixes to it. Included was a temporary change to make it compile on rn 0.32. Can someone who's on RN 0.33 please check if master still works for them?

@npomfret nice, but I think there is a breaking change for RN 0.33 that not work for RN 0.32.

Also I compiled and tested it on RN 0.33 and its working. Just let me know when you want to release it to NPM.

@zo0r before 2.1.0 i tried with 2.0.1 (I posted comment on this thread) but same problem.

That's good that it works on RN0.33 because I've been testing on rn0.32 (haddn't tried 33 yet). Hold off on the release though, it was quite a big change. Wouldn't mind getting a few people to try it first.

To fix the incompatibility problem I took out the @Override annotations, and left both implementations of the problematic method in. So I think thats why it works with RN33 and earlier now. It was a guess though, apologies if its not correct.

The annotations are only a compile-time tool and have no effect at runtime. In a sense they're totally optional. IMO it's always a good idea to use them, commenting them out is a hack, but until its decided that this project only supports the latests RN (maybe?) then I guess we can leave both implementations of the method in.

I'd suggest that supporting more than 1 version of RN is going to be a nightmare. Perhaps each time RN becomes incompatible we simply make a branch for the old one, and keep master compatible with the latest RN? Then just link to the branch on the README file for this people who want the old version.

In my opinion there is no point for later versions of the project to support earlier versions of RN. As long as which package versions support which versions of RN is documented, then it will be better to provide support for only the current version of RN in master.

I'm inclined to agree. If people want new features and fixes they need to upgrade their version or RN. Otherwise they're free to fork and maintain their own version.

For compile project i have to delete one parameter in OnActivityResult
../node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java

I change

@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
...
}

for

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
...
}

Now project compile, but i have to try if it works.

EDIT: function onRegister never is called. I think it doesnt works now
EDIT2: Ok i had bad senderID, with other app senderID it return a token. I have to try to send me a push

Master currently contains both methods, but as I think the approach is to only support the latest RN that won't be the case going forward.

was using RN 0.33 and upgrading to react-native-push-notification 2.1.0 worked, thank you!

I am using React native 0.47.1 with react-native-push-notification 3.0.0. When trying to build I get

/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/ReactNativePushNotificationPackage.java:20: error: method does not override or implement a method from a supertype

works with rn 0.46.4

@ftcvlad https://github.com/zo0r/react-native-push-notification/pull/526 is waiting to be merged. For temporary, you may install with npm install ximenean/react-native-push-notification#patch-1, then recompile android.

Was this page helpful?
0 / 5 - 0 ratings