【问题标题】:React-Native assembleRelease fails for task ':app:bundleReleaseJsAndAssets'任务':app:bundleReleaseJsAndAssets'的React-Native assembleRelease失败
【发布时间】:2018-09-05 20:55:48
【问题描述】:

当我运行 ./gradlew assembleRelease 时,构建失败并出现此错误:

Error:Execution failed for task ':app:bundleReleaseJsAndAssets. 
> A problem occurred starting process 'command 'node'

我在网上搜索了一些关于它的主题,但我无法解决我的问题。

React-Native 版本:0.54.0

编辑:
现在我从终端而不是 Android Studio 运行 ./gradlew assembleRelease --info,我得到了不同的错误。
这是结果:

> Task :app:processReleaseResources
Putting task artifact state for task ':app:processReleaseResources' into context took 0.007 secs.
file or directory '**/android/app/libs', not found
file or directory '**/node_modules/appcenter-crashes/android/libs', not found
file or directory '**/node_modules/appcenter-analytics/android/libs', not found
file or directory '**/node_modules/appcenter/android/libs', not found
file or directory '**/node_modules/react-native-interactable/lib/android/libs', not found
file or directory '**/node_modules/react-native-navigation/android/app/libs', not found
file or directory '**/android/app/libs', not found
file or directory '**/node_modules/appcenter-crashes/android/libs', not found
file or directory '**/appcenter-analytics/android/libs', not found
file or directory '**/node_modules/appcenter/android/libs', not found
file or directory '**/node_modules/react-native-interactable/lib/android/libs', not found
file or directory '**/node_modules/react-native-navigation/android/app/libs', not found
Executing task ':app:processReleaseResources' (up-to-date check took 0.035 secs) due to:
  Task has failed previously.
All input files are considered out-of-date for incremental task ':app:processReleaseResources'.
Unable do incremental execution: full task run
file or directory '**/android/app/libs', not found
file or directory '**/node_modules/appcenter-crashes/android/libs', not found
file or directory '**/node_modules/appcenter-analytics/android/libs', not found
file or directory '**/node_modules/appcenter/android/libs', not found
file or directory '**/node_modules/react-native-interactable/lib/android/libs', not found
file or directory '**/node_modules/react-native-navigation/android/app/libs', not found
file or directory '**/android/app/libs', not found
file or directory '**/node_modules/appcenter-crashes/android/libs', not found
file or directory '**/node_modules/appcenter-analytics/android/libs', not found
file or directory '**/node_modules/appcenter/android/libs', not found
file or directory '**/node_modules/react-native-interactable/lib/android/libs', not found
file or directory '**/node_modules/react-native-navigation/android/app/libs', not found
Aapt2QueuedResourceProcessor is using **/Android/sdk/build-tools/26.0.2/aapt2
Failed to execute aapt
com.android.ide.common.process.ProcessException: Failed to execute aapt
*
*
*
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processReleaseResources'.
> Failed to execute aapt


似乎 gradle 正在所有模块中寻找 libs 文件夹,但节点模块中没有 libs 文件夹。确实是这样,但是不知道gradle为什么要找libs文件夹。

【问题讨论】:

  • 您是否尝试将节点二进制文件所在的路径添加到 PATH 环境变量中?
  • @Ch4t4r 是的,我有
  • 然后运行./gradlew assembleRelease --debug--stacktrace。它显示了更详细的信息。
  • @Ch4t4r 谢谢。我刚刚用新结果编辑了问题

标签: javascript android react-native gradle


【解决方案1】:

看起来你还没有制作一个 js 包,所以请先使用命令制作一个包:-

 react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

然后在你的项目目录中

 cd android 

清理你的gradle

 ./gradlew clean

最后进行构建

./gradlew assembleDebug

试试这个。 希望对你有帮助。

【讨论】:

  • 这适用于构建调试,但 './gradlew assembleRelease' 仍然给我错误
【解决方案2】:

第一:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

最终构建:

./gradlew assembleRelease -x bundleReleaseJsAndAssets

【讨论】:

  • 当我在我的 cli 中运行它时,它正在成功构建,但 APK 未签名,当我尝试通过 Android Studio 对 APK 进行签名时,出现上述错误
  • 以上内容几乎对我有用,但是当我运行构建时,我得到:Task 'bundleReleaseJsAndAssets' not found in root project
  • 只是 ./gradlew assembleRelease -x bundleReleaseJsAndAssets 救了我。谢谢
  • 获取任务:react-native-firebase-analytics:verifyReleaseResources FAILED FAILURE:构建失败并出现异常。 * 出了什么问题:任务 ':react-native-firebase-analytics:verifyReleaseResources' 执行失败。
  • 如果您运行 Windows 10,请使用具有管理员权限的 cmd(无 git bash),确保您使用的是 @react-native-community/cli 的实际版本,即目录 android/app /src/main/assets 存在并使用 yarn react-native bundle 代替 react-native bundle
【解决方案3】:

上述步骤确实有帮助。

以下是适用于 react-native 0.55.3 的脚本。

在本地或 CI 运行 android-build 命令生成 APK。

/packages.json(反应原生):

"android-bundle": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res",
"android-release-fix": "node ./android-release-gradle-fix.js",
"android-build": "yarn killbin && yarn android-clean && yarn android-release-fix && yarn android-bundle && cd android && ./gradlew assembleRelease -x bundleReleaseJsAndAssets --info",
"android-clean": "cd android && ./gradlew clean",
"killbin": "rm -rf ./node_modules/.bin",

android-release-gradle-fix.js

const fs = require('fs')

// Fix issues with Android resources like duplicate files
// CI: run install with --unsafe-perm option
// https://stackoverflow.com/questions/47084810/react-native-android-duplicate-file-error-when-generating-apk
try {
        var curDir = __dirname
        var rootDir = process.cwd()

        var file = `${rootDir}/node_modules/react-native/react.gradle`
        var dataFix = fs.readFileSync(`${curDir}/android-react-gradle-fix`, 'utf8')
        var data = fs.readFileSync(file, 'utf8')

        var doLast = "doLast \{"
        if (data.indexOf(doLast) !== -1) {
            throw "Already fixed."
        }

        var result = data.replace(/                \/\/ Set up inputs and outputs so gradle can cache the result/g, dataFix);
        fs.writeFileSync(file, result, 'utf8')
        console.log('Done')
    } catch (error) {
        console.error(error)
    }

android-react-gradle-fix

doLast {
    def moveFunc = { resSuffix ->
        File originalDir = file("${resourcesDir}/drawable-${resSuffix}")
        if (originalDir.exists()) {
            File destDir = file("${resourcesDir}/drawable-${resSuffix}-v4")
            ant.move(file: originalDir, tofile: destDir)
        }
    }
    moveFunc.curry("ldpi").call()
    moveFunc.curry("mdpi").call()
    moveFunc.curry("hdpi").call()
    moveFunc.curry("xhdpi").call()
    moveFunc.curry("xxhdpi").call()
    moveFunc.curry("xxxhdpi").call()
}

// Set up inputs and outputs so gradle can cache the result

/android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 21
        compileSdkVersion = 27
        targetSdkVersion = 27
        supportLibVersion = "27.1.1"
        googlePlayServicesVersion = "15.0.1"
        androidMapsUtilsVersion = "0.5+"
    }
...
subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 27
                buildToolsVersion '27.0.3'
            }
        }
    }
}

/android/app/build.gradle

