hi today i have installed react-native-maps in my project and i have configured it but when i run react-native run-android
it show me an error:
> 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
this is the link of the guide I followed on github to configure react-native-maps.
In the MainApplication.java I added import com.airbnb.android.react.maps.MapsPackage
and
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new MapsPackage()
);
}
in the public class MainApplication extends Application implements ReactApplication {
.
do you know how I can overcome this problem?
UPDATING
after TheWanderer has solved the previous problem, the terminal shows me the following error:
> 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
thank you
The later versions of react-native-maps
no longer require manually adding the package to your ReactNativeApplication on Android.
The installation instructions simply tell you to run npm install react-native-maps
or yarn add react-native-maps
depending on your package manager.
If you still need to manually link the package for whatever reason, your Application
class should look something like this:
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);
}
}
You can also take a look at the older example application from the library source: https://github.com/react-native-maps/react-native-maps/blob/153257316a092db3cdacdf311e021ba458d9ea4f/example/android/app/src/main/java/com/airbnb/android/react/maps/example/ExampleApplication.java