Native React - VS Studio Code - npm run android - 任务“:app:checkDebugAarMetadata”执行失败

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

尝试在我的本机 React 项目上运行 npm android build 时遇到此错误。我已经完成了整个 Android 设置以及更新环境变量。模拟器可以工作,但安装失败并显示以下消息:

     What went wrong:                                                                                                                                    
Execution failed for task ':app:checkDebugAarMetadata'.                                                                                               
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform react-android-0.72.6-debug.aar (com.facebook.react:react-android:0.72.6) to match attributes {artifactType=android-aar-metadata, com.android.build.api.attributes.BuildTypeAttr=debug, 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 JetifyTransform: C:\Users\BenTo\.gradle\caches\modules-2\files-2.1\com.facebook.react\react-android\0.72.6\2e2db118c9084b05c1a5d6079148bc983668f372\react-android-0.72.6-debug.aar.

build.gradle如下:

buildscript {
ext {
    buildToolsVersion = "33.0.0"
    minSdkVersion = 21
    compileSdkVersion = 33
    targetSdkVersion = 33

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

}

我还运行了react doctor,它显示以下内容:

    Android
 ✓ Adb - Required to verify if the android device is attached correctly
 ✓ JDK - Required to compile Java code
 ✓ Android Studio - Required for building and installing your app on Android
 ✖ Android SDK - Required for building and installing your app on Android
   - Versions found: N/A
   - Version supported: 33.0.0
 ✓ ANDROID_HOME - Environment variable that points to your Android SDK installation

Errors:   1
Warnings: 0

Usage
 › Press f to try to fix issues.
 › Press e to try to fix errors.
 › Press w to try to fix warnings.
 › Press Enter to exit.

当我按 e 解决时,它显示问题已修复并重新启动。当我重新启动时,我收到同样的错误。

请帮忙。

react-native android-studio visual-studio-code android-emulator react-native-cli
1个回答
0
投票

尝试在android studio设置中检查SDK版本,点击SDK Manager,然后点击SDK工具,然后点击显示包详细信息并检查是否勾选了android开发所需的33.0.0,并且在开发中提到了33.0.0 React Native 的环境设置也是如此。

链接 - https://reactnative.dev/docs/environment-setup

也只需几步

  1. 在项目的 android 文件夹中运行 ./gradlew clean,然后运行 ./gradlew assembleDebug 以清理 gradle 缓存
  2. 现在运行 ./gradlew build 来构建 android 文件夹,如果成功,您应该能够运行该项目。
© www.soinside.com 2019 - 2024. All rights reserved.