Android Studio Gradle assembleRelease 文件名

标签 android gradle android-studio

是否可以通过gradle指定生成的*.apk的文件名?这样我就可以自动获取 MyApp-1.0.0.apk 而不是默认的 app-release.apk

最佳答案

您可以通过将以下行添加到您的 android{...} 部分内的 build.gradle 文件来执行此操作:

android.applicationVariants.all { variant ->
    variant.outputFile = file("$project.buildDir/${defaultConfig.versionName}-${defaultConfig.versionCode}.apk")
}

注意事项:

  1. 当然,file(...) 中的所有内容都是任意的
  2. 此代码会将 *.apk 输出到您的 project/module/build 目录,无论您在构建签名 APK 时指定的路径是什么。
  3. 输出文件将从您的 build.gradle 文件中获取名称和版本代码。
  4. Android Studio 可能会提示它“无法解析符号 applicationVariants/defaultConfig” - 忽略它。 ;)

关于Android Studio Gradle assembleRelease 文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25620427/

相关文章:

android - 在 Androidx 上使用 registerForActivityResult 选择文件

Android截图错误: RGBA override BLOB format buffer should have height == width

android - Android Studio版本与Gradle插件版本之间有什么关系?

android - 在 Gradle 中通过 Build Flavors 使用替代资源

android - 如何同时使抽屉导航选框 ListView 中的所有 TextView ?

android - AlertDialog 弹出两次

java - Mapbox Android SDK 崩溃 - "java.lang.Error: Vertex shader fill failed to compile"

android - 无法解析符号 'RequestQueue'

android-studio - 如何将flutter项目迁移到androidx:任务 ':app:preDebugBuild'执行失败。 > Android依赖项'androidx.versionedparcelable

Android Studio - 如何压缩对齐 apk