Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help Wanted]: Issue with ./gradlew androidDependencies after upgrading to React Native 0.74 #2275

Open
2 of 3 tasks
rarenatoe opened this issue Feb 14, 2025 · 14 comments
Open
2 of 3 tasks

Comments

@rarenatoe
Copy link

rarenatoe commented Feb 14, 2025

Required Reading

  • Confirmed

Plugin Version

4.17.6

Mobile operating-system(s)

  • iOS
  • Android

What do you require assistance about?

Hello,

I recently upgraded my project to React Native 0.74. Running npx react-native run-android works fine, but when I execute cd android && ./gradlew androidDependencies, I encounter the following error:

Execution failed for task ':app:androidDependencies'.
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
   > Could not resolve com.transistorsoft:tslocationmanager-v21:+.
     Required by:
         project :app > project :react-native-background-geolocation
      > Failed to list versions for com.transistorsoft:tslocationmanager-v21.
         > Unable to load Maven meta-data from file:/Users/renatoalegre/Repositories/mobile/node_modules/react-native-background-geolocation/android/libs/com/transistorsoft/tslocationmanager-v21/maven-metadata.xml.
            > org.xml.sax.SAXNotRecognizedException: Property 'http://javax.xml.XMLConstants/property/accessExternalSchema' is not recognized.

This happens even if I upgrade to the latest version of the package.

Could you please provide guidance on how to temporarily fix this? I want to migrate to future React Native versions, but this is a large project, so upgrading incrementally (even with patches) is necessary for us.

Any advice or workarounds would be greatly appreciated.

Thanks!

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 31
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "26.1.10909125"
        kotlinVersion = "1.9.24"

        // Additions for react-native-background-location
        googlePlayServicesLocationVersion = "21.3.0"
        appCompatVersion = "1.6.1"
    }
    repositories {
        google()
        mavenCentral()
        // FullStory
        maven { url "https://maven.fullstory.com" }
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
        classpath("com.jaredsburrows:gradle-license-plugin:0.9.7")
        classpath("com.google.gms:google-services:4.4.2")
        classpath(localGroovy())
        classpath("com.fullstory:gradle-plugin-local:1.53.0")
    }
}

allprojects {
    repositories {
        // Required for react-native-background-geolocation
        maven { url("${project(':react-native-background-geolocation').projectDir}/libs") }

        // Required for react-native-background-fetch
        maven { url("${project(':react-native-background-fetch').projectDir}/libs") }
        
        // All of Detox' artifacts are provided via the npm module
        maven { url "$rootDir/../node_modules/detox/Detox-android" }
    }
}

apply plugin: "com.facebook.react.rootproject"

android/app/build.gradle

apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "fullstory"
apply plugin: "com.facebook.react"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
apply plugin: "com.jaredsburrows.license"

import com.android.build.OutputFile
import groovy.json.JsonSlurper

