【问题标题】:Debug and Release apk not working in React Native 0.63.3调试和发布 apk 在 React Native 0.63.3 中不起作用
【发布时间】:2021-05-27 17:01:39
【问题描述】:

我正在使用以下步骤来构建调试和发布 apk

  1. cd android && ./gradlew clean && cd ..
  2. cd android && ./gradlew cleanBuildCache && cd ..
  3. 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
  4. 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


【解决方案1】:

在项目目录的终端中:-

cd android
然后./gradlew clean
然后cd ..

然后
//创建包
npx 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/

然后
//创建调试版本
npx react-native run-android variant=debug

和
//创建发布版本
npx react-native run-android variant=release

注意:- 确保你已经在项目根目录中运行了npm start。

【讨论】:

  • 感谢 +1 的回答,我试过了。
猜你喜欢
  • 2019-07-30
  • 2016-12-23
  • 1970-01-01
  • 2017-04-07
  • 1970-01-01
  • 2017-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多