Search code examples
androidreact-nativegradle-kotlin-dslgradle-settings

Keep com.facebook.react gradle plugin from silently adding project repositories


I'm configuring an existing Android app adding react native support. I already migrated gradle files in the documentation to Kotlin DSL and Versions catalog which is the target configuration required by the existing app.

The current configuration in settings.gradle.kts requires settings repositories:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        //...
    }
}

Right after applying the plugin in :app build.gradle.kts like this:

plugins {
    //..
    id("com.facebook.react")
}

I get the following error:

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

Switching to repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) makes the error only a warning but then I get other errors when compiling probably because of the conflict and ultimately I need to stick to RepositoriesMode.FAIL_ON_PROJECT_REPOS to comply with the policies.

Here is the error I get when I use RepositoriesMode.PREFER_SETTINGS:

A problem occurred configuring project ':app'.
> defaultConfig contains custom resource values, but the feature is disabled.

Here is the list of warnings I get:

Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by plugin 'com.facebook.react'
Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by plugin 'com.facebook.react'
Build was configured to prefer settings repositories over project repositories but repository 'maven2' was added by plugin 'com.facebook.react'
Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by plugin 'com.facebook.react'
Build was configured to prefer settings repositories over project repositories but repository 'maven3' was added by plugin 'com.facebook.react'

I'm currently using com.facebook.react:react-android:0.73.4

Any ideas?


Solution

  • Finally I got the fix. Turns out we were using some custom plugins and in some of then we had the following configuration:

    resValues = false
    

    That in fact was causing the error and by enabling the feature the error went away.

    // works with the react native plugin without issues.
    resValues = true
    

    Sadly I was not able to get around the react native's plugin behaviour but with the above workaround everything worked for me.