簡體   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