Search code examples
javaandroidreact-nativemavengradle

How to add a maven dependency in gradle 8.x


My react-native android project is running on Gradle v8.3. I have files like settings.gradle and build.gradle in my android project.

The problem I'm having is when I try to implement PendoSDK for android, following the read me below:

https://github.com/pendo-io/pendo-mobile-sdk/blob/master/android/pnddocs/rn-android.md

After installing the paclage, I have to add the following maven url under allProjects of android/build.gradle:

allprojects { 
    repositories {
        maven {
            url "https://software.mobile.pendo.io/artifactory/androidx-release"
        }
        mavenCentral()
    }
}

The problem it with using latest Android Studio Koala and Gradle version greater than 7.4 there is no allProjects and it's buildscript > repositories.

How do I add the above maven repo into my project? Ive tried the following below and it doesn't work.

Tried Solution 1: If I add the maven { url "https://software.mobile.pendo.io/artifactory/androidx-release" } under buildscript > repositories I get Failed to resolve: sdk.pendo.io:pendoIO:3.3.+ error.

Tried Solution 2: If I move add the package in settings.gradle as below:

dependencyResolutionManagement {
     repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven { url "https://software.mobile.pendo.io/artifactory/androidx-release" }
        google()
        mavenCentral()
    }
}

I get the error: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by plugin 'com.facebook.react'

For reference and more info I have opened an issue at their official repo as well: https://github.com/pendo-io/pendo-mobile-sdk/issues/158


Solution

  • Note that allprojects is still valid. You could try adding the repositories section at the top level of your build.script, ie not inside other sections like buildscript.

    It maybe that the repository is not really working.