dependencies {
    implementation project(':amazon-cognito-identity-js')
    implementation project(':appcenter-push')
    implementation project(':react-native-fbsdk')
    implementation(project(':react-native-google-signin')) {
        exclude group: "com.google.android.gms" // very important
    }
    implementation project(':react-native-image-picker')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-sentry')
    implementation project(':react-native-maps')
    implementation "com.google.android.gms:play-services-auth:$googlePlayServicesVersion" // Google signin
    implementation project(':react-native-sentry')
    implementation(project(':react-native-maps')) {
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    implementation "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
    implementation "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"
    implementation "com.google.firebase:firebase-core:15.0.2"
    implementation "com.google.firebase:firebase-messaging:15.0.2"
    implementation project(':react-native-vector-icons')
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "com.android.support:appcompat-v7:$supportLibVersion"
    implementation 'com.facebook.react:react-native:+'
    // implementation "com.android.support:$supportLibVersion"
}

【讨论】:

    【解决方案4】:

    这对我有用,请按照以下步骤操作:-

    1) 停止运行 Gradle

     $ cd RectNatoveProjectName & cd android  (Open your project and go to android folder)  
     $ ./gradlew --stop (Run this command to stop old running Gradle service )
    

    2) 更新android app build gradle

    project.ext.react = [
            nodeExecutableAndArgs : ["/usr/local/bin/node"]
    ];
    

    3) 获取节点详情

    $ which node 
    

    >(结果类似于“/usr/username/.nvm/versions/node/v10.7.0/bin/node”)

    4) 链接节点(非常重要的一步复制上述步骤 3 中的结果)

    - ln -s /usr/username/.nvm/versions/node/v10.7.0/bin/node /usr/local/bin/node
    

    5) 如果 Step - 4 返回文件存在 - 然后去文件夹 /usr/local/bin/ 并删除“节点”文件并再次执行步骤-4。

    6) 如果步骤 - 4 运行成功,则此节点问题将得到解决。

    【讨论】:

      【解决方案5】:

      我使用了错误的图像尺寸(即 image@5x.png),这导致了我出现这个问题。当我删除那个 image@5x.png 文件时……它起作用了!!

      【讨论】:

        【解决方案6】:

        从 RN 0.58 开始,CI 构建的命令如下:

        首先创建目录:

        mkdir -p app/build/generated/assets/react/production/release/ && mkdir -p app/build/generated/res/react/production/release

        下一步:

        node ../node_modules/react-native/local-cli/cli.js bundle --platform android --dev false --entry-file index.android.js --bundle-output app/build/generated/assets/react/production/release/index.android.bundle --assets-dest app/build/generated/res/react/production/release --max-workers 1 --reset-cache

        此外,您可能还想根据this 为您的生产版本添加;

        --minify true

        取自RN's source

        注意:我们添加了 --max-workers 1 以不耗尽 CI 资源,因为它们仅限于较低的数字(内存和 cpu)。

        【讨论】:

          【解决方案7】:

          只使用./gradlew --stop 然后./gradlew assembleRelease 为我工作。

          【讨论】:

          • 您好 Behzad Fattahi,欢迎来到 StackOverflow!请使用代码格式,它更容易阅读:)
          【解决方案8】:

          我现在已经晚了。可能这会帮助某人。

          对我来说,我必须升级到最新的react-native-sentry

          apply from: "../../node_modules/react-native-sentry/sentry.gradle"
          

          导致问题

          【讨论】:

          【解决方案9】:

          对我来说,创建捆绑包失败了,但我注意到Sahin Elidemir 的评论:

          只是 ./gradlew assembleRelease -x bundleReleaseJsAndAssets 救了我。

          它几乎对我有用。最后起作用的是(注意app:,对我来说没有它就失败了,clean 很好衡量):

          ./gradlew clean app:assembleRelease -x bundleReleaseJsAndAssets
          

          【讨论】:

            【解决方案10】:

            我遇到了同样的问题,解决方法是:

            cdyourApp/android 文件夹

            运行这个

            ./gradlew --stop

            然后

            ./gradlew assembleRelease

            这将构建您的应用程序。

            构建完成后,去查看你的应用程序(apk)。

            android\app\build\outputs\apk\release

            【讨论】:

              【解决方案11】:

              我是这样做的,而且效果很好:

              • 删除了节点模块(你可以通过运行这个命令来做到这一点rm -rf node_modules
              • 运行npm installlyarn install
              • 然后运行./gradlew clean && ./gradlew app:assembleRelease./gradlew app:assembleDebug

              【讨论】:

              • 你的安装有 3 l
              • @punjabi4life 没看到?
              【解决方案12】:

              我遇到了同样的问题。就我而言,几个小时后,我在 GitHub 上看到了这个:https://github.com/getsentry/sentry-react-native/issues/578#issuecomment-503428032。 我在 Sentry 上重命名了该项目。如果您重命名了项目,请更新 android/sentry.propertiesios/sentry.properties 文件。

              defaults.url=https://sentry.io/
              defaults.org=yourorg
              defaults.project=newprojectname
              auth.token=?
              

              就是这样

              【讨论】:

                【解决方案13】:

                考虑检查所有 JS(React Native)。我遇到了这个问题,因为 JS 文件(React native)中有一个编码错误。

                【讨论】:

                  【解决方案14】:

                  对我来说:

                  • 操作系统:Windows
                  • 我刚刚将 .keystore 文件复制到了 android\app。
                  • cd android && gradlew --stop 然后gradlew assembleRelease

                  【讨论】:

                    【解决方案15】:

                    如果你在 VS 代码中运行这些命令, 只需在android文件夹运行的cmd(管理员模式)中打开项目 $ gradlew clean $ gradlew assembleRelease

                    【讨论】:

                      猜你喜欢
                      • 2022-06-14
                      • 2022-11-08
                      • 1970-01-01
                      • 2020-07-16
                      • 1970-01-01
                      • 2021-09-24
                      • 1970-01-01
                      • 2022-11-08
                      • 1970-01-01
                      相关资源
                      最近更新 更多