在 android 项目中包含构建变体无法在以前的版本上更新生产 apk

问题描述 投票:0回答:1

我的 Android 应用程序项目之前没有任何构建变体,我过去常常使用我创建的密钥库凭据对生产 apk 进行签名,并直接安装,而不作为 apk 文件在 Play 商店上发布。

但现在由于客户要求某些用户需要在同一设备上分别拥有 UAT 和生产 apk,我在 build.gradle 文件中引入了构建变体和产品风格。

UAT 版本具有不同的包名称,生产版本与以前保持相同的包名称。

UAT 版本正在安装,因为它是一个具有新包名称的新 apk,但是生产 apk 没有在当前版本上更新,即使它具有相同的包名称并抛出错误“App not installed as package appears无效"

下面给出了无flavors和有flavors的gradle文件代码。

没有味道的旧代码:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    // Add the Crashlytics Gradle plugin
    id 'com.google.firebase.crashlytics'
}

android {
    compileSdk 32
    android.defaultConfig.vectorDrawables.useSupportLibrary = true
    defaultConfig {
        applicationId "com.cropinsurance.krishak"
        minSdk 21
        targetSdk 32
        versionCode 14 // play store version 13
        versionName "1.3.6" // play store version 1.3.5 release
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/proguard/androidx-annotations.pro'
        exclude 'META-INF/LICENSE.md'
        exclude 'META-INF/NOTICE.md'
    }
    lintOptions {
        disable 'MissingTranslation'
        checkReleaseBuilds false
    }
    flavorDimensions "dimension_less"
    productFlavors {
        typeBuildSudesiUat {}
        typeBuildSbiUat {}
        typeBuildProd {}
    }

}

dependencies {

    implementation "androidx.autofill:autofill:1.1.0"

    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.intuit.sdp:sdp-android:1.0.4'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.squareup.retrofit2:retrofit:2.8.1'
    implementation "com.squareup.retrofit2:converter-gson:2.8.1"
    implementation 'com.squareup.okhttp3:logging-interceptor:4.6.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.squareup.okhttp3:okhttp:4.9.0'


    //firebase
    implementation platform('com.google.firebase:firebase-bom:31.1.0')
    implementation 'com.google.firebase:firebase-analytics'


        // Import the BoM for the Firebase platform
        implementation platform('com.google.firebase:firebase-bom:31.1.0')
        // Add the dependencies for the Crashlytics and Analytics libraries
        // When using the BoM, you don't specify versions in Firebase library dependencies
        implementation 'com.google.firebase:firebase-crashlytics'
        implementation 'com.google.firebase:firebase-analytics'

    implementation 'com.google.android.play:core:1.10.3'

}

具有产品口味的新代码:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    // Add the Crashlytics Gradle plugin
    id 'com.google.firebase.crashlytics'
}

android {
    signingConfigs {

    /*    debug {
            storeFile file('filepath')
            storePassword 'mypassword'
            keyAlias 'key0'
            keyPassword 'mypassword'
        }
*/

        release {
           storeFile file('filepath')
            storePassword 'mypassword'
            keyAlias 'key0'
            keyPassword 'mypassword'
        }
    }
    compileSdk 32
    android.defaultConfig.vectorDrawables.useSupportLibrary = true
    defaultConfig {
        applicationId "com.cropinsurance.krishak"
        minSdk 21
        targetSdk 32
        versionCode 14 // play store version 13
        versionName "1.3.6" // play store version 1.3.5 release
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        signingConfig signingConfigs.release
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            debuggable false
        }

        debug{
            debuggable true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/proguard/androidx-annotations.pro'
        exclude 'META-INF/LICENSE.md'
        exclude 'META-INF/NOTICE.md'
    }
    lintOptions {
        disable 'MissingTranslation'
        checkReleaseBuilds false
    }
    flavorDimensions "dimension_less"
    productFlavors {
//        typeBuildSudesiUat {}
        typeBuildSbiUat {
            applicationId 'com.cropinsurance.krishak.uat'
            manifestPlaceholders = [ appLabel : "UAT_Krishak"]
            buildConfigField("String", "URL_BASE_MASTER", '""')
            buildConfigField("String", "URL_BASE_UP", '""')
            buildConfigField("String", "URL_BASE_DOWN", '""')
            buildConfigField("String", "URL_BASE_IMAGE", '""')
        }
        typeBuildProd {
            applicationId 'com.cropinsurance.krishak'
            manifestPlaceholders = [ appLabel : "Krishak"]
            buildConfigField("String", "URL_BASE_MASTER", '""')
            buildConfigField("String", "URL_BASE_UP", '""')
            buildConfigField("String", "URL_BASE_DOWN", '""')
            buildConfigField("String", "URL_BASE_IMAGE", '""')
        }
    }

}

dependencies {

    implementation "androidx.autofill:autofill:1.1.0"

    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.intuit.sdp:sdp-android:1.0.4'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.squareup.retrofit2:retrofit:2.8.1'
    implementation "com.squareup.retrofit2:converter-gson:2.8.1"
    implementation 'com.squareup.okhttp3:logging-interceptor:4.6.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.squareup.okhttp3:okhttp:4.9.0'


    //firebase
    implementation platform('com.google.firebase:firebase-bom:31.1.0')
    implementation 'com.google.firebase:firebase-analytics'


        // Import the BoM for the Firebase platform
        implementation platform('com.google.firebase:firebase-bom:31.1.0')
        // Add the dependencies for the Crashlytics and Analytics libraries
        // When using the BoM, you don't specify versions in Firebase library dependencies
        implementation 'com.google.firebase:firebase-crashlytics'
        implementation 'com.google.firebase:firebase-analytics'

    implementation 'com.google.android.play:core:1.10.3'

}

任何人都可以建议我在这里做错了什么吗?我需要生产版本风味安装在以前的生产 apk 上,因为我为生产版本保留了相同的包。

我不能要求用户卸载并安装 apk,因为他们会丢失数据。

提前致谢。

android android-productflavors build-variant
1个回答
0
投票

立即创建签名的 apk 将导致应用程序未安装),

您应该在创建签名包/apk 之前清理项目

如果这不起作用,使缓存无效并重新启动并创建一个签名的包/apk。

© www.soinside.com 2019 - 2024. All rights reserved.