在React-Native中使用Android运行CodePush

时间:2017-05-21 05:46:50

标签: java android react-native react-native-code-push

在如此接近成功运行Android的React-Native之后,我遇到了以下错误。

:app:compileDebugJavaWithJavac
/Users/Spicycurryman/Desktop/Main/Projects/Wosyl-Delivery-1.0-master/android/app/src/main/java/com/wosyldelivery/MainApplication.java:30: error: no suitable constructor found for CodePush(<null>,<anonymous ReactNativeHost>,boolean)
            new CodePush(null, this, BuildConfig.DEBUG),
            ^
    constructor CodePush.CodePush(String,Context,boolean,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor CodePush.CodePush(String,Context,boolean) is not applicable
      (actual argument <anonymous ReactNativeHost> cannot be converted to Context by method invocation conversion)
    constructor CodePush.CodePush(String,Context) is not applicable
      (actual and formal argument lists differ in length)
1 error
:app:compileDebugJavaWithJavac FAILED

我已按照回购协议中的说明进行操作,即使在查看此https://github.com/Microsoft/react-native-code-push/issues/790

之后也不确定为什么会出现这种情况

这是我的MainApplication.java用于完整上下文。

package com.wosyldelivery;

import android.app.Application;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.microsoft.codepush.react.CodePush;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;


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

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new CodePush(null, this, BuildConfig.DEBUG),
            new VectorIconsPackage()
      );
    }
    @Override
    protected String getJSBundleFile() {
      return CodePush.getJSBundleFile();
    }
  };

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

发生此错误的原因是什么?怎么解决?

2 个答案:

答案 0 :(得分:2)

new CodePush("deployment-key", getApplicationContext(), BuildConfig.DEBUG)

deployment-key是一个字母数字字符串,您在注册代码推送帐户时会获得该字符串,但它不能为空。

答案 1 :(得分:0)

将CodePush的实例化更改为:

new CodePush("deployment-key-here", MainApplication.this, BuildConfig.DEBUG)