evollu / react-native-gcm-push-notification

GCM for React Native Android and IOS
MIT License
15 stars 10 forks source link

No static method builder() Lcom/facebook/react/ReactInstanceManager$Builder; #7

Open nadirHomeFriend opened 6 years ago

nadirHomeFriend commented 6 years ago

hello, dam facing an issue with react)native)gem when app is killer . every thing works fine when app foreground/bacground but when app is killer the app crash when receiving the notification:

04-24 16:14:47.858 4569-4569/? E/Zygote: v2 04-24 16:14:47.868 4569-4569/? E/Zygote: accessInfo : 0 04-24 16:14:48.588 4569-4569/com.homefriend.app.staging E/UncaughtException: java.lang.NoSuchMethodError: No static method builder()Lcom/facebook/react/ReactInstanceManager$Builder; in class Lcom/facebook/react/ReactInstanceManager; or its super classes (declaration of 'com.facebook.react.ReactInstanceManager' appears in /data/app/com.homefriend.app.staging-1/base.apk) at com.oney.gcm.BackgroundService.onStartCommand(BackgroundService.java:28) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4062) at android.app.ActivityThread.access$2400(ActivityThread.java:221) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1897) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7225) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 04-24 16:14:48.868 4569-4569/com.homefriend.app.staging E/AndroidRuntime: FATAL EXCEPTION: main Process: com.homefriend.app.staging, PID: 4569 java.lang.NoSuchMethodError: No static method builder()Lcom/facebook/react/ReactInstanceManager$Builder; in class Lcom/facebook/react/ReactInstanceManager; or its super classes (declaration of 'com.facebook.react.ReactInstanceManager' appears in /data/app/com.homefriend.app.staging-1/base.apk) at com.oney.gcm.BackgroundService.onStartCommand(BackgroundService.java:28) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4062) at android.app.ActivityThread.access$2400(ActivityThread.java:221) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1897) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7225) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

"react-native": "0.44.0",
"react": "16.0.0-alpha.6",
"react-native-gcm-android": "^0.2.0",
"react-native-system-notification": "^0.2.1",

backgroundService.java:

package com.oney.gcm;

import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log;

import com.facebook.react.LifecycleState; import com.facebook.react.ReactInstanceManager;

import java.lang.reflect.Field;

import io.neson.react.notification.NotificationPackage;

public class BackgroundService extends Service { private static final String TAG = "BackgroundService"; private static ReactInstanceManager mReactInstanceManager;

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand");

    mReactInstanceManager = ReactInstanceManager.builder()
            .setApplication(getApplication())
            .setBundleAssetName("index.android.bundle")
            .setJSMainModuleName("index.android")
            .addPackage(new MainReactPackage())
            .addPackage(new GcmPackage(intent))
            .addPackage(new NotificationPackage())
            .setUseDeveloperSupport(getBuildConfigDEBUG())
            .setInitialLifecycleState(LifecycleState.RESUMED)
            .build();
    mReactInstanceManager.createReactContextInBackground();

    return START_NOT_STICKY;
}
 //   @Override

/* public int onStartCommand(Intent intent, int flags, int startId) {

Bundle bundle = intent.getBundleExtra("bundle");
Object result = bundle.get("info");
String data   = result.toString();
String id     = bundle.get("google.message_id").toString();
try{
    JSONObject jsonObj = new JSONObject(data);
    Log.d(TAG,"onStartCommand jsonObj => :"+jsonObj);
    Log.d(TAG,"onStartCommand bundle => :"+bundle);
    String message = jsonObj.getString("message");
    String subject = jsonObj.getString("subject");
    Integer notificationId = Integer.parseInt(id.substring(0, 10).replaceAll("[\\D]", ""));

    NotificationAttributes attributes = new NotificationAttributes();
    attributes.delayed = false;
    attributes.scheduled = false;
    attributes.autoClear = true;
    attributes.inboxStyle = false;
    attributes.priority = 2;
    attributes.sound = "default";
    attributes.smallIcon = "ic_launcher";
    attributes.message = message;
    attributes.subject = subject;
    Notification notification = new Notification(this, notificationId, attributes);
    notification.create();

}catch (JSONException e) {
   Log.d(TAG,e);
}  
return START_NOT_STICKY;

}*/ @Override public void onDestroy() { Log.d(TAG, "onDestroy"); super.onDestroy(); mReactInstanceManager.onPause(); mReactInstanceManager.onDestroy(); mReactInstanceManager = null; }

