如果我们使用多个APK,BuildConfig.VERSION_CODE是否不会更改 [英] Does BuildConfig.VERSION_CODE not get changed if we are using multiple APK's

查看:262
本文介绍了如果我们使用多个APK,BuildConfig.VERSION_CODE是否不会更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建多个apk 对于每个 ABI ,我这样做是为每个apk分配单独的版本代码。

I am creating multiple apk's for each ABI, I did this to assign separate version code to each apk.

ext.abiCodes = ['armeabi-v7a':1, mips:2, x86:3]

import com.android.build.OutputFile
android.applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def baseAbiVersionCode =
                project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))

        if (baseAbiVersionCode != null) {
            output.versionCodeOverride =
                    baseAbiVersionCode * 1000 + variant.versionCode
        }
    }
} 

这是我的 dafaultConfig ,下面的 versionCode 用于 UniversalApk

This is my dafaultConfig, and the following versionCode is for universalApk

 defaultConfig {
        versionCode 74
        versionName "1.0.2"
}

我附上 versionCode 对于每个服务请求,我还将在其中一个活动中显示 versionCode 。所以我需要正确的 versionCode 来执行这些操作,我使用此代码来获取 versionCode

I append the versionCode with each service request, I also display the versionCode in one of the activity. So i need the correct versionCode to perform these operations, I use this code to get versionCode

int versionCode = BuildConfig.VERSION_CODE;

现在的问题是,它显示 versionCode defaultConfig 中声明的c>而不是实际代表构建的那个。

Now the problem is that, it displays the versionCode that is stated in defaultConfig and not the one that actually represents the build.

我需要知道如何获取分配给此版本的 versionCode 大于 1000 的数字,而不是 dafaultConfig

I need to know that how can i get the versionCode that is assigned to this build, that may be some number greater than 1000, and not the one that is assigned in dafaultConfig

推荐答案

要检查版本代码,可以使用PackageInfo和PackageManager

To check version code you can use PackageInfo and PackageManager

try {
    PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
    String version = pInfo.versionName;   //version name
    int verCode = pInfo.versionCode;      //version code
} catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
}

这篇关于如果我们使用多个APK,BuildConfig.VERSION_CODE是否不会更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