react-native-geolocation icon indicating copy to clipboard operation
react-native-geolocation copied to clipboard

Error: The package '@react-native-community/geolocation' doesn't seem to be linked. Make sure:

Open lucasrodrigues19 opened this issue 3 years ago • 16 comments

Environment

System: OS: Windows 10 10.0.19043 CPU: (8) x64 Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz Memory: 1.32 GB / 7.80 GB Binaries: Node: 16.15.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.12.1 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: Not Found IDEs: Android Studio: AI-213.7172.25.2113.9123335 Visual Studio: 17.0.32112.339 (Visual Studio Community 2022) Languages: Java: 11.0.12 - /c/Program Files/Common Files/Oracle/Java/javapath/javac npmPackages: @react-native-community/cli: Not Found react: 18.0.0 => 18.0.0 react-native: 0.69.6 => 0.69.6 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

Platforms

Android

Versions

  • Android: sdk 30
  • iOS: 12.0
  • react-native-geolocation:
  • react-native: 0.69.6
  • react: 18.0.0

Description

Error: The package '@react-native-community/geolocation' doesn't seem to be linked. Make sure:

  • You rebuilt the app after installing the package
  • You are not using Expo managed workflow

Reproducible Demo

when trying to import the package, example: import Geolocation from '@react-native-community/geolocation'

and reference it in the code, example: watchId = Geolocation.watchPosition(()=>{},()=>{},{})

lucasrodrigues19 avatar Nov 18 '22 11:11 lucasrodrigues19

I had to downgrade to 2.0.2 for the moment until there's a fix. Don't forget to ./gradlew clean and rebuild.

techurgency avatar Dec 06 '22 20:12 techurgency

+1

cubesmeta avatar Dec 09 '22 00:12 cubesmeta

It seems that it's no more auto-linked. In my experience, by executing react-native config, the android field related to @react-native-community/geolocation was null. I guess, although not entirely sure, it's due to the compatibility with the new architecture.

In my case, a temporary workaround was adding the following snippet into react-native.config.js

const geolocationFolder = path.resolve('<path-to-node_modules>/@react-native-community/geolocation')

module.exports = {
  dependencies: {
    '@react-native-community/geolocation': {
      platforms: {
        android: {
          sourceDir: path.resolve(geolocationFolder, 'android'),
          folder: geolocationFolder,
          packageImportPath: 'import com.reactnativecommunity.geolocation.GeolocationPackage;',
          packageInstance: 'new GeolocationPackage()',
          buildTypes: [],
        },
      },
    },
  },
}

valeriobelli avatar Dec 22 '22 09:12 valeriobelli

I dug a bit into the problem.

Version 3.x of this library started relying on an auto-linking feature introduced in @react-native-community/cli-platform-android@>=6.3.0. Starting from that version, native_modules.gradle also started looking for classes that extend the TurboReactPackage class.

As you can see here, this feature wasn't present in @react-native-community/cli-platform-android@<6.3.0. This means that the current GeolocationPackage won't be auto-linked if you are pointing to one of the cli-platform-android versions affected by this missing feature.

In my opinion, I would say that there are some paths to follow here:

  • Given that react-native started supporting @react-native-community/cli-platform-android@^6.0.0 at version 0.65.0 as you can see here, @react-native-community/geolocation should declare at least react-native@>0.65.0 in their peer dependency to avoid such problems. Otherwise, a developer can't update @react-native-community/cli-platform-android by using upgrade methods like npm update or yarn up (offered by Yarn Berry), but just via resolutions, which may break react-native CLI;
  • Anyone is currently pointing to @react-native-community/cli-platform-android@>=6.0.0 <6.3.0 should force the package manager to resolve a version compatible with ^6.3.0 (e.g., yarn upgrade @react-native-community/cli-platform-android@^6.0.0 with Yarn v1);
  • Update the documentation by adding some troubleshooting for such a problem without digging into the issues section.

Let me know if that is clear.

valeriobelli avatar Dec 23 '22 10:12 valeriobelli

+1

Maddumage avatar Dec 24 '22 12:12 Maddumage

manually link:

  • android/settings.gradle
include ':react-native-community-geolocation'
project(':react-native-community-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/geolocation/android')
  • android/app/build.gradle
