Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

javascript - 如何生成无需服务器即可运行带有react-native的apk?(How can I generate an apk that can run without server with react-native?)

I've built my app, I can run it on my local simulator (and also on my android device within the same network by changing debug server).(我已经构建了我的应用程序,可以在本地模拟器上运行它,也可以通过更改调试服务器在同一网络中的android设备上运行它。)

However, I want to build an apk that I can send to someone without access to development server and I want them to be able to test application.(但是,我想构建一个APK,可以将其发送给某人,而无需访问开发服务器,并且希望他们能够测试应用程序。) I see there is a section Using offline bundle on iOS section of the documentation.(我看到文档中有一节在iOS上使用脱机捆绑包。) But I couldn't figure out how to accomplish same for android.(但是我不知道如何为android实现相同的功能。) Is this possible?(这可能吗?) If so, how?(如果是这样,怎么办?) UPDATE: On the answer to this question ( react native android failed to load JS bundle ) it is said that offline bundle can be downloaded from development server.(更新:关于此问题的答案( 响应本机android无法加载JS包 ),据说可以从开发服务器下载脱机包。) But when I obtain the bundle from development server the image files can't be loaded.(但是,当我从开发服务器获取捆绑软件时,无法加载图像文件。)   ask by Gokhan Sari translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You will have to create a key to sign the apk.(您将必须创建一个密钥来对apk进行签名。)

Use below to create your key:(使用以下内容创建密钥:) keytool -genkey -v -keystore my-app-key.keystore -alias my-app-alias -keyalg RSA -keysize 2048 -validity 10000 Use a password when prompted(出现提示时使用密码) Once the key is generated, use it to generate the installable 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/ Generate the build using gradle(使用gradle生成构建) cd android && ./gradlew assembleRelease Upload the APK to your phone.(将APK上传到您的手机。) The -r flag will replace the existing app (if it exists)(-r标志将替换现有应用程序(如果存在)) adb install -r ./app/build/outputs/apk/app-release-unsigned.apk A more detailed description is mentioned here: https://facebook.github.io/react-native/docs/signed-apk-android.html(这里提到了更详细的描述: https : //facebook.github.io/react-native/docs/signed-apk-android.html) UPDATE : Based on comments by @shashuec and @Fallen(更新 :基于@shashuec和@Fallen的评论) if you get error(如果您遇到错误) ENOENT: no such file or directory, open 'android/app/src/main/assets/index.android.bundle'(ENOENT:没有此类文件或目录,请打开“ android / app / src / main / assets / index.android.bundle”) run mkdir android/app/src/main/assets(运行mkdir android / app / src / main / assets)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...