【发布时间】:2021-05-27 17:01:39
【问题描述】:
我正在使用以下步骤来构建调试和发布 apk
- cd android && ./gradlew clean && cd ..
- cd android && ./gradlew cleanBuildCache && cd ..
- npx react-native bundle --platform android --dev true --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android /app/src/main/res --verbose
- cd android && ./gradlew assembleDebug && cd .. 或 cd android && ./gradlew assembleRelease && cd ..
apk 生成成功。但是当我运行它们时,我总是得到这个。
但是,如果我启动 Metro-server,应用程序可以正常工作,但 debug-apk 不能。
任何帮助将不胜感激。
安卓配置:
buildToolsVersion = "29.0.2"
minSdkVersion = 23
compileSdkVersion = 29
targetSdkVersion = 29
classpath 'com.google.gms:google-services:4.1.0'
清单
<application
android:name=".MainApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
>
应用的 build.gradle
project.ext.react = [
entryFile: "index.js",
bundleAssetName: "index.android.bundle",
enableHermes: false, // clean and rebuild if changing
devDisabledInDev: true, // Disable dev server in dev release
bundleInDev: true, // add
bundleInDebug: true
]
谢谢
【问题讨论】:
-
在主终端的项目目录中运行
npx react-native start或在运行npx react-native start后在 VS 中运行npm react-native run-android。 -
我也试过了,但是当我生成构建并安装该 apk 文件时,我得到了同样的错误。
-
如果您在模拟器上运行应用程序,请尝试
react-native run-android --variant=debug -
我能够成功生成构建,问题是当我从存储安装它时,它给了我这个错误。
标签: android reactjs react-native apk