当我运行./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文件夹。
答案 0 :(得分:23)
第一:
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
答案 1 :(得分:4)
看起来你还没有制作一个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
试试这个。 希望它会对你有所帮助。
答案 2 :(得分:3)
我现在已经晚了。也许这会帮助别人。
对我来说,我必须升级到最新的react-native-sentry
。
apply from: "../../node_modules/react-native-sentry/sentry.gradle"
引起问题
答案 3 :(得分:3)
我遇到了同样的问题,解决方法是:
cd
到 yourApp / android 文件夹
运行此
./gradlew --stop
然后
./gradlew assembleRelease
这将建立您的应用程序。
构建完成后,去查看您的应用程序(apk)。
android \ app \ build \ outputs \ apk \ release
答案 4 :(得分:2)
这对我有用,请按照以下步骤操作:-
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应用程序构建版本
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 /并删除“ node”文件,然后再次执行步骤-4。
6)如果步骤-4成功运行,则此节点问题将得到解决。
答案 5 :(得分:1)
上述步骤确实有帮助。
以下是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"
}
答案 6 :(得分:1)
仅使用./gradlew --stop
然后使用./gradlew assembleRelease
对我有用。
答案 7 :(得分:1)
我这样做是可行的,
rm -rf node_modules
来完成)npm installl
或yarn install
./gradlew clean
&& ./gradlew app:assembleRelease
或./gradlew app:assembleDebug
答案 8 :(得分:0)
我使用了错误的图像尺寸(即image@5x.png),这导致了我这个问题。当我删除那个image@5x.png文件时...起作用了!
答案 9 :(得分:0)
从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
注意:我们添加了--max-workers 1
并不会耗尽CI资源,因为它们仅限于较小的数字(mem&cpu)。
答案 10 :(得分:0)
对我来说,创建捆绑包失败,但是我注意到Sahin Elidemir的评论:
./ gradlew assembleRelease -x bundleReleaseJsAndAssets救了我。
这几乎对我有用。最后起作用的是(请注意app:
,对我而言,如果没有它,它会失败,而clean
则是很好的措施):
./gradlew clean app:assembleRelease -x bundleReleaseJsAndAssets
答案 11 :(得分:0)
我有同样的问题。就我而言,几个小时后,我在GitHub上看到了这一点:https://github.com/getsentry/sentry-react-native/issues/578#issuecomment-503428032。
我已在Sentry上将项目重命名。如果您重命名了项目,请更新android/sentry.properties
和ios/sentry.properties
文件。
defaults.url=https://sentry.io/
defaults.org=yourorg
defaults.project=newprojectname
auth.token=?
答案 12 :(得分:0)
考虑检查您所有的 JS(React 原生)。我遇到了这个问题,因为 JS 文件中有一个编码错误(React Native)。
答案 13 :(得分:0)
对我来说:
Windows
。cd android && gradlew --stop
然后是 gradlew assembleRelease
。答案 14 :(得分:0)
如果你在 VS 代码中运行这些命令, 只需在android文件夹中以cmd(管理员模式)打开项目运行 $ gradlew 干净 $ gradlew assembleRelease