private Class getBuildConfigClass() {
    try {
        String packageName = getPackageName();

        return Class.forName(packageName + ".BuildConfig");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
private boolean getBuildConfigDEBUG() {
    Class klass = getBuildConfigClass();
    for (Field f : klass.getDeclaredFields()) {
        if (f.getName().equals("DEBUG")) {
            try {
                return f.getBoolean(this);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
    return false;
}

}

ReactInstanceManager.java:

/**

package com.facebook.react;

import javax.annotation.Nullable;

import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List;

import android.app.Activity; import android.app.Application; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.os.Process; import android.view.View;

import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; import com.facebook.react.bridge.CatalystInstance; import com.facebook.react.bridge.JavaJSExecutor; import com.facebook.react.bridge.JavaScriptModule; import com.facebook.react.bridge.JavaScriptModuleRegistry; import com.facebook.react.bridge.NativeModuleCallExceptionHandler; import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactMarker; import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec; import com.facebook.react.common.ApplicationHolder; import com.facebook.react.common.LifecycleState; import com.facebook.react.common.ReactConstants; import com.facebook.react.common.annotations.VisibleForTesting; import com.facebook.react.cxxbridge.Arguments; import com.facebook.react.cxxbridge.CatalystInstanceImpl; import com.facebook.react.cxxbridge.JSBundleLoader; import com.facebook.react.cxxbridge.JSCJavaScriptExecutor; import com.facebook.react.cxxbridge.JavaScriptExecutor; import com.facebook.react.cxxbridge.NativeModuleRegistry; import com.facebook.react.cxxbridge.ProxyJavaScriptExecutor; import com.facebook.react.cxxbridge.UiThreadUtil; import com.facebook.react.devsupport.DevSupportManagerFactory; import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler; import com.facebook.react.devsupport.RedBoxHandler; import com.facebook.react.devsupport.interfaces.DevSupportManager; import com.facebook.react.devsupport.interfaces.PackagerStatusCallback; import com.facebook.react.modules.appregistry.AppRegistry; import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; import com.facebook.react.modules.core.DeviceEventManagerModule; import com.facebook.react.modules.debug.interfaces.DeveloperSettings; import com.facebook.react.uimanager.DisplayMetricsHolder; import com.facebook.react.uimanager.UIImplementationProvider; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.ViewManager; import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper; import com.facebook.soloader.SoLoader; import com.facebook.systrace.Systrace; import com.facebook.systrace.SystraceMessage;

import static com.facebook.react.bridge.ReactMarkerConstants.BUILD_NATIVE_MODULE_REGISTRY_END; import static com.facebook.react.bridge.ReactMarkerConstants.BUILD_NATIVE_MODULE_REGISTRY_START; import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_CATALYST_INSTANCE_END; import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_CATALYST_INSTANCE_START; import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_REACT_CONTEXT_START; import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_VIEW_MANAGERS_END; import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_VIEW_MANAGERS_START; import static com.facebook.react.bridge.ReactMarkerConstants.PRE_SETUP_REACT_CONTEXT_END; import static com.facebook.react.bridge.ReactMarkerConstants.PRE_SETUP_REACT_CONTEXT_START; import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_PACKAGES_END; import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_PACKAGES_START; import static com.facebook.react.bridge.ReactMarkerConstants.SETUP_REACT_CONTEXT_END; import static com.facebook.react.bridge.ReactMarkerConstants.SETUP_REACT_CONTEXT_START; import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_APPS; import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE; import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JSC_CALLS;

/**

thanks for you reply