我正在尝试通过遵循文档将onesignal配置到我的react-native应用程序中,但是它显示了@override的错误

时间:2019-03-23 07:00:32

标签: react-native configuration onesignal

我试图用一个信号配置我的React Native应用程序,我遵循OneSignal文档的每个步骤,但是当我在MainApplication.java中添加代码时,它显示此错误(错误:方法未覆盖或实现方法来自超型@Override)

我一直在尝试互联网上提供的其他解决方案,但没有一个起作用。

错误:

error: method does not override or implement a method from a supertype
@Override
^
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
24 actionable tasks: 1 executed, 23 up-to-date
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: gradlew.bat app:installDebug

要从文档中添加的代码: (MainApplication.java)

import com.geektime.rnonesignalandroid.ReactNativeOneSignalPackage;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new ReactNativeOneSignalPackage() // You must return the ReactNativeOneSignalPackage here
      );
    }
  };

   @Override
    public List<ReactPackage> createAdditionalReactPackages() {
    return getPackages();
  }
 }

MainApplication.java

package com.onsignalapp;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.geektime.rnonesignalandroid.ReactNativeOneSignalPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.geektime.rnonesignalandroid.ReactNativeOneSignalPackage;


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

public class MainApplication extends Application 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(),
            new ReactNativeOneSignalPackage()
      );
    }
    @Override
      public List<ReactPackage> createAdditionalReactPackages() {
        return getPackages();
      }

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

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

    @Override
      public void onCreate() {
      super.onCreate();
      SoLoader.init(this, /* native exopackage */ false);
    }
   }

1 个答案:

答案 0 :(得分:0)

尝试运行react-native升级,这将更新mainActivity.java。也许可以解决您的问题