dependencies {
   ...
   implementation project(':react-native-community-geolocation')
}
  • android/app/src/main/.../MainApplication.java

On top, where imports are:

import com.reactnativecommunity.geolocation.GeolocationPackage;

Add the GeolocationPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      packages.add(new GeolocationPackage()); // <== add this line
      return packages;
}

woowalker avatar Dec 26 '22 09:12 woowalker

@woowalker thanks. Work for me!

khanhdevvn avatar Jan 02 '23 15:01 khanhdevvn

manually link:

  • android/settings.gradle
include ':react-native-community-geolocation'
project(':react-native-community-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/geolocation/android')
  • android/app/build.gradle
dependencies {
   ...
   implementation project(':react-native-community-geolocation')
}
  • android/app/src/main/.../MainApplication.java

On top, where imports are:

import com.reactnativecommunity.geolocation.GeolocationPackage;

Add the GeolocationPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      packages.add(new GeolocationPackage()); // <== add this line
      return packages;
}

work for me to, thanks!

ganholete avatar Jan 04 '23 21:01 ganholete

manually link:

  • android/settings.gradle
include ':react-native-community-geolocation'
project(':react-native-community-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/geolocation/android')
  • android/app/build.gradle
dependencies {
   ...
   implementation project(':react-native-community-geolocation')
}
  • android/app/src/main/.../MainApplication.java

On top, where imports are:

import com.reactnativecommunity.geolocation.GeolocationPackage;

Add the GeolocationPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      packages.add(new GeolocationPackage()); // <== add this line
      return packages;
}

thanks, worked for me!

SliverYuki avatar Apr 26 '23 10:04 SliverYuki

manually link:

  • android/settings.gradle
include ':react-native-community-geolocation'
project(':react-native-community-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/geolocation/android')
  • android/app/build.gradle
dependencies {
   ...
   implementation project(':react-native-community-geolocation')
}
  • android/app/src/main/.../MainApplication.java

On top, where imports are:

import com.reactnativecommunity.geolocation.GeolocationPackage;

Add the GeolocationPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      packages.add(new GeolocationPackage()); // <== add this line
      return packages;
}

Your answer is so on point, thanks for that.

BenHurMartins avatar Jul 17 '23 20:07 BenHurMartins

I created a PR to update the steps for Android running on 0.65 and bellow:

https://github.com/michalchudziak/react-native-geolocation/pull/259

BenHurMartins avatar Jul 17 '23 20:07 BenHurMartins

i can add a manually link and use a latest version but it can throw a error on build.gradle/android/app and MainApplication plz help

bharvadiyavishal avatar Jul 26 '23 05:07 bharvadiyavishal

manually link:

  • android/settings.gradle
include ':react-native-community-geolocation'
project(':react-native-community-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/geolocation/android')
  • android/app/build.gradle
dependencies {
   ...
   implementation project(':react-native-community-geolocation')
}
  • android/app/src/main/.../MainApplication.java

On top, where imports are:

import com.reactnativecommunity.geolocation.GeolocationPackage;

Add the GeolocationPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      packages.add(new GeolocationPackage()); // <== add this line
      return packages;
}

Thank you, Any fix for iOS ?

thidasapankaja avatar Aug 08 '23 10:08 thidasapankaja

add this under target in your pod file for manually linking react-native-geolocation pod 'react-native-geolocation', :path => '../node_modules/@react-native-community/geolocation'

chandan1505 avatar Aug 11 '23 05:08 chandan1505

manually link:

  • android/settings.gradle
include ':react-native-community-geolocation'
project(':react-native-community-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/geolocation/android')
  • android/app/build.gradle
dependencies {
   ...
   implementation project(':react-native-community-geolocation')
}
  • android/app/src/main/.../MainApplication.java

On top, where imports are:

import com.reactnativecommunity.geolocation.GeolocationPackage;

Add the GeolocationPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      packages.add(new GeolocationPackage()); // <== add this line
      return packages;
}

Thank you, Any fix for iOS ?

Yes,use community package (as the react-native-community/geolocation deprecated.), like react-native-geolocation-service or react-native-get-location. This are the two powerful alternative.

SB2318 avatar Aug 11 '23 07:08 SB2318