Maps: [Android] Autolinking not working

Created on 26 Sep 2019  路  16Comments  路  Source: react-native-mapbox-gl/maps

Describe the bug
Build failed when I launch react-native run-android

Expected behavior
Should build.

Versions :

  • Platfrom: Android
  • Device: Emulator
  • OS: Android 9
  • SDK Version: 28
  • React Native Version 0.60.5

    • react-native-mapbox-gl/maps version: 7.0.6

Additional context

FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:preDebugBuild'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve project :@react-native-mapbox-gl_maps.
     Required by:
         project :app
      > Unable to find a matching configuration of project :@react-native-mapbox-gl_maps:
          - None of the consumable configurations have attributes.

Most helpful comment

I just try manually linking by adding this in settings.gradle file

include ':@react-native-mapbox-gl_maps'
project(':@react-native-mapbox-gl_maps').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-mapbox-gl/maps/android/rctmgl')

and it works!

It's a workaround, there is still a bug with the autolinking

All 16 comments

Have you tried manually linking?

I just try manually linking by adding this in settings.gradle file

include ':@react-native-mapbox-gl_maps'
project(':@react-native-mapbox-gl_maps').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-mapbox-gl/maps/android/rctmgl')

and it works!

It's a workaround, there is still a bug with the autolinking

Ok. Can you confirm iOS autolinking works?

@kristfal yes, IOS autolinking works

Ok, feel free to explore why autolinking fails for Android. In the interim, we'll keep this ticket open.

I'll also have a look at updating the example app to RN61 next week and can review things then as well.

@kristfal thanks

@Misioka I don't edit MainApplication.java or build.gradle

https://raw.githubusercontent.com/react-native-community/rn-diff-purge/release/0.60.5/RnDiffApp/android/app/src/main/java/com/rndiffapp/MainApplication.java

https://raw.githubusercontent.com/react-native-community/rn-diff-purge/release/0.60.5/RnDiffApp/android/app/build.gradle

I just modify settings.gradle

rootProject.name = 'my_app'

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

include ':@react-native-mapbox-gl_maps'
project(':@react-native-mapbox-gl_maps').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-mapbox-gl/maps/android/rctmgl')

include ':app'

@bpouzet thanks a lot. Now I see.
Line order in settings.gradle is important.
When I put apply from... above include. It starts to work.

@bpouzet I had the same problem. I discovered this repo "@react-native-mapbox-gl/maps": "jshearer/maps" It fixes autolinking.

@Alaa-Ben I can't really see any commits in that repo that should fix Android autolinking. Any idea why that one is working and not this main one?

@kristfal Unfortunately no. I would say it's something in this commit:
https://github.com/jshearer/maps/commit/cdeb03231e3c8d53ffeeda7527fd7a715ad5291b

I read that using this repo resolves the:
Could not resolve project :@react-native-mapbox-gl_maps.
I read the commits, didn't believe it, but gave it a try eventually: it works for me.

Bizarrely to get this to work for me all I had to do was add a trailing slash to the include in settings.gradle.

i.e:
```apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

include ':@react-native-mapbox-gl_maps'
project(':@react-native-mapbox-gl_maps').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-mapbox-gl/maps/android/rctmgl/')
```

With the repo I mentionned above, I don't even need to touch the settings.gradle file

@bpouzet's fix worked for me, but I also need to install and use jetifier.

I was updating my app from React Native 0.59.10 to React Native 0.60.0. I also needed Jetifier for react-native-auth0.

Turns out the react native configuration file (react-native.config.js) is named as "react-native-config.js" in the package ! Renaming the file fixed autolinking issues for me. But you'll have to do it everytime you update any package.

@MrScorp thanks for finding this issue. That was a silly typo/oversight from me. Opened a PR and merging this as soon as CI is good.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RichardLindhout picture RichardLindhout  路  4Comments

alexisrougnant picture alexisrougnant  路  3Comments

magnusburton picture magnusburton  路  3Comments

atomheartother picture atomheartother  路  3Comments

dorthwein picture dorthwein  路  3Comments