react 本机 MainApplication.java 方法不会覆盖或实现超类型的方法

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

嗨,今天我在我的项目中安装了react-native-maps,并且我已经配置了它,但是当我运行

react-native run-android
时,它显示了一个错误:

> Task :app:compileDebugJavaWithJavac FAILED
/home/valentino/Scrivania/test/android/app/src/main/java/com/test/MainApplication.java:38: error: method does not override or implement a method from a supertype
  @Override
  ^
1 error

这是我在github上配置react-native-maps的指南的链接。

在 MainApplication.java 中我添加了

import com.airbnb.android.react.maps.MapsPackage

@Override
      protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
                  new MainReactPackage(),
                  new MapsPackage()
          );
      }

public class MainApplication extends Application implements ReactApplication {

你知道我该如何克服这个问题吗?

更新中

TheWanderer 解决了之前的问题后,终端显示以下错误:

> Task :app:compileDebugJavaWithJavac FAILED
/home/valentino/Scrivania/test/android/app/src/main/java/com/test/MainApplication.java:38: error: method getPackages() is already defined in class <anonymous com.test.MainApplication$1>
    protected List<ReactPackage> getPackages() {
                                 ^
1 error

谢谢你

android react-native react-native-maps
1个回答
1
投票

更高版本的

react-native-maps
不再需要手动将包添加到Android上的ReactNativeApplication中。

安装说明只是告诉您运行

npm install react-native-maps
yarn add react-native-maps
,具体取决于您的软件包管理器。

如果您出于某种原因仍然需要手动链接包,您的

Application
类应该如下所示:

import android.app.Application;

import com.rnmaps.maps.MapsPackage;
import com.facebook.react.ReactApplication;
import com.facebook.react.PackageList;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

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

public class ExampleApplication extends Application implements ReactApplication {
  private final ReactNativeHost reactNativeHost = new ReactNativeHost(this) {
    @Override public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

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

    @Override protected List<ReactPackage> getPackages() {
      ArrayList<ReactPackage> packages = new PackageList(this).getPackages();
      // This is the important thing to add.
      packages.add(new MapsPackage());
      return packages;
    }
  };

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

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

您还可以从库源查看旧的示例应用程序:https://github.com/react-native-maps/react-native-maps/blob/153257316a092db3cdacdf311e021ba458d9ea4f/example/android/app/src/主/java/com/airbnb/android/react/maps/example/ExampleApplication.java

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