如何生成一个可以在没有带反应原生的服务器的情况下运行的apk? [英] How can I generate an apk that can run without server with react-native?
问题描述
我已经构建了我的应用程序,我可以在我的本地模拟器上运行它(也可以通过更改调试服务器在同一网络中的我的Android设备上运行)。
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).
但是,我想构建一个apk,我可以发送给没有访问开发服务器的人,我希望他们能够测试应用程序。
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.
我看到有一个部分在文档的iOS部分使用脱机捆绑包。但我无法弄清楚如何为Android做同样的事情。这可能吗?如果是这样,怎么做?
I see there is a section Using offline bundle on iOS section of the documentation. But I couldn't figure out how to accomplish same for android. Is this possible? If so, how?
更新:关于这个问题的答案(反应原生android无法加载JS包)据说离线包可以从开发服务器下载。但是当我从开发服务器获取包时,无法加载图像文件。
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. But when I obtain the bundle from development server the image files can't be loaded.
推荐答案
按照Aditya Singh的回答生成(没有签名)apk不会安装在我的手机上。我必须使用说明生成一个签名的apk 这里。
Following Aditya Singh's answer the generated (unsigned) apk would not install on my phone. I had to generate a signed apk using the instructions here.
以下对我有用:
$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
将 my-release-key.keystore
文件放在 android / app
下项目文件夹中的目录。然后编辑文件
〜/ .gradle / gradle.properties
并添加以下内容(用正确的密钥库密码替换****
,别名密钥密码)
Place the my-release-key.keystore
file under the android/app
directory in your project folder. Then edit the file
~/.gradle/gradle.properties
and add the following (replace ****
with the correct keystore password, alias and key password)
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=****
MYAPP_RELEASE_KEY_PASSWORD=****
如果你'重新使用MacOS,您可以使用此处而不是以明文形式存储它。
If you're using MacOS, you can store your password in the keychain using the instructions here instead of storing it in plaintext.
然后编辑app / build.gradle并确保以下内容(可能需要添加visaConfigs signingConfig的部分):
Then edit app/build.gradle and ensure the following are there (the sections with signingConfigs signingConfig may need to be added) :
...
android {
...
defaultConfig { ... }
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
release {
...
signingConfig signingConfigs.release
}
}
}
...
然后运行命令 cd android&& ./gradlew assembleRelease
,
For Windows 'cd android'然后运行 gradlew assembleRelease
命令,在 android / app / build / outputs / apk / app-release.apk
签名 apk >
For Windows 'cd android' and then run gradlew assembleRelease
command , and find your signed apk under android/app/build/outputs/apk/app-release.apk
这篇关于如何生成一个可以在没有带反应原生的服务器的情况下运行的apk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!