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

问题描述 投票:0回答:1

我正在尝试使用一个信号来配置我的本机应用程序我遵循OneSignal文档遵循每一步但当我在MainApplication.java中添加代码时它显示此错误(错误:方法不会覆盖或实现超类型的方法@覆盖)

我一直尝试在互联网上提供不同的解决方案,但没有一个有效。

错误:

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();
  }
 }

main application.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);
    }
   }
react-native configuration onesignal
1个回答
0
投票

尝试运行react-native upgrade,这将更新mainActivity.java。也许那会解决你的问题

© www.soinside.com 2019 - 2024. All rights reserved.