Android 如何在react native中构建调试apk

Android 如何在react native中构建调试apk,android,reactjs,react-native,Android,Reactjs,React Native,我想构建未签名的apk或调试apk。我的应用程序正在本地主机上成功运行。我尝试过不同的方法。但它显示了错误。我已经从你那里得到了答案。应用命令时 react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-de

我想构建未签名的apk或调试apk。我的应用程序正在本地主机上成功运行。我尝试过不同的方法。但它显示了错误。我已经从你那里得到了答案。应用命令时

 react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug
它显示错误是错误的

Cannot find entry file index.android.js in any of the roots: ["D:\\workspace\\reactjs\\native\\myapp5"]
ENOENT: no such file or directory, open 'D:\workspace\reactjs\native\myapp5\android\app\build\intermediates\assets\debug\index.android.bundle'
然后我将index.android.js更改为App.js

然后它将显示错误为

Cannot find entry file index.android.js in any of the roots: ["D:\\workspace\\reactjs\\native\\myapp5"]
ENOENT: no such file or directory, open 'D:\workspace\reactjs\native\myapp5\android\app\build\intermediates\assets\debug\index.android.bundle'
如何解决这个问题?请帮帮我

我的react本机版本是react本机cli:2.0.1,react本机:0.52.0。我发布的根文件夹的屏幕截图

当我在android文件夹中运行
gradlew assembleDebug
时,它会显示错误


这里的问题是您似乎没有为react native bundle指定的条目文件:

index.android.js

根据项目结构,将其替换为项目的条目文件index.js或app.js

更新:

react-native bundle --dev false --platform android --entry-file <your-entry-file> --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug

您的apk将位于根项目目录中的android/app/build/outputs/apk

确保您已经有了目录android/app/src/main/assets/如果没有,请在创建新文件后创建目录并另存为index.android.bundle,然后像这样将文件放入android/app/src/main/assets/index.android.bundle

在cmd中运行此命令之后

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&./gradlew-assembleDebug


然后可以在项目的根文件夹中获取apkapp/build/outputs/apk/debug/app debug.apk,运行以下命令:

react-native run-android --variant=debug
对于旧版本:

mkdir -p android/app/src/main/assets && rm -rf android/app/build && 
react-native bundle --platform android --dev false --entry-file index.android.js 
--bundle-output android/app/src/main/assets/index.android.bundle
--assets-dest android/app/src/main/res 
&& cd android && ./gradlew clean assembleDebug && cd ../
mkdir -p android/app/src/main/assets && rm -rf android/app/build && 
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 && ./gradlew clean assembleDebug && cd ../
对于RN新版本:

mkdir -p android/app/src/main/assets && rm -rf android/app/build && 
react-native bundle --platform android --dev false --entry-file index.android.js 
--bundle-output android/app/src/main/assets/index.android.bundle
--assets-dest android/app/src/main/res 
&& cd android && ./gradlew clean assembleDebug && cd ../
mkdir -p android/app/src/main/assets && rm -rf android/app/build && 
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 && ./gradlew clean assembleDebug && cd ../
apk在以下文件夹中生成:

app/build/outputs/apk/debug/app debug.apk

如果你想在模拟器上运行apk。运行以下命令:

react-native run-android --variant=debug
这会有用的

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 && ./gradlew assembleDebug

请确认您的根目录中存在index.android.js,在更新版本的react native中可能是index.js而不是index.android.js,在根文件夹中找不到index.js。App.js可以在根文件夹中找到。你能分享你根目录的截图吗?我已经发布了截图。请检查一下。你的输入文件index.android.js在哪里?我用过app.js。然后显示错误为“enoint:没有这样的文件或目录,打开'D:\workspace\reactjs\native\myapp5\android\app\build\intermediates\assets\debug\index.android.bundle'”@Joe I更新了我的答案。将条目文件名替换为显示相同错误。“enoint:没有这样的文件或目录,打开'D:\workspace\reactjs\native\myapp5\android\app\build\intermediates\assets\debug\index.android.bundle”“@Joe你可以发布cd android&./gradlew assembledebug的输出吗输出是“系统找不到指定的路径”。这是最新的react native SDK的正确解决方案。在0.55.9上运行良好