Android studio- adding signing configurations to gradle

蓝咒 提交于 2020-04-28 09:44:26

问题


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'])
}

回答1:


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).




回答2:


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.




回答3:


structure of get a release is like this :

signingConfigs {
        release {
            storeFile file("release.keystore")
            storePassword "******"
            keyAlias "******"
            keyPassword "******"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }

most of programmer has



来源:https://stackoverflow.com/questions/40276327/android-studio-adding-signing-configurations-to-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!