从33升级到34后,无法转换appcompat-resources-1.7.0.aar React Native(android)

问题描述 投票:0回答:1

从 33 升级到 34 后,我在尝试构建时遇到此问题:

BUILD FAILED in 4m 27s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeExtDexDevelopmentDebug'.
> Could not resolve all files for configuration ':app:developmentDebugRuntimeClasspath'.
   > Failed to transform appcompat-resources-1.7.0.aar (androidx.appcompat:appcompat-resources:1.7.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingNoClasspathTransform: /Users/niltonsf/.gradle/caches/transforms-3/a07d39668226bbd09c1d6dde810edac8/transformed/jetified-appcompat-resources-1.7.0-runtime.jar.
         > Error while dexing.
   > Failed to transform appcompat-1.7.0.aar (androidx.appcompat:appcompat:1.7.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingNoClasspathTransform: /Users/niltonsf/.gradle/caches/transforms-3/63c934ac88a350488897afd33f8937a0/transformed/appcompat-1.7.0-runtime.jar.
         > Error while dexing.


2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)

这是我的

build.gradlew
已经尝试将构建工具更改为34。:

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

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 24
        compileSdkVersion = 34
        targetSdkVersion = 34
        kotlinVersion = "1.8.22"

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "25.1.8937393"
    }
    repositories {
        google()
        mavenCentral()             
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("com.google.gms:google-services:4.4.1")
    }
}

我的

package.json

{
  "name": "",
  "version": "2.3.0",
  "private": true,
  "scripts": {
    "android": "react-native run-android --variant=developmentDebug --appIdSuffix=dev",
    "android:prod": "react-native run-android --variant=productionRelease",
    "android:dev:debug": "cd ./android && (gradlew clean assembleDevelopmentDebug || ./gradlew clean assembleDevelopmentDebug)",
    "android:dev:release": "cd ./android && (gradlew clean assembleDevelopmentRelease || ./gradlew clean assembleDevelopmentRelease)",
    "android:prod:debug": "cd ./android && (gradlew clean assembleProductionDebug || ./gradlew clean assembleProductionDebug)",
    "android:prod:release": "cd ./android && (gradlew clean assembleProductionRelease || ./gradlew clean assembleProductionRelease)",
    "android:publish": "cd ./android && ./gradlew bundleProductionRelease",
    "ios": "react-native run-ios --scheme 'StagingDebug' --simulator='iPhone 14'",
    "ios:prod": "react-native run-ios --scheme 'Production' --simulator='iPhone 14'",
    "start": "react-native start --reset-cache",
    "postinstall": "patch-package",
    "version": "react-native-version --never-amend"
  },
  "dependencies": {
    "@gorhom/bottom-sheet": "^4",
    "@hookform/resolvers": "^2.9.10",    
    "@intercom/intercom-react-native": "^4.0.1",
    "@nozbe/watermelondb": "^0.25.5",
    "@react-native-async-storage/async-storage": "^1.17.11",
    "@react-native-community/datetimepicker": "^7.6.2",
    "@react-native-community/netinfo": "^9.3.7",
    "@react-navigation/bottom-tabs": "^6.5.3",
    "@react-navigation/drawer": "^6.6.6",
    "@react-navigation/native": "^6.1.2",
    "@react-navigation/native-stack": "^6.9.8",
    "@react-navigation/stack": "^6.3.11",
    "@tanstack/react-query": "^4.24.4",
    "@uidotdev/usehooks": "^2.4.1",
    "axios": "^1.2.3",
    "buffer": "^6.0.3",
    "chroma-js": "^2.4.2",
    "dayjs": "^1.11.9",
    "deprecated-react-native-prop-types": "^4.0.0",
    "i18next": "^22.4.9",
    "lodash": "^4.17.21",
    "mime": "^4.0.1",
    "patch-package": "^6.5.1",
    "react": "18.2.0",
    "react-hook-form": "^7.45.2",
    "react-i18next": "^12.1.4",
    "react-native": "0.71.1",
    "react-native-blob-util": "^0.17.1",
    "react-native-camera": "^4.2.1",
    "react-native-config": "^1.5.1",
    "react-native-crisp-chat-sdk": "^0.14.4",
    "react-native-device-info": "^10.3.0",
    "react-native-document-picker": "^8.1.3",
    "react-native-drawer-layout": "^4.0.0-alpha.1",
    "react-native-element-dropdown": "^2.5.3",
    "react-native-fast-image": "^8.6.3",
    "react-native-file-viewer": "^2.1.5",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^2.9.0",
    "react-native-image-crop-picker": "^0.39.0",
    "react-native-image-picker": "^7.1.0",
    "react-native-images-to-pdf": "^0.2.1",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-mask-input": "^1.2.3",
    "react-native-mmkv": "^2.12.2",
    "react-native-pager-view": "^6.2.2",
    "react-native-permissions": "^3.6.1",
    "react-native-qrcode-scanner": "^1.5.5",
    "react-native-reanimated": "^3.3.0",
    "react-native-safe-area-context": "^4.5.0",
    "react-native-screens": "^3.34.0",
    "react-native-status-bar-height": "^2.6.0",
    "react-native-svg": "^13.8.0",
    "react-native-tab-view": "^3.5.2",
    "react-native-tcp-socket": "^6.0.6",
    "react-native-toast-message": "^2.1.5",
    "react-native-vector-icons": "^9.2.0",
    "styled-components": "^5.1.6",
    "yup": "^0.32.11",
    "zustand": "^4.5.4"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/plugin-proposal-decorators": "^7.21.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.0.0",
    "@rocketseat/eslint-config": "^2.1.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/chroma-js": "^2.4.2",
    "@types/jest": "^29.2.1",
    "@types/node": "^20.5.9",
    "@types/react": "^18.0.24",
    "@types/react-native-doc-viewer": "^2.7.2",
    "@types/react-native-vector-icons": "^6.4.13",
    "@types/react-test-renderer": "^18.0.0",
    "@types/styled-components": "^5.1.26",
    "@types/styled-components-react-native": "^5.1.6",
    "@typescript-eslint/eslint-plugin": "^5.54.1",
    "@typescript-eslint/parser": "^5.54.1",
    "babel-jest": "^29.2.1",
    "babel-plugin-root-import": "^6.6.0",
    "customize-cra": "^1.0.0",
    "eslint": "^8.47.0",
    "eslint-plugin-unused-imports": "^3.0.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.7",
    "prettier": "^2.4.1",
    "react-app-rewired": "^2.2.1",
    "react-native-svg-transformer": "^1.0.0",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "jest": {
    "preset": "react-native"
  }
}
android react-native gradle build
1个回答
0
投票

我最近遇到了一个类似的问题,并且能够通过使用

force
(对于旧版本的 gradle)或
strictly
(对于新版本的 gradle)专门控制依赖关系来修复。我还添加了导致问题的依赖项的特定版本。

  1. 对于旧版本的 gradle < 8
   implementation('androidx.lifecycle:lifecycle-livedata-core:2.2.0') {
     force = true
   }
   implementation('androidx.appcompat:appcompat:1.6.1') {
     force = true
   }
  1. 对于较新版本的 gradle > 8
  implementation('androidx.lifecycle:lifecycle-livedata-core:2.2.0') {
    version {
      strictly '2.2.0'
    }
  }
  implementation('androidx.appcompat:appcompat:1.6.1') {
    version {
      strictly '1.6.1'
    }
  }
© www.soinside.com 2019 - 2024. All rights reserved.