Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Compatibility with ExpoKit (Android) #152

Closed
ChildishDanbino opened this issue Nov 11, 2017 · 9 comments
Closed

Question: Compatibility with ExpoKit (Android) #152

ChildishDanbino opened this issue Nov 11, 2017 · 9 comments

Comments

@ChildishDanbino
Copy link

Our team has recently detached from Expo to Expokit to give us more control over the native modules we would like to use including push notifications. I am personally a big fan of this library and would love to use it if possible. iOS setup / installation was smooth but I am running into some issues on Android. Because the ExpoKit MainApplication.java looks as follows

import android.support.multidex.MultiDexApplication;

import com.facebook.react.ReactPackage;

import java.util.Arrays;
import java.util.List;

// Needed for `react-native link`
// import com.facebook.react.ReactApplication;

public class MainApplication extends MultiDexApplication {

  // Needed for `react-native link`
  public List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        // Add your own packages here!
        // TODO: add cool native modules

        // Needed for `react-native link`
        // new MainReactPackage()
    );
  }
}

if you notice the MainApplication doesn't implement the ReactApplication thus when we apply new RNNotificationsPackage(MainApplication.this) we get the error java.lang.IllegalStateException: Application instance isn't a react-application.

In short is this library compatible with ExpoKit and what would be the steps to get it up and running. I'd be willing to open a PR to update the docs once fixed. Thanks!

@ChildishDanbino ChildishDanbino changed the title Compatability with ExpoKit (Android) Question: Compatibility with ExpoKit (Android) Nov 11, 2017
@slorber
Copy link

slorber commented Nov 23, 2017

also looking for a push lib after ejecting Expo. Had troubles with OneSignal so I wanted to try this one but it looks complicated as well.

@Daadler6 if you have any idea on a working push solution with Expo SDK23 ejected I'm interested

@ChildishDanbino
Copy link
Author

@slorber I was able to get this working with Expo! With that said it was anything but easy. I am going to attempt to explain the steps here so anyone in the future can look. But let me know if you have questions and i'll try and answer them.

IOS:

  • I recommend doing PodInstall Method but adding the node module into the Podfile and then running Pod Install in your iOs directory. It looks like like this for my Expo 22:
    :path => "../node_modules/react-native/ReactCommon/yoga"
  pod 'DoubleConversion',
    :podspec => "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec",
    :inhibit_warnings => true
  pod 'Folly',
    :podspec => "../node_modules/react-native/third-party-podspecs/Folly.podspec",
    :inhibit_warnings => true
  pod 'GLog',
    :podspec => "../node_modules/react-native/third-party-podspecs/GLog.podspec",
    :inhibit_warnings => true
  pod 'react-native-notifications',
    :path => "../node_modules/react-native-notifications"

Android:

  • Update your MainApplication.java to implement the ReactApplication interface. React-Native-Notifications takes in an Application specially a react application as an argument which is why I was getting the error mentioned above. The MainApplication.java looks as follows.
package (Your Project as given by expo);

import android.support.multidex.MultiDexApplication;


import com.facebook.react.ReactPackage;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;

import com.wix.reactnativenotifications.RNNotificationsPackage;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends MultiDexApplication 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(),
      );
    }
  };

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

  public List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
            // Add your own packages here!
            // TODO: add cool native modules

            // Needed for `react-native link`
            // new MainReactPackage()
            new RNNotificationsPackage(MainApplication.this)
    );
  }

}

This solves the issue mentioned above and will allow the app to work... but you will not be able to access the device_id in the Javascript code due to a bug with the library. I have detailed how I fixed this issue here: #109.

Please let me know if this works for... specifically the fix for issue #109 if so I'll open a PR for Wix so we can get that issue closed. I haven't been able to validate the fix outside my codebase so I am looking for someone else to tell me that it worked for them. Thanks!

@slorber
Copy link

slorber commented Nov 24, 2017

thanks @Daadler6

I finally suceeded to make it work with OneSignal so I'm going to stick with it but this will certainly be helpful for others ejecting from Expo ;)

@nirpeled
Copy link

Nice job @Daadler6! What Expo version are you using?

I also have a detached Expo (ExpoKit) app with a custom solution for iOS using RN's PushNotificationIOS and now trying to find something similar for Android, would you recommend using Wix's solution or look for something else?

@ChildishDanbino
Copy link
Author

ChildishDanbino commented Apr 24, 2018

@nirpeled - We are currently using Expo SDK 25. Haven't migrated over to 26 yet because of the React 16.3 upgrade and we want to leave ourselves enough time to remove all the deprecated lifecycles from our code. While, I was able to get this working using the code above for a POC I actually decided not to use in when it came time to build for production. Based on my findings it was just too much effort to get it working. We actually went with https://github.com/zo0r/react-native-push-notification and it works great with Expo (IOS and Android). Plus since you already have PushNotificationIOS setup you've done half the work! (it uses that lib (PushNotificationIOS) for the IOS part).

@nirpeled
Copy link

@Daadler6 - Thanks for the quick response dude! Wow I'm so glad to actually find someone that is also using Expo 25 (ExpoKit) that managed to work with https://github.com/zo0r/react-native-push-notification - that was actually my first option on the list but was afraid it won't play nice with ExpoKit. How did you manage to skip the react-native link part? Did you do everything manually and it just worked?

@ChildishDanbino
Copy link
Author

@nirpeled - I linked everything manually. I've found that using Expo react native-link doesn't work most of the time as the inner workings are different than a react native init project. Still given the tools Expo provides I find the manual linking an easy to swallow trade-off as well as learning more about how everything works under the hood. Feel free to reach out to me directly in the Expo Slack if you need help setting it up

@Luckygirlllll
Copy link

Luckygirlllll commented Apr 24, 2019

@ChildishDanbino Hello, I have ExpoKit version 32.0.0 project and I'm trying to do manual linking of the react-native-notifications library, while I'm doing manual linking I'm getting an error in Xcode: "React/RCTBridge.h file not found RNNotification.m"

@Luckygirlllll
Copy link

Luckygirlllll commented Apr 24, 2019

Adding ```
pod 'react-native-notifications',
:path => "../node_modules/react-native-notifications" solved my issue,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants