繁体   English   中英

React-Native assembleRelease 任务 ':app:bundleReleaseJsAndAssets' 失败

[英]React-Native assembleRelease fails for task ':app:bundleReleaseJsAndAssets'

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

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

我在 inte.net 上搜索并找到了一些关于它的主题,但我无法解决我的问题。

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文件夹。

首先:

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

看起来您还没有制作 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

试试这个。 希望它会帮助你。

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

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

它几乎对我有用。 最后有效的是(注意app: ,对我来说它失败了,并且clean了很好的措施):

./gradlew clean app:assembleRelease -x bundleReleaseJsAndAssets

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

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

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

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

造成问题

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

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) 如果步骤 - 4 返回文件存在- 则转到文件夹 /usr/local/bin/ 并删除“节点”文件并再次执行步骤 -4。

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

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

cdyourApp/android文件夹

运行这个

./gradlew --stop

然后

./gradlew assembleRelease

这将构建您的应用程序。

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

android\\app\\build\\outputs\\apk\\release

上面的步骤真的很有帮助。

这是对我们使用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"
}

我是这样做的,它有效:

  • 删除了节点模块(您可以通过运行此命令rm -rf node_modules
  • 运行npm installlyarn install
  • 然后运行./gradlew clean && ./gradlew app:assembleRelease./gradlew app:assembleDebug

如果您使用的是 macOS 并使用 react native,请尝试以下操作:

  1. brew install react-native-cli

  2. ./gradlew --stop

  3. ./gradlew clean

  4. ./gradlew aR./gradlew assembleRelease

当您将项目堆叠在许多文件夹中时,也会发生此错误

尝试将您的项目文件夹复制到您的一个硬盘驱动器中,而不将该项目放入任何文件夹中。

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

从 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

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

--minify true

取自RN的来源

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

尝试删除@ 3x以上的图像。 已删除@ 4x @ 5x,等等,因为Android不支持它们。 因此它无法构建。

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

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

就是这样

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

对我来说:

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

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

解决方案:

1- android\app\build.gradle

project.ext.react = [
    enableHermes: false, 
]

2-

cd android
gradlew clean

3- gradlew bundleRelease

检查您的项目以确保您没有在命名任何文件夹时使用空格。 对我来说,项目父文件夹的名称中有一个空格。 当我删除空格(从Source Codescodes )时,我的构建成功了。

就我而言

由于父目录名称中有空格,npx 无法go进入正确的目录

例子:-

D:\dk\native\aiims raipur\aiimsraipur

从目录中删除空间 -> aiims raipuraiims_raipur

构建工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM