transistorsoft / react-native-background-fetch

Periodic callbacks in the background for both IOS and Android
MIT License
1.43k stars 191 forks source link

Could not determine the dependencies of task ':app:processDebugResources'. #458

Closed khalifathul closed 2 weeks ago

khalifathul commented 9 months ago

πŸš€ [UPDATE] Solution πŸš€

πŸ“‚ android/build.gradle

allprojects {
    repositories {
+       mavenLocal()
+       mavenCentral()
        // 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") }
    }
}

Your Environment

Expected Behavior

After installation app should work

Actual Behavior

After installation throw an error

Steps to Reproduce

  1. add maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
  2. clear cache clean and rebuild

Context

I tried to implement the sample code

Debug logs

Could not determine the dependencies of task ':app:processDebugResources'.

Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'. Could not find any matches for com.transistorsoft:tsbackgroundfetch:+ as no versions of com.transistorsoft:tsbackgroundfetch are available. Searched in the following locations:

Possible solution:

christocracy commented 9 months ago

This issue has been posted dozens of times.

you didn’t follow the Setup Instructions

Jobjeuh commented 9 months ago

I had it working on an older version of RN (0.70.6), so I would assume I did the setup instructions correctly, but recently upgraded to 0.72.4. I even upgraded the background-geolocation and background-fetch packages to their latest versions.

But after the RN upgrade, I get hit with a similar sort of error. My console output says the following: `Could not determine the dependencies of task ':app:processDebugResources'.

Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'. Could not resolve com.transistorsoft:tsbackgroundfetch:+. Required by: project :app > project :react-native-background-fetch Failed to list versions for com.transistorsoft:tsbackgroundfetch. Unable to load Maven meta-data from https://www.jitpack.io/com/transistorsoft/tsbackgroundfetch/maven-metadata.xml. Could not GET 'https://www.jitpack.io/com/transistorsoft/tsbackgroundfetch/maven-metadata.xml'. Read timed out`

Is there something I might still be doing wrong? Or is it due to the latest RN version that breaks this?

christocracy commented 9 months ago

Post your android/build.gradle

Jobjeuh commented 9 months ago
// 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"
        RNMapboxMapsImpl = "mapbox"

        // 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")
        classpath("com.google.gms:google-services:4.3.14")
        classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.2")
    }
}

allprojects {
    repositories {
        maven {
            // Required for react-native-background-geolocation
            url("${project(':react-native-background-geolocation').projectDir}/libs")
        }
        maven {
            // Required for react-native-background-fetch
            url("${project(':react-native-background-fetch').projectDir}/libs")
        }
        maven {
            url 'https://api.mapbox.com/downloads/v2/releases/maven'
            authentication {
                basic(BasicAuthentication)
            }
            credentials {
                //
            }
        }
    }
}
christocracy commented 9 months ago

In the /example app in this repo, the allprojects/repositories section contains both mavenLocal() and mavenCentral()

https://github.com/transistorsoft/react-native-background-fetch/blob/35408089abbc06e430be821a4e02faaa6d2f520a/example/android/build.gradle#L31

Jobjeuh commented 9 months ago

That did resolve the issue. Just as a headsup: the RN upgrade explicitly removes the allprojects and by extension all the repositories in there, so even though the docs are correct that you have to add it back in (see here), it skips the mavenCentral and mavenLocal having to also be added back in

christocracy commented 9 months ago

I just did a fresh new $ npx react-native init foo, added the plugin according to the current Setup Instructions. I did not have to add anything extra (ie: mavenLocal(), mavenCentral()) to allprojects/repositories.

{
  "name": "foo2",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.72.4"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/eslint-config": "^0.72.2",
    "@react-native/metro-config": "^0.72.11",
    "@tsconfig/react-native": "^3.0.0",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.76.8",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "engines": {
    "node": ">=16"
  }
}

πŸ“‚ 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"      // Or higher.  Required for new AndroidX compatibility.
        googlePlayServicesLocationVersion = "21.0.1"  // Or higher.

        // 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-android').projectDir}/libs") }
        maven { url 'https://developer.huawei.com/repo/' }
        // Required for react-native-background-fetch
        maven { url("${project(':react-native-background-fetch').projectDir}/libs") }
    }
}
Screenshot 2023-08-18 at 10 26 58 AM

With a simple implementation of BackgroundGeolocation, the plugin launches, fires events and enters the stationary-state.

