Android studio-给gradle添加签名配置 [英] Android studio- adding signing configurations to gradle

查看:36
本文介绍了Android studio-给gradle添加签名配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 android 世界很陌生,我试图在我的手机上运行一个简单的 hello world 应用程序.当我尝试这个时,我了解到由 android studio 生成的 APK 是未签名的.因此,为了签署这个文件,我经历了创建密钥存储和私钥及其别名的过程,我成功地签署了 APK 并安装在我的手机上并运行它.

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.

然后我浏览了这个链接,将签名配置添加到gradle 使用新创建的密钥存储文件自动签署版本.我已正确按照上述链接中的步骤操作并且没有遗漏任何内容,但是当我完成我的签名配置时,我有一个错误提示

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 项目同步失败.基本功能(例如,编辑、调试)将无法正常工作.

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

错误:(19, 0) 在 SigningConfig 上找不到属性config"容器.

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

让我大吃一惊!现在我也无法手动签署我的 APK.现在,当我尝试手动签名时,它说 gradle 不同步

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

我想这个文件会帮助我解决这个错误.项目的 build.gradle.我试图理解这里提到的内容与我在进行签名配置时通过 Android Studio UI 配置的内容相同.

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

推荐答案

buildTypes.release 块中存在错误.签名配置应该是:

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

signingConfig signingConfigs.release

请注意,这是您在上面的 signingConfigs 块中命名配置的方式.

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

还要省略 buildTypes.debug 块中的签名配置(或者,如果你真的想要它,像上面那样设置).

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

这篇关于Android studio-给gradle添加签名配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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