任务:react-native-async-storage_async-storage:generateDebugRFile失败

Pan*_*git 19 react-native

我在运行昨天运行良好的 React Native 应用程序时遇到问题。因此我运行了命令:

npx react-native run-android -- --warning-mode=all
Run Code Online (Sandbox Code Playgroud)

其中提供的信息开头为:

> Task :react-native-async-storage_async-storage:generateDebugRFile FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

FAILURE: Build failed with an exception.

...

* What went wrong:
Execution failed for task ':react-native-async-storage_async-storage:generateDebugRFile'.
> Could not resolve all files for configuration ':react-native-async-storage_async-storage:debugCompileClasspath'.
> Failed to transform react-native-0.71.0-rc.0-debug.aar (com.facebook.react:react-native:0.71.0-rc.0) to match attributes {artifactType=android-symbol-with-package-name, 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-api}.
  > Execution failed for JetifyTransform: C:\Users\pangi\.gradle\caches\modules-2\files-2.1\com.facebook.react\react-native\0.71.0-rc.0\7a7f5a0af6ebd8eb94f7e5f7495e9d9684b4f543\react-native-0.71.0-rc.0-debug.aar.
     > Java heap space
Run Code Online (Sandbox Code Playgroud)

我的第一个问题是如何解决这个问题?我似乎无法在互联网上找到此特定问题的解决方案。显然它与“异步存储”包有关,我确实更新了它,但这并没有解决问题。

据说使用“--warning-mode=all”措辞应该提供指向 Gradle 的链接来帮助解决问题......但是我没有看到任何链接。我还注意到输出中提到了“react-native-0.71”,但是我使用的是较低版本......不确定这是否与该问题有关。任何建议表示赞赏。

我的第二个问题更为普遍。为什么 React Native 中不断发生这样无意义和可笑的事情?如前所述,上次启动时代码运行良好。我无法对我的代码(或最小的代码)进行任何更改,突然代码被破坏并且无法运行......这不是我自己的错,而是与某些 npm 包或其他一些原因(例如 Gradle)有关与我无关。我从未见过,也没有想象过……如此不可靠且“漏洞百出”的软件可以向公众发布。为什么 React Native 中不断出现这样的问题?这只是无能还是有更好的答案?由于这些做法给我带来了这个特定平台的问题,我总是面临着无休止的沮丧和愤怒。如果有人能够解释为什么这个开发“环境”充满了这些问题,我将不胜感激。

Tha*_*P A 47

由于 React Native 版本的发布,Android 将会出现构建失败的情况0.71.0-rc0

将此修复添加到您的android -> build.gradle文件中,如下所示:

buildscript {
    // ...
}


allprojects {
    repositories {
       exclusiveContent {
           filter {
               includeGroup "com.facebook.react"
           }
           forRepository {
               maven {
                   url "$rootDir/../node_modules/react-native/android"
               }
           }
       }
        // ...
    }
}
Run Code Online (Sandbox Code Playgroud)

此修复将应用一项exclusiveContent解析规则,强制解析 React Native Android 库,以使用其中的解析规则node_modules

如果上述方法不能解决您的问题,请尝试此处提到的方法 2:React Native Android 构建失败,并出现不同的错误,由于 React Native 版本 0.71.0-rc.0 的发布,过去几天代码没有任何更改


小智 18

OP 看起来很生气,说实话,我确实理解他为什么生气,但我怀疑为什么他不应该这样做。我已经两天没有运行构建了,直到昨天,即 11 月 5 日,当我运行 npx react-native run-android 时,注意到了这个错误。我花了近 24 小时寻找解决方案,直到偶然发现这个问题。

根据 @Thanhal 的这个修复对我有用。

我调整了 android/build.gradle。这是我的 gradle 文件和修复的完整内容。

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

buildscript {

    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "21.4.7075529"
        kotlinVersion = '1.6.0'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {

        // ------ Fix starts here

        exclusiveContent {
           filter {
               includeGroup "com.facebook.react"
           }
           forRepository {
               maven {
                   url "$rootDir/../node_modules/react-native/android"
               }
           }
       }
       
       // --------- Fix ends here

       
        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' }
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望这也能帮助那里的人。


归档时间:

查看次数:

31940 次

最近记录:

1 年,10 月 前