如何生成一个可以在没有服务器的情况下使用 react-native 运行的 apk? [英] How can I generate an apk that can run without server with react-native?

查看:12
本文介绍了如何生成一个可以在没有服务器的情况下使用 react-native 运行的 apk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了我的应用程序,我可以在我的本地模拟器上运行它(也可以通过更改调试服务器在我的同一网络内的 android 设备上运行).

I've built my app, I can run it on my local emulator (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 the 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 the same for android. Is this possible? If so, how?

更新:关于这个问题的答案(Android 加载 JS 包失败) 据说可以从开发服务器下载离线包.但是当我从开发服务器获取包时,无法加载图像文件.

UPDATE: On the answer to this question (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 不会安装在我的手机上.我必须使用说明 此处.

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 并确保存在以下内容(可能需要添加带有签名配置的部分签名配置):

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 ,

对于 Windows 'cd android' 然后运行 ​​gradlew assembleRelease 命令,然后在 android/app/下找到你的 signed apkbuild/outputs/apk/app-release.apkandroid/app/build/outputs/apk/release/app-release.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, or android/app/build/outputs/apk/release/app-release.apk

这篇关于如何生成一个可以在没有服务器的情况下使用 react-native 运行的 apk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