react-native-aliyun-push icon indicating copy to clipboard operation
react-native-aliyun-push copied to clipboard

部分手机运行崩溃

Open bigkrys opened this issue 5 years ago • 1 comments

在部分手机上运行会崩溃,但是把MainApplication.java下面原本设置的 @Override public void onCreate() { super.onCreate(); //下面是添加的代码 // this.initCloudChannel(this); //添加结束 SoLoader.init(this, /* native exopackage */ false); } 里面的 this.initCloudChannel(this);注释掉,app正常运行。 debug版本的app运行正常,并且没有报下面的错误。 release版本闪退logcat报错主要如下 FATAL EXCEPTION: main Process: com.egame_android, PID: 10185 java.lang.ExceptionInInitializerError at f.a.b.a.a.a.f.c.a(Unknown Source:0) at f.a.b.a.a.a.e.c.a(Unknown Source:2) at com.alibaba.sdk.android.push.j.a.a(Unknown Source:18) at com.egame_android.MainApplication.a(Unknown Source:3) at com.egame_android.MainApplication.onCreate(Unknown Source:3) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1162) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6717) at android.app.ActivityThread.access$2000(ActivityThread.java:273) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2020) at android.os.Handler.dispatchMessage(Handler.java:112) at android.os.Looper.loop(Looper.java:216) at android.app.ActivityThread.main(ActivityThread.java:7625) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) Caused by: java.lang.IllegalStateException: Fail to load ams-spi-services for f.a.b.a.a.a.f.a at f.a.b.a.a.a.f.d.a(Unknown Source:46) at f.a.b.a.a.a.f.b.(Unknown Source:13) at f.a.b.a.a.a.f.c.a(Unknown Source:0) at f.a.b.a.a.a.e.c.a(Unknown Source:2) at com.alibaba.sdk.android.push.j.a.a(Unknown Source:18) at com.egame_android.MainApplication.a(Unknown Source:3) at com.egame_android.MainApplication.onCreate(Unknown Source:3) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1162) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6717) at android.app.ActivityThread.access$2000(ActivityThread.java:273) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2020) at android.os.Handler.dispatchMessage(Handler.java:112) at android.os.Looper.loop(Looper.java:216) at android.app.ActivityThread.main(ActivityThread.java:7625) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

react-natiive版本0.58.6 react-native-aliyun-push版本 1.0.17

android/build.gradle: image

android/app/build.gradle image

MainApplication.java:

// 下面是被添加的代码 import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.graphics.Color; import android.os.Build;

import org.wonday.aliyun.push.AliyunPushPackage;

import com.alibaba.sdk.android.push.CloudPushService; import com.alibaba.sdk.android.push.CommonCallback; import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory; import com.alibaba.sdk.android.push.register.HuaWeiRegister; import com.alibaba.sdk.android.push.register.MiPushRegister; import com.alibaba.sdk.android.push.register.GcmRegister; // 添加结束

public class MainApplication extends MultiDexApplication implements ReactApplication{

private ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { //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 AliyunPushPackage(),
        //添加结束

  );
}

@Override
protected String getJSMainModuleName() {
  return "index";
}

}; public void setReactNativeHost(ReactNativeHost reactNativeHost) { mReactNativeHost = reactNativeHost; } @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; }

@Override public void onCreate() { super.onCreate(); //下面是添加的代码 this.initCloudChannel(this); //添加结束 SoLoader.init(this, /* native exopackage */ false); }

// 下面是添加的代码 /** * 初始化阿里云推送通道 * @param applicationContext */ private void initCloudChannel(final Context applicationContext) {

  // 创建notificaiton channel
  this.createNotificationChannel();
  PushServiceFactory.init(applicationContext);
  CloudPushService pushService = PushServiceFactory.getCloudPushService();

  pushService.register(applicationContext, "*****", "****", new CommonCallback() {
    @Override
    public void onSuccess(String responnse) {
      // success
    }
    @Override
    public void onFailed(String code, String message) {
      // failed
    }
  });

  // 注册方法会自动判断是否支持小米系统推送,如不支持会跳过注册。
  MiPushRegister.register(applicationContext, "****", "******");
  // 注册方法会自动判断是否支持华为系统推送,如不支持会跳过注册。
   HuaWeiRegister.register(applicationContext);
  // 接入FCM/GCM初始化推送
  GcmRegister.register(applicationContext, "send_id", "application_id");
}


private void createNotificationChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        // 通知渠道的id
        String id = "1";
        // 用户可以看到的通知渠道的名字.
        CharSequence name = "notification channel";
        // 用户可以看到的通知渠道的描述
        String description = "notification description";
        int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel mChannel = new NotificationChannel(id, name, importance);
        // 配置通知渠道的属性
        mChannel.setDescription(description);
        // 设置通知出现时的闪灯(如果 android 设备支持的话)
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.RED);
        // 设置通知出现时的震动(如果 android 设备支持的话)
        mChannel.enableVibration(true);
        mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        //最后在notificationmanager中创建该通知渠道
        mNotificationManager.createNotificationChannel(mChannel);
    }
}
// 添加结束

}

bigkrys avatar Nov 20 '19 01:11 bigkrys

https://help.aliyun.com/knowledge_detail/39998.html?spm=a2c6h.13066369.0.0.59924697EOzwJp 阿里云官方有这个文档,但是这个怎么运用在react-native-aliyun-push里面进行修改呢?

bigkrys avatar Nov 20 '19 03:11 bigkrys