Android Studio does not sign the code for debug build - android

Android Studio refuses to sign my code for debug build.
I have an older project which did not have any signing instructions in build.gradle, so I added these according to this Android gradle signingConfig error and other posts.
My build.gradle file on module level (the only module) looks like this (excerpt):
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "cc.appname.android"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName '1.0'
}
signingConfigs {
debug {
storeFile file('../../../.android/debug.keystore')
keyAlias 'androiddebugkey'
keyPassword 'android'
storePassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
The storeFile can be found, because when I change the path I get a compile error. When the path is correct, it compiles, but when I try to use the Facebook SDK within my app, it reports a wrong keyhash.
I noticed that signingConfigs
signingConfig signingConfigs.debug
is underlined with the error message "Cannot infer argument types..."
So I went to Project Settings in the UI, removed signing and the relationship between the build and signing, saved this, and added it back. Same problem.
I am sure this is something very small that I just overlooked, or Google renamed the command between versions, whatever.
Can anybody help?

Several things here, assuming your debug.keystore is the one from the ~/.android folder.
Change this:
debug {
storeFile file('../../../.android/debug.keystore')
keyAlias 'androiddebugkey'
keyPassword 'android'
storePassword 'android'
}
to this(store the debug.keystore in the root project):
debug {
storeFile rootProject.file('debug.keystore')
keyAlias 'androiddebugkey'
keyPassword 'android'
storePassword 'android'
}
You do not need to override the debug BuildType, it naturally signs with the debug key anyways, so you can remove:
debug {
signingConfig signingConfigs.debug
}
The final build.gradle:
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "cc.appname.android"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName '1.0'
}
signingConfigs {
debug {
storeFile rootProject.file('debug.keystore')
keyAlias 'androiddebugkey'
keyPassword 'android'
storePassword 'android'
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

Both buildTypes.debug and signingConfigs.debug exist by default.
You do not need to define buildTypes.debug unless you want to change it.
You do not need to define signingConfigs.debug unless you want to change it.
If you want to use the default debug signing for a different build type, you can do that. For example, the following works also without defining anything else:
buildTypes {
unsignedRelease {
initWith release
signingConfig signingConfigs.debug
}
}

Adding an answer for the new gradle experimental plugin since the syntax is different:
model {
android {
buildTypes {
release {
signingConfig = $("android.signingConfigs.myConfig")
...
}
}
}
android.signingConfigs {
create("myConfig") {
keyAlias = 'androiddebugkey'
keyPassword = 'android'
storeFile = new File("${System.properties['user.home']}/.android/debug.keystore")
storePassword = 'android'
storeType = "jks"
}
}
}
NOTE: the android.signingConfigs block must be placed outside of the android block.

Related

D8 does not support main-dex inputs and outputs when compiling to API level 21 and above

I am facing this error during the build:
"D8 does not support main-dex inputs and outputs when compiling to API level 21 and above"
If i set minifyEnabled to true in debug buildType everything works fine, but if i set it to false i just get this error.
My gradle file:
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.generalbytes.batm"
minSdkVersion 17
targetSdkVersion 22
multiDexEnabled true
ndk {
abiFilters 'armeabi-v7a'
}
}
useLibrary 'org.apache.http.legacy'
testOptions {
unitTests.all {
enabled !useDummyBitRafael.toBoolean()
}
}
signingConfigs {
release {
storeFile rootProject.file(releaseStoreFile)
storePassword releaseStorePassword
keyAlias releaseKeyAlias
keyPassword releaseKeyPassword
}
debug {
storeFile rootProject.file(releaseStoreFile)
storePassword releaseStorePassword
keyAlias releaseKeyAlias
keyPassword releaseKeyPassword
}
}
buildFeatures {
dataBinding = true
viewBinding = true
}
buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
lintOptions {
tasks.lint.enabled = false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests.returnDefaultValues = true
}
Any ideas?
I just click "refresh gradle dependencies" from Android studio Gradle view and then the problem disappear.

Gradle, 'could not find property'

I've tried to look for similar questions, but
no luck.
I'm building my Gradle project from the command line,
and supply the passwords in the gradle release command line
using -P.
Here's my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
}
}
apply plugin: 'android'
android {
signingConfigs {
release {
storeFile file("C:/Android/Dev/keystore/dm.keystore")
keyAlias KEY_ALIAS
storePassword STORE_PASSWORD
keyPassword KEY_PASSWORD
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
compileSdkVersion 'android-13'
buildToolsVersion '22.0.1'
buildTypes {
release {
minifyEnabled false
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
}
When I try to do a clean, it gives me:
Could not find property 'KEY_ALIAS' on SigningConfig_Decorated{name=release, storeFile=C:\Android\dev\keystore\dm.keystore, storePassword=null, keyAlias=null, keyPassword=null, storeType=C:\Android\dev\keystore\dm.keystore}.
Someone said that the 'signingConfigs' should come before the
'buildTypes', and it does.
Is there any way that I can keep the 'signingConfigs'
in there, but maybe modified somehow, and not have it complain?
If I take 'signingConfigs' out, and add it before I do the release
it works.
Thanks!
try this
def key="default"
def storePass="default"
def keyPass="default"
if (project.hasProperty("KEY_ALIAS")) {
key = KEY_ALIAS
}
if (project.hasProperty("STORE_PASSWORD")) {
storePass = STORE_PASSWORD
}
if (project.hasProperty("KEY_PASSWORD")) {
keyPass = KEY_PASSWORD
}
signingConfigs {
release {
storeFile file("C:/Android/Dev/keystore/dm.keystore")
keyAlias key
storePassword storePass
keyPassword keyPass
}
}
i also recommend you to store your signing information in separate file

Linkedin Sample demo not working

I am working to implement LinkedIn SDK into my application. I import the demo code and created the sample project on LinkedIn developer console. I also added required package name and hash. I got those two from the sample demo code.
But after adding this two when I try to run the application it always fire the below error.
{
"errorMessage":"either bundle id or packagename / hash are invalid,unknown, malformed"
"errorCode":"INVALID_REQUEST"
}
I cross checked several time for the hash and package name because this two are parameter we have to add into console.
Posible duplicate of this post. Problem is about your are not signing correctly the APK generated. Check your signingConfig in the build.gradle file.
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
versionCode 1
versionName "1.0"
}
signingConfigs {
sdkTest {
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release {
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
buildTypes {
sdkTest {
signingConfig signingConfigs.sdkTest
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
compile project(':linkedin-sdk')
}
configurations {
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
}

Override debug build type signing config with flavor signing config

I've got an Android app that has 2 flavors: internal and production, and there are 2 build types as well: debug and release.
I'm trying to assign signing configs based on the flavor, which according to the documentation is doable. I've looked and found other answers to this, but none of them seem to work. Everything compiles, but the app is being signed with the debug keystore local to my machine.
Here is my gradle file:
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0.0"
}
signingConfigs {
internal {
storeFile file("../internal.keystore")
storePassword "password"
keyAlias "user"
keyPassword "password"
}
production {
storeFile file("../production.keystore")
storePassword "password"
keyAlias "user"
keyPassword "password"
}
}
productFlavors {
internal {
signingConfig signingConfigs.internal
applicationId 'com.test.test.internal'
}
production {
signingConfig signingConfigs.production
applicationId 'com.test.test'
}
}
buildTypes {
debug {
applicationIdSuffix ".d"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
variantFilter { variant ->
if (variant.buildType.name.equals('debug')
&& variant.getFlavors().get(0).name.equals('production')) {
variant.setIgnore(true);
}
}
}
Note: I'm also compiling with classpath 'com.android.tools.build:gradle:1.1.3'
It seems that by default, Android has a signingConfig set on the debug build type (the android debug keystore), and when the signingConfig is set for the build type, the signingConfig is ignored for the flavor.
The solution is to set the signingConfig to null on the debug build type. Then the signingConfig given for the flavor will be used instead:
buildTypes {
debug {
// Set to null to override default debug keystore and defer to the product flavor.
signingConfig null
applicationIdSuffix ".d"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

Signing product flavors with gradle

I am tyring to migrate my projects to gradle. One of my projects has multiple product flavors and each one of them has to be signed with a different signingConfig in its release version. So this is what I tried so far:
buildscript {
...
}
apply plugin: 'android'
android {
compileSdkVersion 17
buildToolsVersion '17'
signingConfigs {
flavor1 {
storeFile file("keystore")
storePassword "secret"
keyAlias "aliasForFlavor1"
keyPassword "secretFlavor1"
}
flavor2 {
storeFile file("keystore")
storePassword "secret"
keyAlias "aliasForFlavor2"
keyPassword "secretFlavor2"
}
}
productFlavors {
flavor1 {
signingConfig signingConfigs.flavor1
}
flavor1 {
signingConfig signingConfigs.flavor2
}
}
}
dependencies {
...
}
When I run gradle build I get a groovy.lang.MissingFieldException and the following error message:
No such field: signingConfigs for class: com.android.build.gradle.internal.dsl.GroupableProductFlavorFactory
So I assume the productFlavors.* part of the Gradle script is not the right place to put code signing configurations.
You can declare signing config for each flavor in buildType. Here is my gradle file for release signing flavors with different keystores.
android {
signingConfigs {
configFirst {
keyAlias 'alias'
keyPassword 'password'
storeFile file('first.keystore')
storePassword 'password'
}
configSecond {
keyAlias 'alias'
keyPassword 'password'
storeFile file('second.keystore')
storePassword 'password'
}
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
}
productFlavors{
flavor1 {
applicationId "com.test.firstapp"
}
flavor2 {
applicationId "com.test.secondapp"
}
}
buildTypes {
release {
productFlavors.flavor1.signingConfig signingConfigs.configFirst
productFlavors.flavor2.signingConfig signingConfigs.configSecond
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
buildTypes block should be placed after productFlavors block, I mean order is important.
Per the user guide, signingConfigs for flavors are supported.
The problem here has to do with the scope of the signingConfigs object. I just assigned it to a variable inside the productFlavors block, but outside the flavor1 flavor block to fix the issue:
productFlavors {
def flavor1SigningVariable = signingConfigs.flavor1
flavor1 {
...
signingConfig flavor1SigningVariable
...
}
The gradle plugin for android only supports signing per build type, not per flavor. The reason for this is that any given variant (build type + flavors) can only be signed by one key, but can be a combination of several flavor groups. For example your flavor groups could be cpu (x86/arm) and version (free/paid), that's four different variants right there.
The solution you're looking for is to create separate build types for your different release versions. For example, your build types might be debug, release, release-beta, like this:
...
android {
...
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.release
}
release-beta {
initWith release
signingConfig signingConfigs.release-beta
}
}
}
The initWith above just tells gradle that release-beta should be a copy of the release build type, only signed with a different key.
Maybe another interesting solution with dynamic flavor signing configs and other advantages
Im fine with defining app id and app name of flavors in gradle (it is clear and just 2 lines for each flavor) but I do not want to define separate signing configs (gradle file would be too long when adding flavors)
I also do not want to have sensitive signing information placed in gradle because of commiting it
Bonus advantage is that debug build has another app id and app name.
.gitignore
...
/keystore.properties
.keystore.properties
storeFile=../mystore.jks
storePassword=...
keyAliasFlavor1=...
keyPasswordFlavor1=...
keyAliasFlavor2=...
keyPasswordFlavor2=...
app/build.gradle
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(rootProject.file('keystore.properties')))
android {
...
buildTypes {
debug {
...
manifestPlaceholders = [appNameSuffix: " Dev"]
applicationIdSuffix ".dev"
}
release {
...
manifestPlaceholders = [appNameSuffix: ""]
productFlavors.all { flavor ->
flavor.signingConfig = android.signingConfigs.create("${flavor.name}")
flavor.signingConfig.storeFile = rootProject.file(keystoreProperties["storeFile"])
flavor.signingConfig.storePassword = keystoreProperties["storePassword"]
flavor.signingConfig.keyAlias = keystoreProperties["keyAlias${flavor.name}"]
flavor.signingConfig.keyPassword = keystoreProperties["keyPassword${flavor.name}"]
}
}
}
productFlavors {
Flavor1 {
applicationId "..."
manifestPlaceholders = [appNameBase: "MyApp 1"]
}
Flavor2 {
applicationId "..."
manifestPlaceholders = [appNameBase: "MyApp 2"]
}
// ... and many other flavors without taking care about signing configs
// (just add two lines into keystore.properties for each new flavor)
}
}
app/src/main/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
...
<application android:label="${appNameBase}${appNameSuffix}" ...>
...
</application>
</manifest>
This is the Kotlin DSL equivalent of ashakirov's answer:
// See https://stackoverflow.com/q/60474010
fun getLocalProperty(key: String) = gradleLocalProperties(rootDir).getProperty(key)
fun String?.toFile() = file(this!!)
// Could also use System.getenv("VARIABLE_NAME") to get each variable individually
val environment: Map<String, String> = System.getenv()
android {
signingConfigs {
create("MyFirstConfig") {
keyAlias = getLocalProperty("signing.keyAlias") ?: environment["SIGNING_KEY_ALIAS"]
storeFile = (getLocalProperty("signing.storeFile") ?: environment["SIGNING_STORE_FILE"]).toFile()
keyPassword = getLocalProperty("signing.keyPassword") ?: environment["SIGNING_KEY_PASSWORD"]
storePassword = getLocalProperty("signing.storePassword") ?: environment["SIGNING_STORE_PASSWORD"]
enableV1Signing = true
enableV2Signing = true
}
create("MySecondConfig") {
keyAlias = getLocalProperty("signing.keyAlias2") ?: environment["SIGNING_KEY_ALIAS2"]
storeFile = (getLocalProperty("signing.storeFile2") ?: environment["SIGNING_STORE_FILE2"]).toFile()
keyPassword = getLocalProperty("signing.keyPassword2") ?: environment["SIGNING_KEY_PASSWORD2"]
storePassword = getLocalProperty("signing.storePassword2") ?: environment["SIGNING_STORE_PASSWORD2"]
enableV1Signing = true
enableV2Signing = true
}
}
productFlavors {
create("flavor1") {
// ...
}
create("flavor2") {
// ...
}
}
buildTypes {
getByName("release") { // OR simply release { in newer versions of Android Gradle Plugin (AGP)
productFlavors["flavor1"].signingConfig = signingConfigs["MyFirstConfig"]
productFlavors["flavor2"].signingConfig = signingConfigs["MySecondConfig"]
// OR alternative notation
// productFlavors {
// getByName("flavor1") {
// signingConfig = signingConfigs["MyFirstConfig"]
// }
// getByName("flavor2") {
// signingConfig = signingConfigs["MySecondConfig"]
// }
// }
}
}
}
Split signing configs between Gms and Hms builds
Just for future ref if anyone has to split their signing configs between Gms and Hms builds.
This adds on the the answer listed here:
Maybe another interesting solution with dynamic flavor signing configs and other advantages
build.gradle
Option 1
gradle.startParameter.getTaskNames().each()
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
signingConfigs {
release {
storeFile file(keystoreProperties["RELEASE_STORE_FILE"])
storePassword keystoreProperties["RELEASE_STORE_PASSWORD"]
keyAlias keystoreProperties["RELEASE_KEY_ALIAS"]
keyPassword keystoreProperties["RELEASE_KEY_PASSWORD"]
}
releaseHms {
storeFile file(keystoreProperties["RELEASE_HMS_STORE_FILE"])
storePassword keystoreProperties["RELEASE_STORE_PASSWORD"]
keyAlias keystoreProperties["RELEASE_KEY_ALIAS"]
keyPassword keystoreProperties["RELEASE_KEY_PASSWORD"]
}
debug {
// use default debug key to sign
}
}
buildTypes {
release {
...
gradle.startParameter.getTaskNames().each { task ->
if (task.toLowerCase().contains("gms")) {
signingConfig signingConfigs.release
}
if (task.toLowerCase().contains("hms") {
signingConfig signingConfigs.releaseHms
}
}
}
debug {
...
gradle.startParameter.getTaskNames().each { task ->
if (task.toLowerCase().contains("gms")) {
signingConfig signingConfigs.debug
}
if (task.toLowerCase().contains("hms") {
signingConfig signingConfigs.releaseHms
}
}
flavorDimensions "serviceplatform"
productFlavors {
hms {
dimension "serviceplatform"
applicationIdSuffix ".huawei"
versionNameSuffix "-huawei"
}
gms {
dimension "serviceplatform"
applicationIdSuffix ".android"
}
}
sourceSets {
main {
res.srcDirs = [
"src/main/res",
"src/main/res/layout/toolbar",
"src/main/res/layout/fragment",
"src/main/res/layout/activity"
]
}
gms {
java.srcDir("src/gms/java")
}
hms {
java.srcDir("src/hms/java")
}
}
Option 2
productFlavors.gms.signingConfig
Ensure your flavorDimensions is before buildTypes
flavorDimensions "serviceplatform"
productFlavors {
hms {
...
}
gms {
...
}
}
buildTypes {
release {
...
productFlavors.gms.signingConfig signingConfigs.release
productFlavors.hms.signingConfig signingConfigs.releaseHms
}
debug {
...
productFlavors.gms.signingConfig signingConfigs.debug
productFlavors.hms.signingConfig signingConfigs.releaseHms
}
}

Categories

Resources