React Native 错误:构建 APK 时任务:app:bundleDebugJsAndAssets FAILED

Posted

技术标签:

【中文标题】React Native 错误:构建 APK 时任务:app:bundleDebugJsAndAssets FAILED【英文标题】:React Native Error: Task :app:bundleDebugJsAndAssets FAILED when building APK 【发布时间】:2021-09-21 03:43:01 【问题描述】:

我正在尝试使用以下方式将我的 React Native 项目导出到 APK 文件:

./gradlew 组装

并收到以下错误:

任务:app:bundleDebugJsAndAssets 失败

这是我在执行时的警告输出。是否存在可能贬值的依赖项?我似乎无法确定为什么我无法构建所需的 APK 文件。

我不确定是否需要降级我的 gradle 以实现 Firebase 兼容性。

Configure project :app
useNewCruncher has been deprecated. It will be removed in a future version of the gradle plugin. New cruncher is now always enabled.

> Configure project :react-native-app-install-date
Adding a Configuration as a dependency is a confusing behavior which isn't recommended. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. If you're interested in inheriting the dependencies from the Configuration you are adding, you should use Configuration#extendsFrom instead. See https://docs.gradle.org/6.7/dsl/org.gradle.api.artifacts.Configuration.html#org.gradle.api.artifacts.Configuration:extendsFrom(org.gradle.api.artifacts.Configuration[]) for more details.

> Configure project :react-native-firebase
react-native-firebase: using React Native prebuilt binary from /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/react-native/android

> Configure project :react-native-firebase_app
:react-native-firebase_app package.json found at /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/@react-native-firebase/app/package.json
:react-native-firebase_app:firebase.bom using default value: 28.0.1
:react-native-firebase_app:play.play-services-auth using default value: 19.0.0
:react-native-firebase_app package.json found at /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/@react-native-firebase/app/package.json
:react-native-firebase_app:version set from package.json: 12.0.0 (12,0,0 - 12000000)
:react-native-firebase_app:android.compileSdk using custom value: 29
:react-native-firebase_app:android.targetSdk using custom value: 29
:react-native-firebase_app:android.minSdk using custom value: 21
:react-native-firebase_app:reactNativeAndroidDir /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/react-native/android

> Configure project :react-native-firebase_auth
:react-native-firebase_auth package.json found at /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/@react-native-firebase/auth/package.json
:react-native-firebase_app package.json found at /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/@react-native-firebase/app/package.json
:react-native-firebase_auth:firebase.bom using default value: 28.0.1
:react-native-firebase_auth package.json found at /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/@react-native-firebase/auth/package.json
:react-native-firebase_auth:version set from package.json: 12.0.0 (12,0,0 - 12000000)
:react-native-firebase_auth:android.compileSdk using custom value: 29
:react-native-firebase_auth:android.targetSdk using custom value: 29
:react-native-firebase_auth:android.minSdk using custom value: 21
:react-native-firebase_auth:reactNativeAndroidDir /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/react-native/android

> Task :app:bundleDebugJsAndAssets
warning: the transform cache was reset.
                    Welcome to Metro!
              Fast - Scalable - Integrated


Error: While trying to resolve module `expo` from file `/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/index.js`, the package `/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/expo/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/expo/index.js`. Indeed, none of these files exist:

  * /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/expo/index.js(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
error While trying to resolve module `expo` from file `/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/index.js`, the package `/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/expo/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/expo/index.js`. Indeed, none of these files exist:
  * /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/expo/index.js/index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
    at DependencyGraph.resolveDependency (/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/metro/src/node-haste/DependencyGraph.js:436:17)
    at Object.resolve (/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/metro/src/lib/transformHelpers.js:317:42)
    at resolve (/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/metro/src/DeltaBundler/traverseDependencies.js:629:33)
    at /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/metro/src/DeltaBundler/traverseDependencies.js:645:26
    at Array.reduce (<anonymous>)
    at resolveDependencies (/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/metro/src/DeltaBundler/traverseDependencies.js:644:33)
    at /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/metro/src/DeltaBundler/traverseDependencies.js:329:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/metro/src/DeltaBundler/traverseDependencies.js:137:24)
    at _next (/Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/metro/src/DeltaBundler/traverseDependencies.js:159:9)

info Run CLI with --verbose flag for more details.
  * /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/expo/index.js(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  * /Users/mattlaszcz/Desktop/HearthNative_2/HearthNative_2/node_modules/expo/index.js/index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx).

依赖关系:

buildscript 
    ext 
        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 29
        targetSdkVersion = 29
        ndkVersion = "20.1.5948944"
    
    repositories 
        google()
        jcenter()
    
    dependencies 
        classpath("com.android.tools.build:gradle:4.1.0")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    

【问题讨论】:

【参考方案1】:

由于我使用的是 Expo: expo build:android 控制台中的命令,因此我可以导出 apk 文件。

【讨论】:

以上是关于React Native 错误:构建 APK 时任务:app:bundleDebugJsAndAssets FAILED的主要内容,如果未能解决你的问题,请参考以下文章

如何从我的 react-native 项目构建 android apk?

从 React Native 应用程序生成 Apk,JDK 错误

无法在 react native expo 项目中构建 android apk

google 登录崩溃 Apk(React Native)

React-Native build release apk 执行 aapt 失败

react-native打包apk常见错误收集