facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.28k stars 24.35k forks source link

Caused by: org.gradle.api.InvalidUserDataException: Cannot change resolution strategy of dependency configuration ':android-resource:_agp_internal_javaPreCompileDevDebugAndroidTest_kaptClasspath' after it has been resolved. #41983

Closed cbr167 closed 10 months ago

cbr167 commented 11 months ago

Old Version

0.67.5

New Version

0.70.14

Description

getting "Cannot change resolution strategy of dependency configuration " when I try to build after updating rn version to 0.70.14. And error pointing to node_modules/react-native/react.gradle:478.

project.rootProject.allprojects {
    configurations.all {
        resolutionStrategy {
            force "com.facebook.react:react-native:0.70.+"
            force "com.facebook.react:hermes-engine:0.70.+"
        }
}

### package.json

{
    "name": "native-shopping",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "start": "react-native start",
        "test": "jest",
        "tsc": "tsc",
        "format:all": "prettier --config .prettierrc './**/*.ts{,x}' --write",
        "format:staged": "pretty-quick --staged --pattern '**/*.*(tsx|ts)'",
        "supercacheclear": "xcrun simctl erase all && watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/haste-* && rm -rf $TMPDIR/metro-* && npm start -- --reset-cache",
        "superpodinstall": "npm i && cd ios && pod cache clean --all && pod repo update && pod install",
        "reload": "adb shell \"input keyevent 82 && input keyevent 66 && input keyevent 66\"",
        "menu": "adb shell input keyevent 82",
        "reverseJetifier": "jetifier -r",
        "installJetifier": "jetifier",
        "codegen": "graphql-codegen --config codegen.yml",
        "vuln": "npm audit --json --prod-only | npm-audit-helper",
        "bundle-qa-android": "react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/generated/assets/react/debug/index.android.bundle --assets-dest ./android/app/build/res/react/debug",
        "bundle-qa-ios": "react-native bundle --dev false --platform ios --entry-file index.js --bundle-output ios/main.jsbundle --assets-dest ios"
    },
    "dependencies": {

        "@react-native-async-storage/async-storage": "^1.16.1",
        "@react-native-community/cli-platform-android": "^9.3.4",
        "@react-native-community/geolocation": "^2.0.2",
        "@react-native-community/masked-view": "^0.1.7",
        "@react-native-picker/picker": "^2.1.0",
        "await-lock": "^2.1.0",
        "axios": "^0.21.1",
        "axios-cache-adapter": "^2.7.3",
        "cross-fetch": "^3.1.4",
        "graphql": "^15.5.0",
        "hermes-engine": "^0.2.1",
        "lodash.orderby": "^4.6.0",
        "mock-async-storage": "^2.2.0",
        "prop-types": "^15.6.2",
        "react": "18.1.0",
        "react-error-boundary": "^3.1.0",
        "react-native": "0.70.14",
        "react-native-gesture-handler": "^1.10.3",
        "react-native-picker-select": "^8.0.3",
        "react-native-reanimated": "^1.7.0",
        "react-native-render-html": "^4.2.3",
        "react-native-safe-area-context": "^0.7.3",
        "react-native-safe-area-view": "^1.1.1",
        "react-native-screens": "^2.3.0",
        "react-native-share": "^4.1.0",
        "react-native-swipe-gestures": "^1.0.5",
        "react-native-swipe-list-view": "^3.2.6",
        "react-native-typescript-transformer": "^1.2.13",
        "react-native-webview": "^11.23.1",
        "react-navigation": "^4.4.3",
        "react-navigation-stack": "^2.10.2"
    },
    "devDependencies": {
        "@babel/core": "^7.12.9",
        "@babel/preset-env": "^7.12.1",
        "@babel/preset-typescript": "^7.12.1",
        "@babel/runtime": "^7.12.5",
        "@graphql-codegen/add": "^2.0.2",
        "@graphql-codegen/cli": "1.21.4",
        "@graphql-codegen/fragment-matcher": "^2.0.1",
        "@graphql-codegen/introspection": "1.18.2",
        "@graphql-codegen/typescript": "1.22.0",
        "@graphql-codegen/typescript-operations": "1.17.16",
        "@graphql-codegen/typescript-resolvers": "^1.19.1",
        "@react-native-community/eslint-config": "^2.0.0",
        "@testing-library/jest-native": "^4.0.1",
        "@testing-library/react-native": "^7.2.0",
        "@types/faker": "^5.1.7",
        "@types/jest": "^26.0.22",
        "@types/lodash": "^4.14.157",
        "@types/lodash.orderby": "^4.6.6",
        "@types/node": "^13.13.5",
        "@types/react": "^16.9.56",
        "@types/react-native": "^0.64.0",
        "@types/react-native-share": "^3.3.1",
        "@typescript-eslint/eslint-plugin": "^4.3.0",
        "@typescript-eslint/parser": "^4.3.0",
        "babel-eslint": "^10.0.1",
        "babel-jest": "^25.1.0",
        "eslint": "^7.32.0",
        "eslint-config-airbnb": "18.2.1",
        "eslint-config-airbnb-base": "^14.2.0",
        "eslint-config-prettier": "^6.14.0",
        "eslint-plugin-import": "^2.22.1",
        "eslint-plugin-jest": "^24.1.0",
        "eslint-plugin-jsx-a11y": "^6.3.1",
        "eslint-plugin-prettier": "^3.1.4",
        "eslint-plugin-react": "^7.21.5",
        "eslint-plugin-react-hooks": "^4.2.0",
        "eslint-plugin-react-native": "^3.10.0",
        "eslint-plugin-simple-import-sort": "^7.0.0",
        "eslint-plugin-unused-imports": "^1.0.1",
        "husky": "^4.3.6",
        "jest": "^26.6.3",
        "jetifier": "^1.6.5",
        "metro-react-native-babel-preset": "^0.72.4",
        "npm-audit-helper": "^3.1.0",
        "prettier": "^2.0.5",
        "pretty-quick": "^3.1.0",
        "react-test-renderer": "18.1.0",
        "typescript": "^4.1.3"
    },
    "jest": {
        "preset": "react-native"
    },
    "husky": {
        "hooks": {
            "pre-commit": "npm run format:staged && npm run tsc"
        }
    },
    "rnpm": {
        "assets": [
            "./app/assets/fonts/"
        ]
    }
}

