Closed t34Virus closed 1 year ago
Project with path ':react-native-background-geolocation-android'
You cannot use the private repo react-native-background-geolocation-android
with Expo. You must install from npm react-native-background-geolocation
.
I followed the INSTALL-EXPO instructions. You mean to replace npx expo install react-native-background-geolocation
with npm install react-native-background-geolocation
?
Look at your error log: it references react-native-background-geolocation-android
. That is the private version from the private repo. I suggest you have a look at your package.json.
>[stderr]
> Project with path ':react-native-background-geolocation-android' could not be found in root project 'bison-driver-app'.
I'm unable to locate any reference for react-native-background-geolocation-android
within my repository. For more context, here is my current package.json:
{
"name": "mobile",
"version": "0.0.0",
"main": "index.js",
"private": true,
"scripts": {
"eas-build-pre-install": "echo 123 && pnpm i --filter mobile && bash pre-install.sh",
"build": "eas build --profile development",
"build:android": "pnpm run build --platform android",
"build:ios": "pnpm run build --platform ios",
"expo:prebuild": "expo prebuild --clean",
"doctor": "expo-cli doctor",
"doctor:fix": "pnpm run doctor --fix-dependencies",
"go": "sst bind \"dotenv -e ../../.env expo start -- --clear\"",
"start": "sst bind \"dotenv -e ../../.env expo start -- --clear --dev-client\"",
"test:unit": "jest -c jest.config.unit.js --detectOpenHandles --runInBand --forceExit",
"test:unit:update": "jest -c jest.config.unit.js --detectOpenHandles --runInBand --forceExit -u",
"typecheck": "tsc --noEmit",
"android": "expo run:android",
"ios": "expo run:ios"
},
"dependencies": {
"@expo/vector-icons": "^13.0.0",
"@react-native-async-storage/async-storage": "~1.17.11",
"@react-native-community/netinfo": "9.3.7",
"@react-navigation/bottom-tabs": "~6.5.7",
"@react-navigation/native": "~6.1.6",
"@react-navigation/native-stack": "~6.9.12",
"@react-navigation/routers": "~6.1.8",
"@react-navigation/stack": "~6.3.16",
"@sentry/react-native": "~4.13.0",
"amazon-cognito-identity-js": "~6.1.2",
"aws-amplify": "5.0.17",
"expo": "~48.0.5",
"expo-application": "~5.1.1",
"expo-asset": "~8.9.1",
"expo-build-properties": "~0.5.1",
"expo-camera": "~13.2.1",
"expo-constants": "~14.2.1",
"expo-crypto": "~12.2.1",
"expo-device": "~5.2.1",
"expo-font": "~11.1.1",
"expo-gradle-ext-vars": "~0.1.1",
"expo-splash-screen": "~0.18.1",
"expo-status-bar": "~1.4.4",
"expo-updates": "~0.16.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.71.3",
"react-native-background-fetch": "~4.1.9",
"react-native-background-geolocation": "~4.10.1",
"react-native-gesture-handler": "~2.9.0",
"react-native-keyboard-aware-scroll-view": "~0.9.5",
"react-native-paper": "~5.3.1",
"react-native-safe-area-context": "4.5.0",
"react-native-screens": "~3.20.0",
"react-native-select-dropdown": "~3.3.0",
"react-native-svg": "13.4.0",
"react-native-vector-icons": "~9.2.0",
"react-native-web": "~0.18.12",
"sentry-expo": "~6.1.0"
},
"devDependencies": {
"@babel/core": "^7.21.0",
"@babel/preset-env": "^7.1.6",
"@sentry/cli": "~2.14.4",
"@testing-library/react-native": "12.0.0-rc.2",
"@types/jest": "~29.4.0",
"@types/react": "~18.0.28",
"eas-cli": "~3.7.2",
"expo-dev-client": "~2.1.5",
"expo-modules-autolinking": ">=0.8.1",
"jest": "^29.4.3",
"jest-expo": "~48.0.1",
"react-test-renderer": ">=16.8.0"
},
"peerDependencies": {
"@babel/preset-env": "^7.1.6",
"expo-modules-autolinking": ">=0.8.1",
"react-test-renderer": ">=16.8.0"
}
}
Do you have a local /android
folder?
I can build an /android
folder locally but don't require one to deploy to EAS.
do it. Then post the following files (after running npx expo prebuild
)
android/build.gradle
android/app/build.gradle
The expo plugin's node script determines which version is being installed here, by asking if the folder node_modules/react-native-background-geolocation
exists.
const PUBLIC_MODULE = 'react-native-background-geolocation';
const PRIVATE_MODULE = PUBLIC_MODULE + '-android';
const NODE_MODULES = path.join('.', 'node_modules');
const MODULE_NAME = fs.existsSync(path.join(NODE_MODULES, PUBLIC_MODULE)) ? PUBLIC_MODULE : PRIVATE_MODULE;
It seems that the folder node_modules/react-native-background-geolocation
is not being found on the eas
server.
Interesting. I appreciate you pinpointing the issue. I will look into it further on my end.
I don't know why that code shouldn't find that path on an eas build. Did something change over on their servers?
I will try an eas build on my end.
The expo plug-in script could probably be changed to load package.json
to see which version of the plug-in is installed.
The script is assuming that it's running in the root of the expo app. Perhaps it's not anymore, meaning ./node_modules
doesn't exist.
The app using this plugin lives within a monorepo. EAS builds works for both iOS and Android. After installing the geolocation plugin, iOS continues to build properly but not Android. Is the process of finding that path different per mobile OS?
I've written a simple post install bash script to be executed at the EAS build's post install stage. It locates the incorrect package references within android/build.gradle
and android/app/build.gradle
then renames them appropriately. For visibility, it will display the contents of the edited files within the Post-install hook
of EAS' build logs.
Update package.json with this command:
"scripts": { "eas-build-post-install": "bash ./post-install.sh" }
Create a new file called post-install.sh
next to the package.json:
post-install.sh
#!/bin/bash
if [[ "$EAS_BUILD_PLATFORM" == "android" ]]; then
echo "Run commands for Android builds here" &&
sed -i 's/react-native-background-geolocation-android/react-native-background-geolocation/g' android/build.gradle && sed -i 's/react-native-background-geolocation-android/react-native-background-geolocation/g' android/app/build.gradle && cat android/build.gradle && cat android/app/build.gradle
elif [[ "$EAS_BUILD_PLATFORM" == "ios" ]]; then
echo "Run commands for iOS builds here"
fi
Within the terminal:
Navigate to the directory of the new post-install.sh to give it permissions:
$ chmod +x post-install.sh
Run the build command with the name of the build title declared within eas.json
(In my case, it's development
):
$ eas build --profile development
@t34Virus I have created a PR that should solve the prebuild
error having react-native-background-geolocation
in a monorepo: https://github.com/transistorsoft/react-native-background-geolocation/pull/1682
@cgav that's very kind of you, thank you! I'll forward this over to my former team to double check.
@cgav thank you again for the fix! 💪🥹
Your Environment
react-native -v
): 0.71.3export default ({ config }: ConfigContext): ExpoConfig => ({ ...config, owner: "new-driver-app", name: "bison-driver-app", slug: "bison-driver-app", plugins: [ [ "react-native-background-geolocation", { license: PROVIDED_IN_EMAIL, }, ], [ "expo-gradle-ext-vars", { googlePlayServicesLocationVersion: "20.0.0", appCompatVersion: "1.4.2", }, ], "react-native-background-fetch", ], assetBundlePatterns: ["assets/fonts/", "assets/images/"], android: { package: PROVIDED_IN_EMAIL, }, ios: { bundleIdentifier: PROVIDED_IN_EMAIL, infoPlist: { NSLocationAlwaysAndWhenInUseUsageDescription: "[CHANGEME] This app requires location in the background", NSLocationWhenInUseUsageDescription: "[CHANGEME] This app requires location while in use", NSMotionUsageDescription: "[CHANGEME] This app uses motion-detection to determine the motion-activity of the device (walking, vehicle, bicycle, etc)", UIBackgroundModes: ["location", "fetch", "processing", "audio"], BGTaskSchedulerPermittedIdentifiers: [ "com.transistorsoft.fetch", "com.transistorsoft.customtask", ], }, }, extra: { eas: { projectId: PROVIDED_IN_EMAIL, } });