欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

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

时间:2020-11-17 00:57:20|栏目:Android代码|点击:

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自定义Animation实现View摇摆效果

栏    目:Android代码

下一篇:基于SurfaceView实现可拖动视频控件

本文标题:Android build.gradle版本名打包配置的方法

本文地址:http://www.codeinn.net/misctech/23335.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有