React native(android) assembleRelease 获取捆绑组装错误
Posted
技术标签:
【中文标题】React native(android) assembleRelease 获取捆绑组装错误【英文标题】:React native(android) assembleRelease gets bundle assembling error 【发布时间】:2020-04-22 18:26:17 【问题描述】:
"version": "0.0.1",
"private": true,
"scripts":
"android": "react-native run-android",
"start": "node node_modules/react-native/local-cli/cli.js start",
"load-script": "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",
"test": "jest"
,
"dependencies":
"@react-native-community/async-storage": "1.7.1",
"axios": "^0.18.0",
"native-base": "^2.12.1",
"prop-types": "^15.7.2",
"react": "16.8.3",
"react-native": "0.59.5",
"react-native-extended-stylesheet": "^0.11.1",
"react-native-gesture-handler": "1.4.0",
"react-native-image-slider": "^2.0.3",
"react-native-linear-gradient": "^2.5.6",
"react-native-snap-carousel": "^3.8.4",
"react-navigation": "^3.11.1",
"react-redux": "^7.1.3",
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-persist": "^5.10.0",
"redux-thunk": "^2.3.0"
,
"devDependencies":
"@babel/core": "7.4.4",
"@babel/runtime": "7.4.4",
"babel-jest": "24.7.1",
"eslint-config-rallycoding": "^3.2.0",
"jest": "24.7.1",
"jetifier": "^1.6.5",
"metro-react-native-babel-preset": "0.54.0",
"react-test-renderer": "16.8.3",
"redux-devtools": "^3.5.0",
"remote-redux-devtools": "^0.5.0"
,
"jest":
"preset": "react-native"
//build.gradle android
buildscript
ext
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
我运行了 .\gradlew assembleRelease,然后它崩溃了,然后我用 --info 运行了相同的命令,这就是它向我展示的内容 我已经尝试升级和降级并删除一些未使用的库,但没有任何改变。
> Task :app:bundleReleaseJsAndAssets
Caching disabled for task ':app:bundleReleaseJsAndAssets' because:
Build cache is disabled
Task ':app:bundleReleaseJsAndAssets' is not up-to-date because:
Task has failed previously.
Starting process 'command 'cmd''. Working directory: C:\Users\MOBILE1\Desktop\Gitlab-Devloper-Branch\dev-branch\build-apk-error-last\mbz-mobile-app Command: cmd /c node node_modules/react-native/cli.js bundle --platform android --dev false --reset-cache --entry-file index.android.js --bundle-output C:\Users\MOBILE1\Desktop\Gitlab-Devloper-Branch\dev-branch\build-apk-error-last\mbz-mobile-app\android\app\build\generated\assets\react\release\index.android.bundle --assets-dest C:\Users\MOBILE1\Desktop\Gitlab-Devloper-Branch\dev-branch\build-apk-error-last\mbz-mobile-app\android\app\build\generated\res\react\release
Successfully started process 'command 'cmd''
warning: the transform cache was reset.
error The resource `C:\Users\MOBILE1\Desktop\Gitlab-Devloper-Branch\dev-branch\build-apk-error-last\mbz-mobile-app\index.android.js` was not found.. Run CLI with --verbose flag for more details.
> Task :app:bundleReleaseJsAndAssets FAILED
:app:bundleReleaseJsAndAssets (Thread[Execution worker for ':' Thread 6,5,main]) completed. Took 3.955 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
我还发现使用或覆盖了已弃用的 API 和 使用了已弃用的 Gradle 功能,使其与 react-native-gesture-handler 的 Gradle 6.0 不兼容 在安卓工作室。我明白了
【问题讨论】:
【参考方案1】:尝试一次,./gradlew assembleRelease -x bundleReleaseJsAndAssets
请检查一次。
更新:
gradlew assembleRelease
只会构建/捆绑您的应用程序以进行生产。您需要自己对 APK 文件进行签名。
当我想在生产模式下运行我的应用程序时,我会采取以下步骤:
1.keytool -genkey -v -keystore key.keystore -alias app-alias -keyalg RSA -keysize 2048 -validity 10000
2.cd android && gradlew assembleRelease && cd ..
3.jarsigner -verbose -keystore \path_to_key\key.keystore \path_to_apk\app-release-unsigned.apk app-alias
4.zipalign -f -v 4 \path_to_apk\app-release-unsigned.apk appName.apk
按照这些步骤操作,您的应用应该会成功安装。
如有任何疑问,请恢复。
【讨论】:
它构建了app-release-unsigned并且无法安装【参考方案2】:请使用与主应用程序项目相同的 compileSdkVersion、buildToolsVersion 和支持库项目。
【讨论】:
以上是关于React native(android) assembleRelease 获取捆绑组装错误的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 react-native-camera 从相机胶卷 url 显示图像?
React Native Android - 第一次运行 react-native run-android 时出错
React Native - 在 Android 上构建 react-native-camera 错误
使用 react-native run-android 运行时出现 React-Native 错误
react-native run-android上的React Native错误
解决 React-Native: Android project not found. Maybe run react-native android first?