react-native-geolocation
react-native-geolocation copied to clipboard
Error: The package '@react-native-community/geolocation' doesn't seem to be linked. Make sure:
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(()=>{},()=>{},{})
I had to downgrade to 2.0.2 for the moment until there's a fix. Don't forget to ./gradlew clean and rebuild.
+1
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: [],
},
},
},
},
}
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-nativestarted supporting@react-native-community/cli-platform-android@^6.0.0at version0.65.0as you can see here,@react-native-community/geolocationshould declare at leastreact-native@>0.65.0in their peer dependency to avoid such problems. Otherwise, a developer can't update@react-native-community/cli-platform-androidby using upgrade methods likenpm updateoryarn up(offered by Yarn Berry), but just viaresolutions, which may break react-native CLI; - Anyone is currently pointing to
@react-native-community/cli-platform-android@>=6.0.0 <6.3.0should 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.0with 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.
+1
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 thanks. Work for me!
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!
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!
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.
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
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
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 ?
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'
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.