将 React Native 发布到 Google Play 控制台会生成旧的 apk

Posted

技术标签:

【中文标题】将 React Native 发布到 Google Play 控制台会生成旧的 apk【英文标题】:Publishing React Native to Google Play console generates old apk 【发布时间】:2019-12-17 09:02:51 【问题描述】:

我正在尝试在我的 React Native 项目中为 android 生成发布 apk。 我按照官方 Facebook 的 React Native 发布文档中的所有步骤进行操作。

当我在播放控制台中上传生成的 apk 时,在我的设备上下载并运行它,我没有看到我在上次发布 apk 后所做的任何更改。 (意味着我看到的是具有旧功能而不是新功能的旧 apk)

我还尝试在发布之前运行react-native run-android --variant=release,我得到了相同的旧版本的apk。但我可以看到所有新功能在调试时运行,没有发布标志。

尝试了其他解决方案,如下所示,但这些解决方案会导致“重复错误”。

react-native run-android builds an old version of the code onto device

更新: 希望这可以帮助遇到同样问题并试图找到解决方案的人。

我让它以这种方式工作。我不知道这是多么可取,但这对我现在有用。我在官方 react-native github 问题页面上找到了解决方案。这是link to the actual solution,也是解决方案的快速浏览。我不得不在 doFirst 代码块之后使用以下代码编辑 react.gradle 文件。该文件可以在 node-modules > react-native 文件夹下找到。

doLast 
        def moveFunc =  resSuffix ->
            File originalDir = file("$buildDir/generated/res/react/release/drawable-$resSuffix");
            if (originalDir.exists()) 
                File destDir = file("$buildDir/../src/main/res/drawable-$resSuffix");
                ant.move(file: originalDir, tofile: destDir);
            
        
        moveFunc.curry("ldpi").call()
        moveFunc.curry("mdpi").call()
        moveFunc.curry("hdpi").call()
        moveFunc.curry("xhdpi").call()
        moveFunc.curry("xxhdpi").call()
        moveFunc.curry("xxxhdpi").call()
        

然后我运行以下命令:

cd android
./gradlew bundleRelease
cd..
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

然后我使用发布变体运行构建命令并且它工作。获取所有最新更改并生成新的 apk。尝试了多次,成功了。

react-native run-android --variant=release

【问题讨论】:

【参考方案1】:

当您运行“react-native run-android --variant=release”时,您之前是否删除过您设备上的应用? (如果我以前不这样做,我会遇到一些麻烦)。

对于 play store 部分,您是否增加了您的 react 项目的构建版本? (package.json 中的“version”,android>app>build.gradle 中的“defaultConfig > versionCode 和 versionName”,ios 中的 info.plist)。

【讨论】:

感谢您的回复。回答您的第一个问题:是的,我在运行命令之前确实卸载了所有以前的应用程序实例。回答你的第二个问题:我确实在 android 的 build.gradle 文件中增加了 versionCode 和 versionName。 对不起,它没有帮助:/ 当你构建一个版本时,apk 创建时间会更新吗?

以上是关于将 React Native 发布到 Google Play 控制台会生成旧的 apk的主要内容,如果未能解决你的问题,请参考以下文章

(React Native) 如何将 App Signing Key 上传到 Google Play Console?

尝试解析模块“@react-native-community/google-signin”时出错

React Native App 中的 iCloud 和 Google Drive 集成

重建 react-native 后 Google Play Console 签名错误/无效签名

如何通过 React Native 将打印作业发送到打印机

react-native-google-signin 与 AWS Cognito