I found (thanks, opensource!) That the Android-DSL api plugin is incompatible, allowing the setter to use the SigningConfig interface, but forcing getter to use the internal.dsl.SigningConfig class.
So it should be like this:
package com.android.builder.core; import com.android.builder.internal.BaseConfigImpl; import com.android.builder.model.BuildType; import com.android.builder.model.SigningConfig; public class DefaultBuildType extends BaseConfigImpl implements BuildType { ... public BuildType setSigningConfig(SigningConfig signingConfig) { mSigningConfig = signingConfig; return this; } @Override public SigningConfig getSigningConfig() { return mSigningConfig; } }
But then, the value of BuiltTypeDSL is forcibly applied to the SigningConfigDSL class:
package com.android.build.gradle.internal.dsl import com.android.builder.core.DefaultBuildType public class BuildType extends DefaultBuildType implements Serializable { ... @Override SigningConfig getSigningConfig() { return (SigningConfig) super.signingConfig } }
Note that both getSigningConfig() methods have a return type with the same SigningConfig name, but different packagename. One of them is the com.android.builder.model.SigningConfig interface, and the other is the com.android.build.gradle.internal.dsl.SigningConfig class, which extends com.android.builder.signing.DefaultSigningConfig , which implements com.android.builder.model.SigningConfig and that when my code stops working, because due to the principles of OOP, we can use DefaultSigningConfig for the SigningConfig interface but cannot pass it to the internal.dsl.SigningConfig class.
To make the code work, we can either create internal.dsl.SigningConfig instead of DefaultSigningConfig :
import com.android.build.gradle.internal.dsl.SigningConfig def signingConfig = new SigningConfig(keyProperty) // note that this is class which extends DefaultSigningConfig, not interface signingConfig.storeFile = ... // same as before signingConfig.storePassword = ... signingConfig.keyAlias = ... signingConfig.keyPassword = ... return signingConfig
or wrap DefaultSigningConfig with internal dsl model:
android{ signingConfigs { debug { initWith loadFromPropertiesFile("DEBUG_KEY_PROPERTIES") } } buildTypes { debug { signingConfig signingConfigs.debug } } }