islam hany
islam hany

Reputation: 148

react-native-maps build failed

I installed react-native-maps but when i try to build it fails and gives the following error despite that javac works

> Task :react-native-maps:compileDebugJavaWithJavac
D:\COURSES\ReactNative-ThePracticalGuide\myFirstApp\node_modules\react-native-ma
ps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:12: e
rror: package androidx.core.view does not exist
import androidx.core.view.GestureDetectorCompat;
                         ^
D:\COURSES\ReactNative-ThePracticalGuide\myFirstApp\node_modules\react-native-ma
ps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:13: e
rror: package androidx.core.view does not exist
import androidx.core.view.MotionEventCompat;
                         ^
D:\COURSES\ReactNative-ThePracticalGuide\myFirstApp\node_modules\react-native-ma
ps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:73: e
rror: package androidx.core.content does not exist
import static androidx.core.content.PermissionChecker.checkSelfPermission;
                                   ^
D:\COURSES\ReactNative-ThePracticalGuide\myFirstApp\node_modules\react-native-ma
ps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:73: e
rror: static import only from classes and interfaces
import static androidx.core.content.PermissionChecker.checkSelfPermission;
^
D:\COURSES\ReactNative-ThePracticalGuide\myFirstApp\node_modules\react-native-ma
ps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:108:
error: cannot find symbol
  private final GestureDetectorCompat gestureDetector;
                ^
  symbol:   class GestureDetectorCompat
  location: class AirMapView
D:\COURSES\ReactNative-ThePracticalGuide\myFirstApp\node_modules\react-native-ma
ps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:165:
error: cannot find symbol
        new GestureDetectorCompat(reactContext, new GestureDetector.SimpleOnGest
ureListener() {
            ^
  symbol:   class GestureDetectorCompat
  location: class AirMapView
D:\COURSES\ReactNative-ThePracticalGuide\myFirstApp\node_modules\react-native-ma
ps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:421:
error: cannot find symbol
    return checkSelfPermission(getContext(), PERMISSIONS[0]) == PackageManager.P
ERMISSION_GRANTED ||
           ^
  symbol:   method checkSelfPermission(Context,String)
  location: class AirMapView
D:\COURSES\ReactNative-ThePracticalGuide\myFirstApp\node_modules\react-native-ma
ps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:422:
error: cannot find symbol
        checkSelfPermission(getContext(), PERMISSIONS[1]) == PackageManager.PERM
ISSION_GRANTED;
        ^
  symbol:   method checkSelfPermission(Context,String)
  location: class AirMapView
D:\COURSES\ReactNative-ThePracticalGuide\myFirstApp\node_modules\react-native-ma
ps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:949:
error: cannot find symbol
    int action = MotionEventCompat.getActionMasked(ev);
                 ^
  symbol:   variable MotionEventCompat
  location: class AirMapView
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
9 errors

> Task :react-native-maps:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

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

the versions of my packages "react-native": "0.59.10", "react-native-maps": "0.26.1",

the dependencies in app/build.gradle file

dependencies {
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation 'com.android.support:design:27.1.0' 
    implementation "com.facebook.react:react-native:+" // From node_modules
    compile fileTree(dir: "libs", include: ["*.jar"]) 
    compile project(':react-native-vector-icons') 
    compile project(':react-native-navigation')
    implementation(project(':react-native-maps')){
       exclude group: 'com.google.android.gms', module: 'play-services-base'
       exclude group: 'com.google.android.gms', module: 'play-services-maps'
   }
   implementation 'com.google.android.gms:play-services-base:10.0.1'
   implementation 'com.google.android.gms:play-services-maps:10.0.1'
}

I followed the installations instructions carefully but the build still failed. Any solution to this problem ?

Upvotes: 1

Views: 2223

Answers (2)

islam hany
islam hany

Reputation: 148

I found the solution to my problem. First i add the following lines to ./android/gradle.properties

android.useAndroidX=true
android.enableJetifier=true

then adding jetifier will fix it

npm install --save-dev jetifier
npx jetify
npx react-native run-android

that fixed the problem for me.

Upvotes: 1

Raed Hellal
Raed Hellal

Reputation: 11

try upgrading react native to a version 0.60+ and don't forget to unlink react native maps

Upvotes: 1

Related Questions