Android build.gradle版本名打包配置的方法

 更新时间:2019年02月12日 15:06:21   作者:淡淡_孩子气  
这篇文章主要介绍了Android build.gradle版本名打包配置的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

1、生成密钥文件到app工程目录下

2、在gradle.properties文件下配置密钥文件信息

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
RELEASE_KEY_PASSWORD=key-password
RELEASE_KEY_ALIAS=key-alias
RELEASE_STORE_PASSWORD=store-password
#jks文件名
RELEASE_STORE_FILE=sugr-ivy.jks

3、build.gradle文件下配置

apply plugin: 'com.android.application'

android {

  compileSdkVersion 26
  project.archivesBaseName = "AppName"
  defaultConfig {
    applicationId "com.example.app"
    minSdkVersion 23
    targetSdkVersion 26
    versionCode 1
    versionName "1.4.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }

  signingConfigs {
    release {
      keyAlias RELEASE_KEY_ALIAS
      keyPassword RELEASE_KEY_PASSWORD
      storeFile file(RELEASE_STORE_FILE)
      storePassword RELEASE_STORE_PASSWORD
    }
    debug {
      keyAlias RELEASE_KEY_ALIAS
      keyPassword RELEASE_KEY_PASSWORD
      storeFile file(RELEASE_STORE_FILE)
      storePassword RELEASE_STORE_PASSWORD
    }
  }

  buildTypes {
    release {
      buildConfigField "boolean", "LOG_DEBUG", "false" // 不显示Log
      minifyEnabled false           //混淆
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      signingConfig signingConfigs.release  //签名
    }
    debug {
      signingConfig signingConfigs.debug  //签名
    }
  }

  applicationVariants.all {
    variant ->
      variant.outputs.all {
        Calendar calendar = Calendar.getInstance(Locale.CHINA);
        def buildDate = String.format(Locale.CHINA, "%04d%02d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH))
        def versionName = defaultConfig.versionName
        def versionCode = defaultConfig.versionCode
        //android studio3.0之前的写法
        //  output->output.outputFile=new File(output.outputFile.parent,output.outputFile.name.replace(".apk","-"+defaultConfig.versionName+".apk"))
        //android studio3.0的写法
        //项目名-版本名-版本号-release/debug.apk
        if (variant.buildType.name.equals('release')) {
          outputFileName = "${project.archivesBaseName}-v${versionName}-c${versionCode}-${buildDate}-release.apk"
        } else {
          outputFileName = "${project.archivesBaseName}-v${versionName}-c${versionCode}-${buildDate}-debug.apk"
        }
      }
  }

}

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

  implementation 'com.android.support:appcompat-v7:26.1.0'
  implementation 'com.android.support.constraint:constraint-layout:1.1.3'
  implementation 'com.android.support:multidex:1.0.3'
  implementation 'com.android.support:recyclerview-v7:26.1.0'

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • Android中传递对象的三种方法的实现

    Android中传递对象的三种方法的实现

    本篇文章主要介绍了Android中传递对象的三种方法的实现,可以通过Bundle、Intent或者JSON字符串,有兴趣的可以了解一下。
    2017-02-02
  • Android控件系列之CheckBox使用介绍

    Android控件系列之CheckBox使用介绍

    CheckBox和Button一样,也是一种古老的控件,它的优点在于,不用用户去填写具体的信息,只需轻轻点击,缺点在于只有“是”和“否”两种情况,但我们往往利用它的这个特性,来获取用户的一些信息
    2012-11-11
  • Android中PackageManager使用详解

    Android中PackageManager使用详解

    PackageManger的主要职责是管理应用程序包,通过它可以获取应用程序信息,这篇文章主要给大家介绍了关于Android中PackageManager使用的相关资料,需要的朋友可以参考下
    2021-11-11
  • Android中dip、dp、sp、pt和px的区别详解

    Android中dip、dp、sp、pt和px的区别详解

    本篇文章是对Android中dip、dp、sp、pt和px的区别进行了详细的分析介绍,需要的朋友参考下
    2013-06-06
  • 完美解决Android Studio集成crashlytics后无法编译的问题

    完美解决Android Studio集成crashlytics后无法编译的问题

    下面小编就为大家带来一篇完美解决Android Studio集成crashlytics后无法编译的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • Android 开发调试工具的使用总结

    Android 开发调试工具的使用总结

    这篇文章主要介绍了Android 开发调试工具的使用总结的相关资料,这里整理了,Android开发所需要的常用工具,需要的朋友可以参考下
    2016-11-11
  • 浅谈Android添加快捷方式ShortCut

    浅谈Android添加快捷方式ShortCut

    这篇文章主要介绍了浅谈Android添加快捷方式ShortCut,对添加快捷方式感兴趣的同学,可以参考下
    2021-04-04
  • Android全屏设置的方法总结

    Android全屏设置的方法总结

    这篇文章主要介绍了Android全屏设置的方法总结的相关资料,需要的朋友可以参考下
    2017-06-06
  • Android界面设计(APP设计趋势 左侧隐藏菜单右边显示content)

    Android界面设计(APP设计趋势 左侧隐藏菜单右边显示content)

    这文章讲述了2013年未来的移动APP设计趋势,感觉挺有道理的:Android界面设计实现左侧隐藏菜单右边显示content,感兴趣的你可以了解下啊,希望本文对你的APP设计提高有所帮助哦
    2013-01-01
  • Android WebView交互传递json字符串并解析的方法

    Android WebView交互传递json字符串并解析的方法

    这篇文章主要给大家介绍了关于Android中WebView交互传递json字符串并解析的相关资料,文中通过示例代码介绍的非常详细,对各位Android开发者具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
    2018-05-05

最新评论