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.62k stars 428 forks source link

Project with path ':react-native-background-geolocation-android' could not be found in project ':app'. #1813

Closed christian-hess-94 closed 3 months ago

christian-hess-94 commented 1 year ago

Your Environment

Expected Behavior

The app should run after doing the installation according to the docs

Actual Behavior

App fails when executing yarn start + A or yarn android with the following error:

* Where:
Build file 'C:\Users\chris\Desktop\POCBackgroundLocation\android\app\build.gradle' line: 5

* What went wrong:
A problem occurred evaluating project ':app'.
> Project with path ':react-native-background-geolocation-android' could not be found in project ':app'.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified. Please add it to build.gradle

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
=============================================================================

I have already triple checked the build.gradle files and they all seem to be correct. The project is not able to execute line 5 of app/build.gradle:

project(':react-native-background-geolocation-android')

I have checked inside the node_modules folder and the .iml file exists in there as per this screenshot image

Steps to Reproduce

  1. Clone reproducible repo: https://github.com/christian-hess-94/poc-background-location
  2. Install deps with yarn or npm
  3. Run yarn start + A (npm run start + A) or yarn android(npm run android)
  4. Code breaks on starting Android installation

Context

I was creating a POC to see if the plugin is easy to configure and install in the project I'm currently working at. Created a brand new RN project with npx react-native init AppName --template react-native-template-typescript and installed only it

Debug logs (no logs were generated)

Logs ``` No logs are generated ```
christocracy commented 1 year ago

post your two gradle files:

christian-hess-94 commented 1 year ago

android/app/build.gradlew

apply plugin: "com.android.application"
apply plugin: "com.facebook.react"

// background-geolocation
Project background_geolocation = project(':react-native-background-geolocation-android')
apply from: "${background_geolocation.projectDir}/app.gradle"

/**
 * 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 {
    /* 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"]
}

/**
 * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
 */
def enableProguardInReleaseBuilds = false

/**
 * 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:'

android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    namespace "com.pocbackgroundlocation"
    defaultConfig {
        applicationId "com.pocbackgroundlocation"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    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"
        }
    }
}

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")

    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: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
christian-hess-94 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 {
        buildToolsVersion= "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        appCompatVersion = "1.4.2"   
        googlePlayServicesLocationVersion = "20.0.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")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }
}

allprojects {
    repositories{
        // Required for react-native-background-geolocation
        maven { url("${project(':react-native-background-geolocation').projectDir}/libs") }
        maven { url 'https://developer.huawei.com/repo/' }
       // Required for react-native-background-fetch
        maven { url("${project(':react-native-background-fetch').projectDir}/libs") }
    }
}
christocracy commented 1 year ago
   maven { url("${project(':react-native-background-geolocation').projectDir}/libs") }

If you're installing from the private repo react-native-background-geolocation-android, then that maven url needs to have -android appended to it.

Also, why does your app/build.gradle contain no references to background_geolocation, as prescribed in the Setup Instructions linked in the README.

I suggest you go have a close look at the Android Setup Instructions.

christocracy commented 1 year ago

Also, why does your app/build.gradle contain no references to background_geolocation

Correction, there it is. However, you're still missing entries prescribed by the Setup Instructions (eg: proguard-rules)

// background-geolocation Project background_geolocation = project(':react-native-background-geolocation-android') apply from: "${background_geolocation.projectDir}/app.gradle"

christocracy commented 1 year ago

Your build.gradle files are confused between references to react-native-background-geolocation (the public version from npm) and react-native-background-geolocation-android (the private version).

They all need to match.

christian-hess-94 commented 1 year ago

thanks I will give those a look. I had copied the setup from this section of the docs:

image

christian-hess-94 commented 1 year ago

I don't think I'm installing it from the private repo, so I would have to change it in the Project background_geolocation = project(':react-native-background-geolocation-android')

To Project background_geolocation = project(':react-native-background-geolocation')

christian-hess-94 commented 1 year ago

Also not sure if it's relevant but I don't have a license yet

darksnow commented 11 months ago

This page https://github.com/transistorsoft/react-native-background-geolocation/blob/master/help/INSTALL-ANDROID-AUTO.md has instructions to add:

Project background_geolocation = project(':react-native-background-geolocation-android')

to android/app/build.gradle

If this is wrong, then the documentation needs to be updated.

christocracy commented 11 months ago

Fixed;

mumnanikunj commented 11 months ago

include ':react-native-background-geolocation' project(':react-native-background-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-geolocation/android')

include ':react-native-background-fetch' project(':react-native-background-fetch').projectDir = new File(rootProject.projectDir , './node_modules/react-native-background-fetch/android')

add this line in setting.gradle @christian-hess-94

github-actions[bot] commented 4 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 3 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.