08-18 10:25:39.910 16794 16951 I TSLocationManager: [c.t.l.adapter.TSConfig print]
08-18 10:25:39.910 16794 16951 I TSLocationManager: ╔═════════════════════════════════════════════
08-18 10:25:39.910 16794 16951 I TSLocationManager: β•‘ TSLocationManager version: 3.4.2 (422)
08-18 10:25:39.910 16794 16951 I TSLocationManager: ╠═════════════════════════════════════════════
08-18 10:25:39.910 16794 16951 I TSLocationManager: β•Ÿβ”€ Google Pixel 6 @ 14 (react-native)
08-18 10:25:39.910 16794 16951 I TSLocationManager: {
.
.
.
08-18 10:25:39.910 16794 16951 I TSLocationManager: }
.
.
.
08-18 10:25:46.347 16794 16794 D TSLocationManager: [c.t.l.g.TSGeofenceManager startMonitoringStationaryRegion]
08-18 10:25:46.347 16794 16794 D TSLocationManager:   🎾  Start monitoring stationary region (radius: 150.0m 45.5188929,-73.6005087 hAcc=26.4)
08-18 10:25:46.350 16794 16951 I TSLocationManager: [a.b persist]
08-18 10:25:46.350 16794 16951 I TSLocationManager:   βœ…  INSERT: 6ea5bd92-9d5b-4c8c-912b-8f10502d7483
08-18 10:25:46.360  1601  3727 I ActivityManager: Background started FGS: Allowed [callingPackage: com.foo2; callingUid: 10344; uidState: TPSL; uidBFSL: n/a; intent: Intent { act=motionchange cmp=com.foo2/com.transistorsoft.locationmanager.service.TrackingService }; code:ACTIVITY_STARTER; tempAllowListReason:<null,reasonCode:LOCATION_PROVIDER,duration:20000,callingUid:10149>; targetSdkVersion:33; callerTargetSdkVersion:33; startForegroundCount:0; bindFromPackage:null: isBindService:false]
08-18 10:25:46.377 16794 16794 D TSLocationManager: [c.t.l.service.AbstractService start]
08-18 10:25:46.377 16794 16794 D TSLocationManager:   🎾  TrackingService [eventCount: 1]
08-18 10:25:46.378 16794 16794 I TSLocationManager: [c.t.l.service.TrackingService handleMotionChangeResult]
08-18 10:25:46.378 16794 16794 I TSLocationManager: ╔═════════════════════════════════════════════
08-18 10:25:46.378 16794 16794 I TSLocationManager: β•‘ TrackingService motionchange: false
08-18 10:25:46.378 16794 16794 I TSLocationManager: ╠═════════════════════════════════════════════

However, I did initially have a runtime ClassCastException (from background-geolocation) related to that plugin importing the latest logback-android@3.0.0 (the plugin's Logger lib) because of this, where RN's com.facebook.flipper requires the older version (2.0.1). I will downgrade the plugin's default logback-android to match what flipper requires.

08-18 10:01:50.888 31886 32024 E AndroidRuntime: java.lang.ClassCastException: org.slf4j.helpers.SubstituteLogger cannot be cast to ch.qos.logback.classic.Logger
08-18 10:01:50.888 31886 32024 E AndroidRuntime:    at com.transistorsoft.locationmanager.logger.TSLog.getRootLogger(Unknown Source:6)
08-18 10:01:50.888 31886 32024 E AndroidRuntime:    at com.transistorsoft.locationmanager.logger.TSLog.access$000(Unknown Source:0)
08-18 10:01:50.888 31886 32024 E AndroidRuntime:    at com.transistorsoft.locationmanager.logger.TSLog$a.run(Unknown Source:0)
08-18 10:01:50.888 31886 32024 E AndroidRuntime:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
08-18 10:01:50.888 31886 32024 E AndroidRuntime:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
08-18 10:01:50.888 31886 32024 E AndroidRuntime:    at java.lang.Thread.run(Thread.java:1012)
christocracy commented 9 months ago

Could you please find out exactly which added repository fixes your issue?

Does just mavenLocal() fix it or does it require both mavenLocal() AND mavenCentral()?

Jobjeuh commented 9 months ago

Yes I will. I do not have the time right now, but I will check for you on monday :)

christocracy commented 9 months ago

Today I upgraded the SampleApp from RN 0.68.5 -> 0.72.4.

It does not require any extra repositories in allprojects/repositories

allprojects {
    repositories {
        // It's been reported that some people might require mavenLocal() repo here.
        // I leave it disabled for now.
        //mavenLocal()

        // 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") }
    }
}
github-actions[bot] commented 4 weeks ago

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

github-actions[bot] commented 2 weeks ago

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