[英]React-Native assembleRelease fails for task ':app:bundleReleaseJsAndAssets'
When I run ./gradlew assembleRelease
build is failed with this error:当我运行
./gradlew assembleRelease
build 失败并出现此错误时:
Error:Execution failed for task ':app:bundleReleaseJsAndAssets. > A problem occurred starting process 'command 'node'
I searched on the inte.net and found some topics about it, but I couldn't solve my problem.我在 inte.net 上搜索并找到了一些关于它的主题,但我无法解决我的问题。
React-Native version: 0.54.0 React-Native 版本:0.54.0
EDIT:编辑:
Now I'm running ./gradlew assembleRelease --info
from the terminal instead of Android Studio and I get different error.现在我正在从终端而不是 Android Studio 运行
./gradlew assembleRelease --info
,我得到了不同的错误。
Here is the result:这是结果:
> 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
It seems gradle is looking for libs folder in all modules, but there are no libs folders in the node modules.似乎 gradle 在所有模块中寻找 libs 文件夹,但节点模块中没有 libs 文件夹。 It's true, but I don't know why gradle is looking for libs folder.
没错,就是不知道gradle为什么要找libs文件夹。
First:首先:
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
finally build:最后构建:
./gradlew assembleRelease -x bundleReleaseJsAndAssets
Looks like you haven't made a js bundle so please make a bundle first by using command :-看起来您还没有制作 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
then in your project directory然后在你的项目目录中
cd android
Clean your gradle清理你的gradle
./gradlew clean
and make a build finally并最终进行构建
./gradlew assembleDebug
Try this.试试这个。 Hope it will helps you.
希望它会帮助你。
For me the creating the bundle failed, but I noticed this comment by Sahin Elidemir :对我来说,创建包失败了,但我注意到Sahin Elidemir 的这条评论:
just ./gradlew assembleRelease -x bundleReleaseJsAndAssets saved me.
只是 ./gradlew assembleRelease -x bundleReleaseJsAndAssets 救了我。
It almost worked for me.它几乎对我有用。 What worked at the end was (notice the
app:
, which for me it fails without, and a clean
for good measure):最后有效的是(注意
app:
,对我来说它失败了,并且clean
了很好的措施):
./gradlew clean app:assembleRelease -x bundleReleaseJsAndAssets
只需使用./gradlew --stop
然后./gradlew assembleRelease
为我工作。
I now this is late.我现在已经晚了。 may be this will help somebody.
可能这会帮助某人。
For me it i had to upgrade to latest react-native-sentry
.对我来说,我必须升级到最新的
react-native-sentry
。
apply from: "../../node_modules/react-native-sentry/sentry.gradle"
was causing problem造成问题
This is working for me, Please follow the below steps:-
这对我有用,请按照以下步骤操作:-
1) Stop Running 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) Update the android app build gradle 2) 更新android app build gradle
project.ext.react = [
nodeExecutableAndArgs : ["/usr/local/bin/node"]
];
3) Get Node details 3) 获取节点详情
$ which node
> (Result will be like "/usr/username/.nvm/versions/node/v10.7.0/bin/node") >(结果将类似于“/usr/username/.nvm/versions/node/v10.7.0/bin/node”)
4) Link node (very imp step copy the above result in step 3) 4)链接节点(非常重要的步骤复制步骤3中的上述结果)
- ln -s /usr/username/.nvm/versions/node/v10.7.0/bin/node /usr/local/bin/node
5) If Step - 4 return file exist - then to go the folder /usr/local/bin/ and delete the "node" file and perform the step -4 again. 5) 如果步骤 - 4 返回文件存在- 则转到文件夹 /usr/local/bin/ 并删除“节点”文件并再次执行步骤 -4。
6) If Step - 4 run successfully then this node issue will be resolved. 6) 如果步骤 - 4 运行成功,则此节点问题将得到解决。
I had the same problem, the solution was :我遇到了同样的问题,解决方案是:
cd
to yourApp/android folder cd
到yourApp/android文件夹
run this运行这个
./gradlew --stop
and then然后
./gradlew assembleRelease
This gonna build your app.这将构建您的应用程序。
After build is done, go to see your application(apk).构建完成后,去查看你的应用程序(apk)。
android\\app\\build\\outputs\\apk\\release android\\app\\build\\outputs\\apk\\release
The steps above really helped.上面的步骤真的很有帮助。
Here's the scripts that work for us with react-native 0.55.3
.这是对我们使用
react-native 0.55.3
。
Run the android-build
command locally or CI to generate an APK.在本地或 CI 运行
android-build
命令以生成 APK。
/packages.json (react-native): /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 : 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 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 : /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 : /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"
}
I did it like this and it works:我是这样做的,它有效:
rm -rf node_modules
)rm -rf node_modules
)npm installl
or yarn install
npm installl
或yarn install
./gradlew clean
&& ./gradlew app:assembleRelease
or ./gradlew app:assembleDebug
./gradlew clean
&& ./gradlew app:assembleRelease
或./gradlew app:assembleDebug
if you are using macOS and using react native try this:如果您使用的是 macOS 并使用 react native,请尝试以下操作:
brew install react-native-cli
./gradlew --stop
./gradlew clean
./gradlew aR
or ./gradlew assembleRelease
./gradlew aR
或./gradlew assembleRelease
This error also occurs when you have stacked your project inside many folders当您将项目堆叠在许多文件夹中时,也会发生此错误
Try copying your project folder into one of your hard drives without putting that project into any folder.尝试将您的项目文件夹复制到您的一个硬盘驱动器中,而不将该项目放入任何文件夹中。
I was using the wrong image size (ie image@5x.png) which caused me this problem.我使用了错误的图像大小(即 image@5x.png),这导致了我出现此问题。 When I deleted that image@5x.png file...it worked!!
当我删除那个 image@5x.png 文件时......它起作用了!!
As of RN 0.58, for CI builds the commands is as follows:从 RN 0.58 开始,对于 CI 构建命令如下:
First create directories:首先创建目录:
mkdir -p app/build/generated/assets/react/production/release/ && mkdir -p app/build/generated/res/react/production/release
Next:下一步:
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
Also you may also want to add for your production builds according to this ;此外,您可能还想根据此为您的生产版本添加;
--minify true
Taken from RN's source取自RN的来源
NOTE: We added --max-workers 1
not to deplete CI resources since they are limited to lower numbers (mem&cpu).注意:我们添加了
--max-workers 1
为了不耗尽 CI 资源,因为它们仅限于较低的数字 (mem&cpu)。
Try removing images above @3x. 尝试删除@ 3x以上的图像。 Removed @4x @5x, etc coz android does't support them.
已删除@ 4x @ 5x,等等,因为Android不支持它们。 so it fails the build.
因此它无法构建。
I had the same problem.我有同样的问题。 In my case, after a few hours, I saw this on GitHub: https://github.com/getsentry/sentry-react-native/issues/578#issuecomment-503428032 .
就我而言,几个小时后,我在 GitHub 上看到了这个: https : //github.com/getsentry/sentry-react-native/issues/578#issuecomment-503428032 。 I had renamed the project on Sentry.
我在 Sentry 上重命名了这个项目。 If you renamed the project on, update the
android/sentry.properties
and ios/sentry.properties
file.如果您将项目重命名为 on,请更新
android/sentry.properties
和ios/sentry.properties
文件。
defaults.url=https://sentry.io/
defaults.org=yourorg
defaults.project=newprojectname
auth.token=🔑
And that's it就是这样
Consider checking all your JS (React native).考虑检查你所有的 JS(React Native)。 I faced this issue coz have a coding error in the JS file (React native).
我遇到了这个问题,因为 JS 文件(React Native)中有一个编码错误。
For me:对我来说:
Windows
.Windows
。cd android && gradlew --stop
then gradlew assembleRelease
. cd android && gradlew --stop
然后gradlew assembleRelease
。如果您在 VS 代码中运行这些命令,只需在 android 文件夹中的 cmd(管理员模式)中打开项目 run $ gradlew clean $ gradlew assembleRelease
Solution:解决方案:
1- android\app\build.gradle
1-
android\app\build.gradle
project.ext.react = [
enableHermes: false,
]
2- 2-
cd android
gradlew clean
3- gradlew bundleRelease
3-
gradlew bundleRelease
Check your project to make sure that you didn't name any of your folders with spaces in between.检查您的项目以确保您没有在命名任何文件夹时使用空格。 For me, there was a space in the name of my project's parent folder.
对我来说,项目父文件夹的名称中有一个空格。 When I remove the space (from
Source Codes
to codes
) my build was successful.当我删除空格(从
Source Codes
到codes
)时,我的构建成功了。
In my case就我而言
npx was not able to go into the correct directory due to a space in the parent directory name由于父目录名称中有空格,npx 无法go进入正确的目录
example:-例子:-
D:\dk\native\aiims raipur\aiimsraipur
Removed space from directory -> aiims raipur to aiims_raipur从目录中删除空间 -> aiims raipur到aiims_raipur
Build works fine.构建工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.