android gradle中关于 versionCode versionName 的配置

gradle中关于 versionCode versionName 的配置

    defaultConfig {
        applicationId "com.ppg.simple"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 
    }

基本上绝大部分人的gradle刚刚创建的时候都是这样的,其中有两个属性versionCodeversionName 一开始我也搞不清楚有什么用,从名字上看似乎是版本号,和版本名

但是在我们公司的项目中基本只用改动versionName而不改动versionCode,直到有一次一个小伙伴不小心把versionCode改成11导致了一次大bug之后我才对着两个属性研究了一番

简单的说,就是
versionCode是给程序识别用的,如果当前A手机上装有versionCode为5的app时,A下载了一个versionCode为4的新的安装包是不能安装的,会提示当前版本比较新之类的提示,不论你的versionName怎么样都不行.
当时我们的项目就是怎么弄都更新识别,后来发现了这个问题后把versionCode改成12就能更新了

versionName是给

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Android Studio Gradle 配置主要分为两部分:项目级别的 build.gradle 和应用级别的 build.gradle。 1. 项目级别的 build.gradle 该文件位于项目根目录下,主要用于配置项目的构建属性、仓库地址等。 示例代码: ``` buildscript { repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:4.2.2' } } allprojects { repositories { jcenter() google() } } ``` 其: - `buildscript` 用于配置项目构建所需要的依赖库,如 `com.android.tools.build:gradle`,以及仓库地址。 - `allprojects` 用于配置所有模块的仓库地址。 2. 应用级别的 build.gradle 该文件位于 app 模块目录下,主要用于配置应用的构建属性、依赖库等。 示例代码: ``` apply plugin: 'com.android.application' android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.example.myapplication" minSdkVersion 21 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' } ``` 其: - `apply plugin: 'com.android.application'` 表示应用模块使用 Android 应用插件。 - `android` 用于配置应用的构建属性,如编译版本号、应用ID、依赖库等。 - `dependencies` 用于配置应用的依赖库,可以通过 Maven 仓库、本地目录或文件、远程仓库等方式引入。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值