Android的工作室:创建一个自定义生成类型时是必要的签字配置的创造? [英] Android Studio: Is creation of a signing configuration necessary when creating a custom build type?

查看:566
本文介绍了Android的工作室:创建一个自定义生成类型时是必要的签字配置的创造?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的创建的自定义buildTypes 如下上午和不使用默认的调试和发布buildTypes

buildTypes {
        releasefree {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        releasepro {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationIdSuffix ".pro"
        }
        debugfree {
            shrinkResources true
            applicationIdSuffix ".debug"
            debuggable true
        }
        debugpro {
            shrinkResources true
            applicationIdSuffix ".pro.debug"
            debuggable true
        }
    }

这样做的原因:我有几个productFlavors和需要为每个专业版,我觉得这是不是创建的每个免费的一个单独的PRO的味道更容易。我的code处理使用APPLICATION_ID从BuildConfig类的差异。另一个原因是我有定制类和将需要复制两次,如果我有两个不同的口味。我知道我可以配置sourcesets,但我有问题,当我有太多的味道。很难追踪。

Reason for doing this: I have several productFlavors and need to have a PRO version for each and I felt this was easier than creating a seperate PRO flavor for each free one. My code handles the difference using APPLICATION_ID from BuildConfig class. Another reason is i have customized classes and will need to replicate twice if i have two separate flavors. I know i can configure sourcesets, but I've had problems with that when i have too many flavors. Very difficult to track.

现在的问题::当我尝试运行使用自定义buildType构建变种的应用,它要求我为每个自定义生成类型的签字配置。

Now the issue: When i try to run the application using a custom buildType build variant, it asks me to create a signing configuration for each custom build type.

这是错误信息之我见

同样执行,当我看到在运行控制台的消息:

Similarly i see a message in the Run console when executing:

失败[INSTALL_PARSE_FAILED_NO_CERTIFICATES]

Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]

安装失败,因为APK要么没有签名,或签名
  不正确的。如果这是一个基于摇篮项目,然后确保
  签约配置在指定的摇篮构建脚本。

Installation failed since the APK was either not signed, or signed incorrectly. If this is a Gradle-based project, then make sure the signing configuration is specified in the Gradle build script.

我的理解,它可能是必需的。但是,我试图找出是:有没有设置什么我可以改变,使得debugfree和我创建可以绕过签订配置要求就像默认的调试buildType debugpro buildTypes ?我知道了建立签约配置是一分钟的事情,我会做,如果我不能很快得到的东西。只是出于好奇,我想知道需要做,使定制buildType工作就像默认的调试buildType,而不是要求签署什么样的配置

I understand that it may be required. But, what I was trying to find out was: Is there a setting what i could change so that the debugfree and debugpro buildTypes I've created could bypass the signing configuration requirement just like the default debug buildType? I know creating a signing configuration is a one minute thing and I'll do it if i do not get something soon. But just out of curiosity I want to understand what needs to be done to make the custom buildType work like the default debug buildType and not require a signing configuration.

尝试设置

debuggable true

(这是在默认的第调试buildType和我的自定义调试buildType属性唯一的区别),希望它会工作像默认的调试buildType,但没有。需要什么要改变自定义buildType喜欢默认的料理农场,即不需要签署配置。

(which was the only difference in the properties of th default debug buildType and my custom debug buildType) hoping it would work like the default debug buildType, but did not. What else need to be changed for the custom buildType to work like the default one i.e. not require a signing configuration.

推荐答案

构建类型没有严格的继承。但是,您可以使用相当于一个拷贝构造函数:

Build types don't have strict inheritance. However, you can use what amounts to a copy constructor:

debugfree.initWith(buildTypes.debug)

其中, debugfree 是要定义一个构建类型,调试是构建类型要从复制。

where debugfree is a build type that you want to define, and debug is the build type you want to copy from.

新的版本类型(否则, initFrom()可消灭在初始化部分)。

Do this before the rest of the initialization of the new build type (otherwise, initFrom() may wipe out parts of that initialization).

在特别是,由于调试已签约的配置已经成立,由调试使用相同的调试签约的配置。

In particular, since debug has a signing configuration already set up, starting a new build type by initializing from debug uses that same debug signing configuration.

不过,是的非常非常小心使用调试生成类型为起点时的。你不想意外清盘试图船舶应用与调试签约配置。

However, be very very careful when using the debug build type as a starting point. You don't want to accidentally wind up trying to ship apps with that debug signing configuration.

这篇关于Android的工作室:创建一个自定义生成类型时是必要的签字配置的创造?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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