What's the difference between gradlewAssembleRelease, gradlewInstallRelease, and gradlew bundleRelease and when to use which?

zid*_*ryi 27 java android kotlin react-native

When I want to upload an Android application to the Play Store, which one should I use?

I have tried the above but I am still confused about which one is the most effective?

./gradlew assembleRelease
./gradlew installRelease
./gradlew bundleRelease
Run Code Online (Sandbox Code Playgroud)

I expect the best way to do the above.

And*_*rew 67

您正在寻找的大多数答案都可以在这里找到

assembleDebug

这会使用调试变体为您的项目构建一个apk

这会在 project_name/module_name/build/outputs/apk/ 中创建一个名为 module_name-debug.apk 的 APK。该文件已使用调试密钥签名并与 zipalign 对齐,因此您可以立即将其安装到设备上。

installDebug

这会使用调试变体为您的项目构建一个apk,然后将其安装在连接的设备上

或者要构建 APK 并立即将其安装在正在运行的模拟器或连接的设备上,而不是调用 installDebug

assembleRelease

这将创建您的应用程序的发布apk。然后,您需要使用命令行或通过在您的build.gradle(见下文)中设置签名详细信息对其进行签名,然后您可以使用adb.

通过命令行签署apk所涉及的步骤相当长,这取决于您的项目是如何设置的。可以在此处找到签名步骤

bundleRelease

这将创建一个发布aab,这是 Google 上传到 Play 商店的首选格式。

Android App Bundles 包含您应用的所有编译代码和资源,但将 APK 生成和签名推迟到 Google Play。与 APK 不同,您不能将 app bundle 直接部署到设备。因此,如果您想快速测试或与其他人共享 APK,您应该构建一个 APK。

签署您的 apk/aab

您可以配置您的app/build.gradle签名,以便在构建完成后进行签名。

在你的 app/build.gradle

android {
    ...
    defaultConfig { ... }
    signingConfigs {
        release {
            // You need to specify either an absolute path or include the
            // keystore file in the same directory as the build.gradle file.
            storeFile file("my-release-key.jks")
            storePassword "password"
            keyAlias "my-alias"
            keyPassword "password"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            ...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以在此处阅读有关签署您的应用程序的更多信息

现在,当您通过调用 Gradle 任务构建您的应用程序时,Gradle 会为您签署您的应用程序(并运行 zipalign)。

此外,由于您已使用签名密钥配置发布版本,因此“安装”任务可用于该版本类型。因此,您可以使用 installRelease 任务在模拟器或设备上构建、对齐、签名和安装发布版 APK。

installRelease

您必须设置上面的签名才能用于发布版本。它installDebug

用法

  • assembleRelease用来构建一个我想与其他人分享的apk
  • 我用installRelease的时候我想连接的设备上测试发布版本。
  • bundleRelease在将我的应用上传到 Play 商店时使用。

  • 值得一提的是,签名数据应该从另一个文件(例如 keystore.properties)中获取,并且该文件应该添加到 gitignore,这样其他人就不会复制您的签名。 (2认同)