简体   繁体   English

Android工作室 - 发布APK for flavor

[英]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. 我是Android Studio的新手并且在设备上运行调试版本工作正常,但是为了测试应用程序购买(显然要发布)我需要使用普通密钥签名的发布版本。 I can make an APK using Build -> Generate signed APK, however the package name seems to be incorrect. 我可以使用Build - > Generate signed APK制作APK,但是包名似乎不正确。 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. 请注意在flavor中重写的包名称。 That flavor has no manifest; 那味道没有明显; the only manifest is under main, and specifies a package of com.company.common. 唯一的清单是在main下,并指定一个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. 如果我使用Android创建com.company.test APK并将其安装在设备上,然后从Android Studio生成APK并安装它,我最终会在设备上安装两个应用程序而不是第二个替换第一个应用程序。 This indicates that the package names are different, I assume because Android Studio is producing an APK with a package of com.company.common. 这表明包名称不同,我假设因为Android Studio正在生成一个带有com.company.common包的APK。 Not sure how to verify that though. 不知道怎么验证这一点。

When I just build the project, I get a debug APK but no release APK. 当我刚刚构建项目时,我得到一个调试APK但没有发布APK。 How do I get a release APK with the correct package name? 如何获得具有正确包名的发布APK? 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. 我刚从Android Studio运行应用程序,它说它正在安装com.company.test.debug,并且需要在安装之前卸载应用程序。 So now I'm thinking the generate signed APK generated a build with the debug package. 所以现在我认为生成签名的APK使用调试包生成了一个构建。

So far this is the issue that's preventing me from moving to Android Studio and gradle. 到目前为止,这是阻止我转向Android Studio和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 Generate Signed APK option, go into the Build Variants window and choose the Release build variant. 在选择Generate Signed APK选项之前,请进入Build Variants窗口并选择Release build variant。 The Generate Signed APK command takes whatever the current build type is selected there and signs it. Generate Signed APK命令接受在那里选择的当前构建类型并签名。 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. 错误https://code.google.com/p/android/issues/detail?id=56532正在请求改进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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