### settings.gradle

import org.apache.tools.ant.taskdefs.condition.Os
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
includeBuild('../node_modules/react-native-gradle-plugin')
def runPython(scriptFile){
    def isWindows = Os.isFamily(Os.FAMILY_WINDOWS)
    def script = "python3 $scriptFile"

    def proc = isWindows
            ? script.execute()
            : ["/bin/sh", "-c", script].execute()

    def output = new StringBuilder(), error = new StringBuilder()
    proc.consumeProcessOutput(output, error)
    proc.waitFor()
    if(error.toString().length() > 0)
        println "ERROR: $error"
    if(output.toString().length() > 0)
        println output
}

if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") {
    include(":ReactAndroid")
    project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid')
    include(":ReactAndroid:hermes-engine")
    project(":ReactAndroid:hermes-engine").projectDir = file('../node_modules/react-native/ReactAndroid/hermes-engine')
}
println "Checking React dependencies..."
runPython("app/scripts/checkReactDependencies.py")
println "Dependency check complete!\n"

println "Running Gradle 7 configuration..."
runPython("app/scripts/gradle7configuration.py")
println "Gradle 7 configuration complete!\n"

include ':react-native-webview'
project(':react-native-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview/android')
include(':react-native-gesture-handler')
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
include(':react-native-reanimated')
project(':react-native-reanimated').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-reanimated/android')
include(':react-native-screens')
project(':react-native-screens').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-screens/android')
include(':react-native-safe-area-context')
project(':react-native-safe-area-context').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-safe-area-context/android')
include ':react-native-community-geolocation'
project(':react-native-community-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/geolocation/android')
include ':@react-native-async-storage'
project(':@react-native-async-storage').projectDir = new File(rootProject.projectDir,
include ':app'

### build.gradle

buildscript {

    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 24
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.8.0"
        ndkVersion = "21.4.7075529"
        google_firebase = '21.6.0'
        okhttpVersion = '4.10.0'
        retrofitVersion = '2.9.0'
        gsonVersion = '2.8.6'
        okhttpUrlVersion = '4.4.1'
        kotlin_version = '1.8.10'
        exifinterface = '1.3.3'
        jetpackCompose = '1.2.0'
        compose_activity = '1.4.0'
        mockitoCoreVersion = '4.8.0'
        powermockVersion = '2.0.0-beta.5'
        jUnitVersion = '4.13.2'
        coroutinesTestVersion = '1.8.10'

    }
    if (System.properties['os.arch'] == "aarch64") {
        // For M1 Users we need to use the NDK 24 which added support for aarch64
        ndkVersion = "24.0.8215888"
    } else {
        // Otherwise we default to the side-by-side NDK version from AGP.
        ndkVersion = "21.4.7075529"
    }
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.4.2")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:5.0.1")
        classpath "io.realm:realm-gradle-plugin:10.11.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.13'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1'
        classpath 'com.apollographql.apollo:apollo-gradle-plugin:2.5.13'
        classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
        //classpath 'com.google.dagger:hilt-android-gradle-plugin:2.45'
        classpath "org.jetbrains.kotlinx:kover-gradle-plugin:0.7.4"
    }
}
//plugins {
//    id 'com.android.application' version '7.2.1' apply false
//    id 'com.android.library' version '7.2.1' apply false
//    id("org.jetbrains.kotlin.android") version "1.8.10" apply false
//}
allprojects {
    repositories {
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        mavenCentral {
            // We don't want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup "com.facebook.react"
            }
        }
        google()
        maven { url 'https://www.jitpack.io' }
        maven {
            url "https://maven.google.com"
        }
        google()
        mavenCentral()
        exclusiveContent {
            filter {
                includeGroup "com.facebook.react"
            }
            forRepository {
                maven {
                    url "$rootDir/../node_modules/react-native/android"
                }
            }
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Steps to reproduce

./gradlew assembleDebug --stacktrace

Affected Platforms

Runtime - Android

Output of npx react-native info

System:
    OS: macOS 13.6.1
    CPU: (8) arm64 Apple M1
    Memory: 75.98 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.5.0 - ~/.nvm/versions/node/v16.5.0/bin/node
    Yarn: Not Found
    npm: 7.19.1 - ~/.nvm/versions/node/v16.5.0/bin/npm
    Watchman: 2023.12.04.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.14.3 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK: Not Found
    Android SDK: Not Found
  IDEs:
    Android Studio: 2023.1 AI-231.9392.1.2311.11076708
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Java: 17.0.7 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.1.0 => 18.1.0 
    react-native: 0.70.14 => 0.70.14 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Stacktrace or Logs

Shopping/node_modules/react-native/react.gradle' line: 478

* What went wrong:
A problem occurred evaluating script.
> Cannot change resolution strategy of dependency configuration ':android-resource:_agp_internal_javaPreCompileDevDebugAndroidTest_kaptClasspath' after it has been resolved.
at build_1sfxsg77twu4oteqb.run(/Users/br/git/untitled folder 2/shopping/android/app/build.gradle:104)
at jdk.internal.reflect.GeneratedMethodAccessor184.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:484)
    at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:196)
    at org.gradle.internal.metaobject.CompositeDynamicObject.tryInvokeMethod(CompositeDynamicObject.java:98)
    at org.gradle.internal.extensibility.MixInClosurePropertiesAsMethodsDynamicObject.tryInvokeMethod(MixInClosurePropertiesAsMethodsDynamicObject.java:34)
    at org.gradle.internal.metaobject.ConfigureDelegate.invokeMethod(ConfigureDelegate.java:56)
    at react_c4wogo9jssh0xxy0fzbqkoczv$_run_closure9$_closure25$_closure26.doCall(/Users/brchinthalap/git/untitled folder 2/nativeShopping/node_modules/react-native/react.gradle:478)
    at jdk.internal.reflect.GeneratedMethodAccessor187.invoke(Unknown Source

Reproducer

don't have public repo

Screenshots and Videos

No response

github-actions[bot] commented 11 months ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
cortinico commented 10 months ago

We can't help without a reproducer + you're on version of React Native which is no longer supported.

cbr167 commented 10 months ago

I'm getting same error even with 0.71.0