12

I am very new to the android world and I was trying to just get to run a simple hello world app on my phone. when I tried this I learnt that the APK generated by an android studio is an unsigned one. So to sign this I have gone through the process of creating a Key store and then a private Key, its alias and I was successful in signing the APK and installing on my phone and running it too.

Then I went through this link for adding signing configurations to the gradle to automatically sign the release with the newly created key store file. I have followed the steps n the above link properly and did not miss anything but still when I finish my signing configurations I have an error saying

Gradle project sync failed.Basic functionality(eg. editing, debugging) will not work properly.

Error:(19, 0) Could not find property 'config' on SigningConfig container.

I was taken by a surprise! and now I am not able to sign my APKs manually too. Now when I try to sign manually, it says the gradle is not in sync

I guess this file will be of help to help me solve this error. build.gradle of the project. I am trying to understand is what is mentioned here is same as the one I configured through the Android Studio UI while making the signing configurations.

apply plugin: 'com.android.application'

android {
    signingConfigs {
        release {
            storeFile file("<path>\\firstKeystore.jks")
            storePassword "******"
            keyAlias "usual password"
            keyPassword "******"
        }
    }
    compileSdkVersion 19
    buildToolsVersion '20.0.0'
    defaultConfig {
        applicationId 'com.tech.vasanth.newsfeed'
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
            debuggable false
            jniDebugBuild false
            renderscriptDebugBuild false
            zipAlign true
        }
        debug {
            signingConfig signingConfigs.config
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
madhan kumar
  • 1,560
  • 2
  • 26
  • 36
Vasanth Nag K V
  • 4,860
  • 5
  • 24
  • 48
  • 1
    Does this answer your question? [How to create a release signed apk file using Gradle?](https://stackoverflow.com/questions/18328730/how-to-create-a-release-signed-apk-file-using-gradle) – VahidHoseini Apr 04 '20 at 12:40

3 Answers3

12

There is a mistake in the buildTypes.release block. The signing config should be:

signingConfig signingConfigs.release

Note, that this is how you named the configuration in the signingConfigs block above.

Also leave out the signing config in the buildTypes.debug block (or, if you really want to have it, set it like above).

Henry
  • 42,982
  • 7
  • 68
  • 84
  • i have made changes like you have suggested and now i get the error at this line in buildTypes.debug signingConfig signingConfigs.config can i remove this? – Vasanth Nag K V Oct 27 '16 at 05:17
  • oh yeah.. thank you, it worked ! one thing what i want to know is, i have given a link above right? in that i used the studio's UI to configure the signing configurations. so instead i can do it by configuring the build.gradle also? both are one and the same? – Vasanth Nag K V Oct 27 '16 at 05:21
  • Yes, the `build.gradle` file has all the information about the build. You can even build your project from the command line without opening Android Studio. – Henry Oct 27 '16 at 05:26
  • Wow that is nice to know, any pointers where i can play with the command line tools for building will be appreciated :) – Vasanth Nag K V Oct 27 '16 at 07:46
  • 1
    Just cd to the root directory of your project and execute `gradlew build` (use ./gradlew if you are on Linux). All the details can be found in the gradle documentation https://docs.gradle.org/current/userguide/userguide.html – Henry Oct 27 '16 at 07:52
  • Also I found a slight quirk, that you need to use `Build>Build APK` rather than `Build>Generate Signed APK Bundle` if you do the gradle script way of assigning the signing config. The latter option doesn't seem to work in this case – gtxtreme Jan 30 '22 at 18:46
8

I have been using below configurations for Debug/Release.

signingConfigs {
            release {
                keyAlias 'keyAlias'
                keyPassword 'keyPassword'
                storePassword 'storePassword'
                storeFile file("${rootDir}/keystores/app.keystore")
            }

            debug {
                storeFile file("${rootDir}/keystores/debug.keystore")
                keyAlias 'androiddebugkey'
                keyPassword 'android'
                storePassword 'android'
            }
        }

While defining a release module:

 buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'other-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            signingConfig signingConfigs.debug
        }
    }

Note: Here rootDir is your project root directory. Please store your keystore in mentioned directory.

AndiGeeky
  • 11,266
  • 6
  • 50
  • 66
4

structure of get a release is like this :

signingConfigs {
    release {
        storeFile file("release.keystore")
        storePassword "******"
        keyAlias "******"
        keyPassword "******"
    }
}
buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}
Nabeel
  • 455
  • 3
  • 14
VahidHoseini
  • 495
  • 2
  • 10
  • 28