You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Android Studio中构建用于Beta版发布的App Bundle?

我在控制台中可以看到应用的不同版本,但不太清楚如何在Android Studio中创建beta版App Bundle。
在此输入图片描述
我目前尝试在Android Studio中按如下路径构建:

Build -> Build Bundle(s)/APk -> Build Bundle(s)

请问如何才能创建beta版App Bundle?以下是我的build.gradle文件代码:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'idea'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'realm-android'
apply plugin: 'git-repo'
apply from: './jacoco.gradle'
apply from: "./common-methods.gradle"

android {

    signingConfigs {
        release
    }

    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/maven/com.squareup.retrofit/retrofit/pom.properties'
        exclude 'META-INF/maven/com.squareup.retrofit/retrofit/pom.xml'
    }

    dexOptions {
        javaMaxHeapSize "2048m"
        jumboMode = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }

    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }

    defaultConfig {
        applicationId "com.sai.android"
        testApplicationId "com.sai.android.tests"

        multiDexEnabled = true
        vectorDrawables.useSupportLibrary = true

        buildToolsVersion '30.0.2'
        minSdkVersion 19
        compileSdkVersion 30
        targetSdkVersion 30
        versionCode 209
        versionName '2.12.1'

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            debuggable false
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            lintOptions {
                disable 'MissingTranslation' // google services plugin is causing missing translation issue
            }
            testCoverageEnabled false
        }
        debug {
            debuggable true
            lintOptions {
                disable 'MissingTranslation' // google services plugin is causing missing translation issue
            }
            testCoverageEnabled true
//            applicationIdSuffix ".debug"
        }
    }

    flavorDimensions "default"

    productFlavors {
        production {
            dimension "default"
        }

        staging {
            dimension "default"
        }

        acceptance {
            dimension "default"
        }
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    bundle {
        language {
            // Specifies that the app bundle should not support configuration APKs for language resources.
            // These resources are instead packaged with each base and dynamic feature APK.
            enableSplit = false
        }
    }
}

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-annotations:29.0.0'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':rasp')
    implementation 'com.saltedge.android.common:views-lib:0.1.8.1@aar'
    implementation 'com.saltedge.android.common:tools-lib:0.1.4@aar'
    implementation 'com.saltedge.android.common:models-lib:0.1.3@aar'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.browser:browser:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation "androidx.preference:preference-ktx:1.1.1"
    implementation "androidx.work:work-runtime-ktx:2.5.0"
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'com.google.android.gms:play-services-identity:17.0.0'
    implementation 'com.google.android.gms:play-services-gcm:17.0.0'
    implementation 'com.google.android.gms:play-services-analytics:17.0.0'
    implementation 'com.google.android.gms:play-services-auth:19.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.1'
    implementation 'com.google.android.gms:play-services-location:18.0.0'
    implementation 'com.google.firebase:firebase-core:19.0.0'
    implementation 'com.google.firebase:firebase-crashlytics:18.0.0'
    implementation 'com.google.firebase:firebase-analytics:19.0.0'
    implementation('com.twitter.sdk.android:twitter:3.3.0@aar') {
        transitive = true
    }
    implementation 'com.tubb.smrv:swipemenu-recyclerview:5.4.8'
    implementation 'org.greenrobot:eventbus:3.2.0'
    implementation 'com.yandex.android:mobmetricalib:3.2.2'
    implementation 'com.facebook.android:facebook-android-sdk:4.31.0'
    implementation 'net.danlew:android.joda:2.10.2'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
    implementation('com.theartofdev.edmodo:android-image-cropper:2.8.0') {
        exclude group: "com.android.support"
    }
    implementation 'net.objecthunter:exp4j:0.4.8'
    kapt 'com.github.bumptech.glide:compiler:4.11.0'
    implementation ("com.github.bumptech.glide:glide:4.11.0") {
        exclude group: "com.android.support"
    }
    implementation 'com.caverock:androidsvg:1.4'

    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation('androidx.multidex:multidex-instrumentation:2.0.0') {
        exclude group: 'com.android.support', module: 'multidex'
    }
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestImplementation 'androidx.test:rules:1.3.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.3.0'
    androidTestImplementation 'androidx.test.espresso:espresso-web:3.3.0'
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestImplementation('androidx.test.espresso:espresso-idling-resource:3.1.0', {
        exclude module: 'support-annotations'
    })
    androidTestImplementation('androidx.test.espresso:espresso-contrib:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'design'
        exclude group: 'com.android.support', module: 'recyclerview-v7'
    })
    androidTestImplementation 'org.hamcrest:hamcrest-core:2.2'
    androidTestImplementation 'org.hamcrest:hamcrest-integration:1.3'
    androidTestImplementation 'org.hamcrest:hamcrest-library:2.2'
    androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.3.1'
    androidTestImplementation 'org.mockito:mockito-android:3.2.4'
    testImplementation 'org.mockito:mockito-core:3.3.3'
}

idea {
    module {
        testOutputDir = file('build/test-classes/debug')
    }
}

repositories {
    mavenCentral()
    maven { url "http://dl.bintray.com/glomadrian/maven" }
    androidCommonGit("https://git.saltedge.com/shared/android-common.git")
}

setupSigning("./signing.properties", "release")

apply plugin: 'com.google.gms.google-services'

解决方法

分两种场景处理,按需选择即可:

场景1:你说的beta是指要上传到Google Play Beta测试轨道的版本

不需要修改任何本地打包配置,你现在正常构建的生产环境release签名App Bundle就可以直接用。Play控制台的beta、正式这些版本属性是平台侧管理的,和你本地打包的类型没有关系,直接把打包好的正式App Bundle上传到beta轨道即可。

场景2:你需要本地构建独立的beta包,和正式生产包做区分

可以直接修改你当前的build.gradle配置,新增beta构建类型即可,修改步骤如下:

  1. 找到build.gradle里的buildTypes代码块,添加如下配置:
beta {
    debuggable false
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    signingConfig signingConfigs.release // 和正式包共用一套签名
    versionNameSuffix "-beta" // 版本名自动加beta后缀,方便识别版本
    // 可选配置:添加`applicationIdSuffix ".beta"`,可以让beta包和正式包同时安装在同一台设备上
    lintOptions {
        disable 'MissingTranslation'
    }
    testCoverageEnabled false
}
  1. 同步Gradle配置后,就可以选择对应的方式打包:
  • 先点开Android Studio左下角的「Build Variants」面板,选你需要的产品风味对应的beta变体(比如productionBeta),再走你之前的Build -> Build Bundle(s)/APk -> Build Bundle(s)路径构建即可
  • 也可以走Build -> Generate Signed Bundle / APK路径,选择App Bundle,输入签名信息后,在变体选择页直接选beta对应的变体构建签名包即可。

如果不想加新的构建类型,也可以直接在productFlavors块里新增一个beta风味,配置逻辑和上面一致,加完选对应beta风味的release版本构建即可。

内容的提问来源于stack exchange,提问作者Morozov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 18:15:04