transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.65k stars 426 forks source link

Android EAS: ':react-native-background-geolocation-android' could not be found in root project #1653

Closed t34Virus closed 1 year ago

t34Virus commented 1 year ago

Your Environment

export 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, } });


## Expected Behavior
<!--- Tell us what should happen -->
Should properly configure android/build.gradle within the EAS Run gradlew step.

## Actual Behavior
<!--- Tell us what happens instead -->
EAS Build fails at the Run gradlew step

## Steps to Reproduce
<!--- reproduce this issue; include code to reproduce, if relevant -->
1. `eas build --profile development --platform android`

## Context
<!--- What were you trying to do? -->
Deploy Android build to EAS

## Debug logs
<!-- include iOS / Android logs
- ios XCode logs,
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat -s TSLocationManager
-->
<details><summary>Logs</summary>

``` <!-- Syntax highlighting:  DO NOT REMOVE -->
Running 'gradlew :app:assembleDebug' in /home/expo/workingdir/build/apps/mobile/android
Downloading https://services.gradle.org/distributions/gradle-7.5.1-all.zip
10%
20%.
30%
40%.
50%.
60%.
70%.
80%
90%.
100%
Welcome to Gradle 7.5.1!
Here are the highlights of this release:
 - Support for Java 18
 - Support for building with Groovy 4
 - Much more responsive continuous builds
 - Improved diagnostics for dependency resolution
For more details see https://docs.gradle.org/7.5.1/release-notes.html
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.5.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build
> Task :react-native-gradle-plugin:pluginDescriptors
> Task :react-native-gradle-plugin:processResources
> Task :react-native-gradle-plugin:compileKotlin
> Task :react-native-gradle-plugin:compileJava NO-SOURCE
> Task :react-native-gradle-plugin:classes
> Task :react-native-gradle-plugin:inspectClassesForKotlinIC
> Task :react-native-gradle-plugin:jar
[stderr] 
FAILURE: Build failed with an exception.
[stderr] 
* Where:
[stderr] 
Build file '/home/expo/workingdir/build/apps/mobile/android/build.gradle' line: 36
[stderr] 
* What went wrong:
[stderr] 
A problem occurred evaluating root project 'bison-driver-app'.
[stderr] 
> Project with path ':react-native-background-geolocation-android' could not be found in root project 'bison-driver-app'.
[stderr] 
* Try:
[stderr] 
> Run with --stacktrace option to get the stack trace.
[stderr] 
> Run with --info or --debug option to get more log output.
[stderr] 
> Run with --scan to get full insights.
[stderr] 
* Get more help at https://help.gradle.org
[stderr] 
BUILD FAILED in 1m 24s
5 actionable tasks: 5 executed
Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

christocracy commented 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.

t34Virus commented 1 year ago

I followed the INSTALL-EXPO instructions. You mean to replace npx expo install react-native-background-geolocation with npm install react-native-background-geolocation?

christocracy commented 1 year ago

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'.
t34Virus commented 1 year ago

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"
  }
}
christocracy commented 1 year ago

Do you have a local /android folder?

t34Virus commented 1 year ago

I can build an /android folder locally but don't require one to deploy to EAS.

christocracy commented 1 year ago

do it. Then post the following files (after running npx expo prebuild)

t34Virus commented 1 year ago
android/build.gradle ``` // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { // @generated begin expo-gradle-ext-vars - expo prebuild (DO NOT MODIFY) sync-ae035b364a8db054c4638b255e3ece11110d7bc0 googlePlayServicesLocationVersion = "20.0.0" appCompatVersion = "1.4.2" // @generated end expo-gradle-ext-vars buildToolsVersion = findProperty('android.buildToolsVersion') ?: '33.0.0' minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '21') compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '33') targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '33') if (findProperty('android.kotlinVersion')) { kotlinVersion = findProperty('android.kotlinVersion') } frescoVersion = findProperty('expo.frescoVersion') ?: '2.5.0' // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. ndkVersion = "23.1.7779620" } repositories { google() mavenCentral() } dependencies { classpath('com.android.tools.build:gradle:7.4.1') classpath('com.facebook.react:react-native-gradle-plugin') } } allprojects { repositories { // @generated begin [react-native-background-fetch]-maven - expo prebuild (DO NOT MODIFY) sync-b86324ce2eb77b03cc8b69ba206ef8275cd006ff maven { url "${project(":react-native-background-fetch").projectDir}/libs" } // @generated begin [react-native-background-geolocation-android-maven - expo prebuild (DO NOT MODIFY) sync-c8fd391463f140f3e9195379c34eec7ac7c7d9c5 maven { url "${project(":react-native-background-geolocation-android").projectDir}/libs" } // @generated end [react-native-background-geolocation-android-maven // @generated end [react-native-background-fetch]-maven maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url(new File(['node', '--print', "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), '../android')) } maven { // Android JSC is installed from npm url(new File(['node', '--print', "require.resolve('jsc-android/package.json')"].execute(null, rootDir).text.trim(), '../dist')) } google() mavenCentral() maven { url 'https://www.jitpack.io' } } } // @generated begin expo-camera-import - expo prebuild (DO NOT MODIFY) sync-f244f4f3d8bf7229102e8f992b525b8602c74770 def expoCameraMavenPath = new File(["node", "--print", "require.resolve('expo-camera/package.json')"].execute(null, rootDir).text.trim(), "../android/maven") allprojects { repositories { maven { url(expoCameraMavenPath) } } } // @generated end expo-camera-import ```
android/app/build.gradle ``` apply plugin: "com.android.application" apply plugin: "com.facebook.react" import com.android.build.OutputFile def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath() def expoDebuggableVariants = ['debug'] // Override `debuggableVariants` for expo-updates debugging if (System.getenv('EX_UPDATES_NATIVE_DEBUG') == "1") { react { expoDebuggableVariants = [] } } /** * This is the configuration block to customize your React Native Android app. * By default you don't need to apply any configuration, just uncomment the lines you need. */ react { entryFile = file(["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android", "absolute"].execute(null, rootDir).text.trim()) reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile() hermesCommand = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/sdks/hermesc/%OS-BIN%/hermesc" debuggableVariants = expoDebuggableVariants /* Folders */ // The root of your project, i.e. where "package.json" lives. Default is '..' // root = file("../") // The folder where the react-native NPM package is. Default is ../node_modules/react-native // reactNativeDir = file("../node_modules/react-native") // The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen // codegenDir = file("../node_modules/react-native-codegen") // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js // cliFile = file("../node_modules/react-native/cli.js") /* Variants */ // The list of variants to that are debuggable. For those we're going to // skip the bundling of the JS bundle and the assets. By default is just 'debug'. // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. // debuggableVariants = ["liteDebug", "prodDebug"] /* Bundling */ // A list containing the node command and its flags. Default is just 'node'. // nodeExecutableAndArgs = ["node"] // // The command to run when bundling. By default is 'bundle' // bundleCommand = "ram-bundle" // // The path to the CLI configuration file. Default is empty. // bundleConfig = file(../rn-cli.config.js) // // The name of the generated asset file containing your JS bundle // bundleAssetName = "MyApplication.android.bundle" // // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' // entryFile = file("../js/MyApplication.android.js") // // A list of extra flags to pass to the 'bundle' commands. // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle // extraPackagerArgs = [] /* Hermes Commands */ // The hermes compiler command to run. By default it is 'hermesc' // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" // // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" // hermesFlags = ["-O", "-output-source-map"] } // Override `hermesEnabled` by `expo.jsEngine` ext { hermesEnabled = (findProperty('expo.jsEngine') ?: "hermes") == "hermes" } /** * Set this to true to create four separate APKs instead of one, * one for each native architecture. This is useful if you don't * use App Bundles (https://developer.android.com/guide/app-bundle/) * and want to have separate APKs to upload to the Play Store. */ def enableSeparateBuildPerCPUArchitecture = false /** * Set this to true to Run Proguard on Release builds to minify the Java bytecode. */ def enableProguardInReleaseBuilds = (findProperty('android.enableProguardInReleaseBuilds') ?: false).toBoolean() /** * The preferred build flavor of JavaScriptCore (JSC) * * For example, to use the international variant, you can use: * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` * * The international variant includes ICU i18n library and necessary data * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that * give correct results when using with locales other than en-US. Note that * this variant is about 6MiB larger per architecture than default. */ def jscFlavor = 'org.webkit:android-jsc:+' /** * Private function to get the list of Native Architectures you want to build. * This reads the value from reactNativeArchitectures in your gradle.properties * file and works together with the --active-arch-only flag of react-native run-android. */ def reactNativeArchitectures() { def value = project.getProperties().get("reactNativeArchitectures") return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] } android { // @generated begin [react-native-background-geolocation-android]-project - expo prebuild (DO NOT MODIFY) sync-cecd55bc11b96b7b7cb2924c1f993a859c0f5e89 Project background_geolocation = project(':react-native-background-geolocation-android') apply from: "${background_geolocation.projectDir}/app.gradle" // @generated end [react-native-background-geolocation-android]-project // @generated begin [react-native-background-fetch]-project - expo prebuild (DO NOT MODIFY) sync-56d2d70cbc3f26369dd5e711d0ab87bf3c0aebb3 Project background_fetch = project(':react-native-background-fetch') // @generated end [react-native-background-fetch]-project ndkVersion rootProject.ext.ndkVersion compileSdkVersion rootProject.ext.compileSdkVersion namespace 'IN_EMAIL' defaultConfig { applicationId 'IN_EMAIL' minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "0.0.0" } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include (*reactNativeArchitectures()) } } signingConfigs { debug { storeFile file('debug.keystore') storePassword 'android' keyAlias 'androiddebugkey' keyPassword 'android' } } buildTypes { debug { signingConfig signingConfigs.debug } release { // Caution! In production, you need to generate your own keystore file. // see https://reactnative.dev/docs/signed-apk-android. signingConfig signingConfigs.debug minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" // @generated begin [react-native-background-geolocation-android]-proguard - expo prebuild (DO NOT MODIFY) sync-606db7f838db1722ea0ff547adceb798272bd706 proguardFiles "${background_geolocation.projectDir}/proguard-rules.pro" // @generated end [react-native-background-geolocation-android]-proguard // @generated begin [react-native-background-fetch]-proguard - expo prebuild (DO NOT MODIFY) sync-7cb5d9a88ae03463dcde5b7e8571a725ecd5854f proguardFiles "${background_fetch.projectDir}/proguard-rules.pro" // @generated end [react-native-background-fetch]-proguard } } // applicationVariants are e.g. debug, release applicationVariants.all { variant -> variant.outputs.each { output -> // For each separate APK per architecture, set a unique version code as described here: // https://developer.android.com/studio/build/configure-apk-splits.html // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc. def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = defaultConfig.versionCode * 1000 + versionCodes.get(abi) } } } } // Apply static values from `gradle.properties` to the `android.packagingOptions` // Accepts values in comma delimited lists, example: // android.packagingOptions.pickFirsts=/LICENSE,**/picasa.ini ["pickFirsts", "excludes", "merges", "doNotStrip"].each { prop -> // Split option: 'foo,bar' -> ['foo', 'bar'] def options = (findProperty("android.packagingOptions.$prop") ?: "").split(","); // Trim all elements in place. for (i in 0.. 0) { println "android.packagingOptions.$prop += $options ($options.length)" // Ex: android.packagingOptions.pickFirsts += '**/SCCS/**' options.each { android.packagingOptions[prop] += it } } } dependencies { // The version of react-native is set by the React Native Gradle Plugin implementation("com.facebook.react:react-android") def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true"; def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true"; def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true"; def frescoVersion = rootProject.ext.frescoVersion // If your app supports Android versions before Ice Cream Sandwich (API level 14) if (isGifEnabled || isWebpEnabled) { implementation("com.facebook.fresco:fresco:${frescoVersion}") implementation("com.facebook.fresco:imagepipeline-okhttp3:${frescoVersion}") } if (isGifEnabled) { // For animated gif support implementation("com.facebook.fresco:animated-gif:${frescoVersion}") } if (isWebpEnabled) { // For webp support implementation("com.facebook.fresco:webpsupport:${frescoVersion}") if (isWebpAnimatedEnabled) { // Animated webp support implementation("com.facebook.fresco:animated-webp:${frescoVersion}") } } implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0") debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { exclude group:'com.squareup.okhttp3', module:'okhttp' } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") if (hermesEnabled.toBoolean()) { implementation("com.facebook.react:hermes-android") } else { implementation jscFlavor } } apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle"); applyNativeModulesAppBuildGradle(project) ```
christocracy commented 1 year ago

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.

t34Virus commented 1 year ago

Interesting. I appreciate you pinpointing the issue. I will look into it further on my end.

christocracy commented 1 year ago

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.

christocracy commented 1 year ago

The expo plug-in script could probably be changed to load package.json to see which version of the plug-in is installed.

christocracy commented 1 year ago

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.

t34Virus commented 1 year ago

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?

t34Virus commented 1 year ago

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

cgav commented 1 year ago

@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

t34Virus commented 1 year ago

@cgav that's very kind of you, thank you! I'll forward this over to my former team to double check.

t34Virus commented 1 year ago

@cgav thank you again for the fix! 💪🥹