【问题标题】:When I try to build for production this error comes up当我尝试构建生产时出现此错误
【发布时间】:2023-01-17 10:12:32
【问题描述】:

当我尝试构建生产环境时,会出现此错误。我正在使用 React Native Firebase。这个错误发生在安卓上。

这是错误

* What went wrong:
Execution failed for task ':react-native-firebase_app:generateReleaseRFile'.
> Could not resolve all files for configuration ':react-native-firebase_app:releaseCompileClasspath'.
   > Failed to transform react-native-0.71.0-rc.0-release.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=release, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-api}.
      > Could not find react-native-0.71.0-rc.0-release.aar (com.facebook.react:react-native:0.71.0-rc.0).
        Searched in the following locations:
            https://repo.maven.apache.org/maven2/com/facebook/react/react-native/0.71.0-rc.0/react-native-0.71.0-rc.0-release.aar

这是我的包裹

[tag:    "@react-native-async-storage/async-storage": "^1.17.10",
    "@react-native-firebase/analytics": "^16.4.3",
    "@react-native-firebase/app": "^16.4.3",
    "@react-navigation/bottom-tabs": "^6.4.0",
    "@react-navigation/native": "^6.0.13",
    "@react-navigation/native-stack": "^6.9.1",
    "@rneui/base": "^4.0.0-rc.7",
    "@rneui/themed": "^4.0.0-rc.7",
    "meilisearch": "^0.29.1",
    "native-base": "^3.4.21",
    "picomatch": "^2.3.1",
    "react": "18.1.0",
    "react-native": "0.70.3",
    "react-native-firebase": "^5.6.0",
    "react-native-google-mobile-ads": "^8.2.1",
    "react-native-navigation-bar-color": "^2.0.1",
    "react-native-safe-area-context": "^4.4.1",
    "react-native-screens": "^3.18.2",
    "react-native-svg": "^13.5.0",
    "react-native-vector-icons": "^9.2.0"]

如果能帮忙,谢谢!

我已经尝试了所有我能在网上找到的东西 =(

我也试过npx jetify

【问题讨论】:

标签: react-native react-native-firebase


【解决方案1】:

尝试这个

将这些行添加到 android/build.gradle 文件中

allprojects {
    repositories {
        google()

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

【讨论】:

    【解决方案2】:

    这是 React Native 的一个错误,已发布修复程序。检查https://github.com/facebook/react-native/issues/35210

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生变化,仅链接答案可能会失效。
    • 在这个问题上浪费了一整天。最后,只有一次,我实际上并没有因为错误而过错 lmao
    【解决方案3】:

    正如第一个答案所说,这是 Maven Central 中的问题,而 React-Native 在这里解决了这个问题https://github.com/facebook/react-native/issues/35210.... 在 package.json 文件中 通过替换此行来更新 react-native

     "react-native": "0.70.5"
    

    然后 npm 安装

    【讨论】:

      【解决方案4】:

      确保 app/build.gradle 中的 react-native 版本与 package.json 中的版本相匹配:

      应用程序/build.gradle

      implementation "com.facebook.react:react-native:0.70.+"
      

      包.json

      "react-native": "0.70.5"
      

      这对我有用

      【讨论】:

        最近更新 更多