/**
 * 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 {
    /* 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 = ["debug", "release"]
}

/**
* 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 = true

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

licenseReport {
    generateHtmlReport = false
    generateJsonReport = true
    copyHtmlReportToAssets = false
    copyJsonReportToAssets = true
}

def getNpmVersion() {
    def inputFile = new File("../package.json")
    def packageJson = new JsonSlurper().parseText(inputFile.text)
    return packageJson["version"]
}

def getNpmVersionArray() { // major [0], minor [1], patch [2]
    def (major, minor, patch) = getNpmVersion().tokenize('.')
    return [Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patch)] as int[]
}
def npmVersion = getNpmVersionArray()
def versionMajor = npmVersion[0]
def versionMinor = npmVersion[1]
def versionPatch = npmVersion[2]

apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

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

def enableShrinkResources = true

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

def getGitSha = {
    return 'git rev-parse HEAD'.execute().text.trim()
}

repositories {
    flatDir {
        dirs 'libs'
    }
}

fullstory {
  org "1ND1D"
  enabledVariants 'all'
  // This is enabled by default. Disabled so we can only record staging sessions.
  recordOnStart false
}

android {
    ndkVersion rootProject.ext.ndkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace "com.swoopmobile"

    buildFeatures {
        buildConfig = true
    }

    defaultConfig {
        applicationId "com.swoopmobile"
        manifestPlaceholders = [codeVersion: "${getGitSha()}", auth0Domain: "${project.env.get("AUTH0_DOMAIN")}", auth0Scheme: "${applicationId}.auth0"]
        minSdkVersion rootProject.ext.minSdkVersion
        missingDimensionStrategy 'react-native-camera', 'general'
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode versionMajor * 100000000 + versionMinor * 10000 + versionPatch
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
        buildConfigField "String", "GIT_SHA", "\"${getGitSha()}\""
        testBuildType System.getProperty('testBuildType', 'debug')  // This will later be used to control the test apk build type
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
        resConfigs 'en'
        resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include (*reactNativeArchitectures())
        }
    }

    signingConfigs {
        debug {
            storeFile file("debug.keystore")
        }
    }

    buildTypes {
        debug {
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            proguardFiles "${background_geolocation.projectDir}/proguard-rules.pro" // Detox-specific additions to pro-guard
            proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
        }
        release {
            minifyEnabled enableProguardInReleaseBuilds
            shrinkResources enableShrinkResources
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            proguardFiles "${background_geolocation.projectDir}/proguard-rules.pro" // Detox-specific additions to pro-guard
            proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
        }
    }

    // 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)
            }
        }
    }
}

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

    androidTestImplementation('com.wix:detox-legacy:+')

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }

    // Dependencies that cannot be autolinked yet can be added manually here
    implementation 'com.pixotech.android.scanner.library:AndroidScanLib@aar'
    implementation 'com.squareup.retrofit:retrofit:1.9.0'
}

// [Added by react-native-background-geolocation] Purge debug sounds from release build.
def purgeBackgroundGeolocationDebugResources(applicationVariants) {
    if ((rootProject.ext.has("removeBackgroundGeolocationDebugSoundsInRelease")) && (rootProject.ext.removeBackgroundGeolocationDebugSoundsInRelease == false)) return
    applicationVariants.all { variant ->
        if (variant.buildType.name == "release") {
            println("[react-native-background-geolocation] Purging debug resources in release build")
            variant.mergeResources.doLast {
                delete(fileTree(dir: variant.mergeResources.outputDir, includes: ["raw_tslocationmanager*"]))
            }
        }
    }
}

apply plugin: 'com.google.gms.google-services'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
@christocracy
Copy link
Member

Post your two gradle files.

@rarenatoe
Copy link
Author

rarenatoe commented Feb 14, 2025

Thanks for the fast response @christocracy , I edited the original issue with the gradle files.

@christocracy
Copy link
Member

4.17.6

I would start installing the latest version:

https://github.com/transistorsoft/react-native-background-geolocation/blob/master/CHANGELOG.md

@rarenatoe
Copy link
Author

@christocracy as I said in the first message, installing the latest version doesn't change the issue at all.

@christocracy
Copy link
Member

I suggest you carefully review the Setup Instructions and very correct edit your files to follow every step exactly as-directed.

@rarenatoe
Copy link
Author

Yes, I checked the android setup earlier today, and just did it again.
Only difference is that this is included in allprojects.repositories

maven { url 'https://developer.huawei.com/repo/' }

I have tried including this in my setup, but the issue persists.

I see it also asks to set shrinkResources false on release builds, but what I am trying to build is a debug build. Also my license validation has never failed in react native 0.72 (what my master branch uses today) or prior.

@christocracy
Copy link
Member

I think you’ve likely messed something up in your upgrade of RN.

I suggest you generate a simple hello-world and follow the setup instructions to make sure it works in a freshly generated app.

@rarenatoe
Copy link
Author

Thanks for the suggestion—I went ahead and created a fresh React Native 0.74.7 project using:

npx [email protected] init testproject --version 0.74.7

Then, I followed the setup instructions exactly as documented. After installing the dependency and running ./gradlew androidDependencies, I encountered the same issue:

> Task :app:androidDependencies FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:androidDependencies'.
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
   > Could not resolve com.transistorsoft:tslocationmanager-v21:+.
     Required by:
         project :app > project :react-native-background-geolocation
      > Failed to list versions for com.transistorsoft:tslocationmanager-v21.
         > Unable to load Maven meta-data from file:/Users/renatoalegre/Repositories/testproject/node_modules/react-native-background-geolocation/android/libs/com/transistorsoft/tslocationmanager-v21/maven-metadata.xml.
            > org.xml.sax.SAXNotRecognizedException: Property 'http://javax.xml.XMLConstants/property/accessExternalSchema' is not recognized.

This confirms that the problem is not related to my upgrade but rather something upstream. Given that this is reproducible in a clean project, could you take a closer look on your end? Let me know if you need any additional details to help investigate.

@christocracy
Copy link
Member

I just generated a fresh hello-world, followed the Setup Instructions and it works.

package.json

{
  "name": "foo5",
  "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.3.1",
    "react-native": "0.77.1",
    "react-native-background-fetch": "^4.2.7",
    "react-native-background-geolocation": "^4.18.5"
  },
  "devDependencies": {
    "@babel/core": "^7.25.2",
    "@babel/preset-env": "^7.25.3",
    "@babel/runtime": "^7.25.0",
    "@react-native-community/cli": "15.0.1",
    "@react-native-community/cli-platform-android": "15.0.1",
    "@react-native-community/cli-platform-ios": "15.0.1",
    "@react-native/babel-preset": "0.77.1",
    "@react-native/eslint-config": "0.77.1",
    "@react-native/metro-config": "0.77.1",
    "@react-native/typescript-config": "0.77.1",
    "@types/jest": "^29.5.13",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.3.1",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "35.0.0"
        minSdkVersion = 24
        compileSdkVersion = 35
        targetSdkVersion = 34
        ndkVersion = "27.1.12297006"
        kotlinVersion = "2.0.21"
        appCompatVersion 	= "1.4.2"      // Or higher.  Required for new AndroidX compatibility.
        googlePlayServicesLocationVersion = "21.0.1"  // Or higher.

    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
    }
}

allprojects {   // <-- NOTE:  allprojects container -- If you don't see this, create it.
    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") }
    }
}

The plugin announces itself in the logs when the app launches:

02-15 09:14:40.678 18734 18775 D TSBackgroundFetch: [RNBackgroundFetch initialize]
02-15 09:14:40.681 18734 18734 D TSBackgroundFetch: ☯️  onCreate
02-15 09:14:40.681 18734 18734 D TSBackgroundFetch: ☯️  onStart
02-15 09:14:40.682 18734 18734 D TSBackgroundFetch: ☯️  onResume
02-15 09:14:40.734 18734 18775 E TSLocationManager: ╔═════════════════════════════════════════════
02-15 09:14:40.734 18734 18775 E TSLocationManager: ║ LICENSE VALIDATION FAILURE: com.foo5
02-15 09:14:40.734 18734 18775 E TSLocationManager: ╠═════════════════════════════════════════════
02-15 09:14:40.734 18734 18775 E TSLocationManager: ╟─ Failed to find license key in AndroidManifest.  Ensure you've added the key within <application><meta-data android:name="com.transistorsoft.locationmanager.license" android:value="<YOUR LICENSE KEY>" />
02-15 09:14:40.734 18734 18775 E TSLocationManager: ╟─ BackgroundGeolocation is fully functional in DEBUG builds without a license so you can 'try before you buy'.
02-15 09:14:40.734 18734 18775 E TSLocationManager: ╚═════════════════════════════════════════════

@rarenatoe
Copy link
Author

rarenatoe commented Feb 15, 2025

  1. You're using React Native 0.77, but the issue occurs specifically with React Native 0.74.
    As I've suggested before, please use the following command to generate a project with the affected version:
    npx [email protected] init testproject --version 0.74.7
  2. As I mentioned in my first post, the app launching in dev mode isn't the issue—npx react-native run-android works as expected.
  3. The issue arises when running:
    cd android && ./gradlew androidDependencies
    This command is useful for diagnosing dependency conflicts in an Android project. In my case, it's part of our deployment pipeline as a verification step, so disabling it wouldn't be a good practice.

@christocracy
Copy link
Member

I have no explanation for ./gradlew androidDependencies failing with [email protected].

However, ./gradlew app:dependencies does not fail. You can use this instead for printing a dependency-tree for your app (this is what I've always used).

./gradle androidDependencies does not fail with [email protected] (current latest). I suspect the problem is related to gradle-tools version.

@rarenatoe
Copy link
Author

Alright thanks. I guess I'll see if I can upgrade further to react native 0.75

@christocracy
Copy link
Member

to react native 0.75

Why not 0.77?

@rarenatoe
Copy link
Author

Our project is currently on React Native 0.72, and upgrading three versions at once is already a significant jump. Given the size of our project, such an upgrade has historically introduced unforeseen issues with dependencies, so we prefer a more controlled approach to minimize risks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants