简体   繁体   中英

Android studio - release APK for flavor

I'm new to Android Studio and running a debug build on a device is working fine, however to test in app purchasing (and obviously to release) I need a release build signed with the normal key. I can make an APK using Build -> Generate signed APK, however the package name seems to be incorrect. Here's my build file:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 9

        testPackageName "com.company.common.common"
        testInstrumentationRunner "android.common.InstrumentationTestRunner"
    }

    signingConfigs {
        releaseConfig {
            storeFile file("filname")
            storePassword "password"
            keyAlias "alias"
            keyPassword "password"
        }
    }

    buildTypes {
        debug {
            packageNameSuffix ".debug"
        }
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.releaseConfig
        }
    }

    productFlavors {
        Flavor1 {
            packageName "com.company.test"
        }
    }
}

dependencies {
    // some dependencies
}

Note the package name overridden in the flavor. That flavor has no manifest; the only manifest is under main, and specifies a package of com.company.common. If I use Android to create a com.company.test APK and install it on a device, then generate an APK from Android Studio and install it, I end up with two apps on the device rather than the second replacing the first. This indicates that the package names are different, I assume because Android Studio is producing an APK with a package of com.company.common. Not sure how to verify that though.

When I just build the project, I get a debug APK but no release APK. How do I get a release APK with the correct package name? I just ran the app from Android Studio and it says it's installing com.company.test.debug, and that it needs to uninstall the app before installing. So now I'm thinking the generate signed APK generated a build with the debug package.

So far this is the issue that's preventing me from moving to Android Studio and gradle. Once I get past this I think I'm clear to move everything over so I'm hoping someone can help me figure it out!

Before you choose the option, go into the window and choose the build variant. 选项之前,请进入窗口并选择 build variant。 The command takes whatever the current build type is selected there and signs it. 命令接受在那里选择的当前构建类型并签名。 This obviously isn't what you want in this case; bug https://code.google.com/p/android/issues/detail?id=56532 is requesting improvements there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM