oney / react-native-gcm-android

GCM for React Native Android
MIT License
172 stars 76 forks source link

Compatibility / instructions for ReactNative 0.19 #42

Open thedgbrt opened 8 years ago

thedgbrt commented 8 years ago

Hello Howard, congratulations on this great work that is very much needed :)

I am using ReactNative 0.19 and can't seem to find how to import the gcm packages properly in android/app/src/main/java/com/testoe/MainActivity.java.

Since 0.18, RN's MainActivity.java file has been simplified a lot and we can't just do this anymore :

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactRootView = new ReactRootView(this);

        mReactInstanceManager = ReactInstanceManager.builder()
                ....
                .addPackage(new MainReactPackage())
                .addPackage(new GcmPackage())                       // <- Add this line
                .addPackage(new NotificationPackage(this))          // <- Add this line

The code that seem to now be responsible for adding packages is now :

@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage()
      );
    }

I tried doing this :

@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new GcmPackage(),
        new NotificationPackage(this)
      );
    }

but I got errors when doing (clean) builds wit gradle, saying packages were not found on Android. (this might because of #41 but I am not sure)

What's the clean way to fix this?

Thanks

pewh commented 8 years ago

Delete folder android/build manually and try react-native clean. Hope it works.

EDIT: Can you post error messages?

liesislukas commented 8 years ago

I've compiled and received notification successfully React Native v0.20

I have fresh v0.20 react native installation and tried adding gcm. It compiled successfully. Done everything like your readme is saying, just changed

from your guidelines:

import com.oney.gcm.GcmPackage;                             // <- Add this line
import io.neson.react.notification.NotificationPackage;     // <- Add this line
    ...
        .addPackage(new MainReactPackage())
        .addPackage(new GcmPackage())                       // <- Add this line
        .addPackage(new NotificationPackage(this))          // <- Add this line

to:

 @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new GcmPackage(),
        new NotificationPackage(this)
      );
    }

I think readme should be updated with up-to-date new instructions. I will write if i'll have any issues actually recieving notifications.