如何在android studio中生成签名的apk

wil*_*iam 3 android gradle apk android-studio

就我而言,我有签名密钥,并且已生成带有功能菜单的 apkbuild--->generate signed Bundle/Apk

以下是生成此 apk 的步骤:

第 1 步:

在此输入图像描述

第2步:

在此输入图像描述

最后:

在此输入图像描述

当我将这个生成的发布 apk 放入我的真实设备时,它会运行良好。

但是当我尝试将此 apk 发送到我的应用程序中心时,它说我此 apk 中没有任何签名文件。

根据google上发现的许多问题,我注意到我的apk中实际上根本没有签名文件。看来Android studiobuild--->generate signed Bundle/Apk根本不起作用,只有一个没有生成签名的版本。

我对 Android 开发还很陌生。我想知道我的gradle设置是否有错误。

我的应用程序有 2 个gradle.build如下图所示的文件: 在此输入图像描述

gradle.build应用程序目录的外侧是 :

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.3'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Run Code Online (Sandbox Code Playgroud)

gradle.buildapp目录内的文件是:

apply plugin: 'com.android.application'

android {
    signingConfigs {
        debug {
            storeFile file('D:\\CodeRepository\\app-key-store\\SimpleSender.jks')
            storePassword '123123123'
            keyAlias 'simple-sender-key'
            keyPassword '123123123'
        }
    }
    compileSdkVersion 30
    buildToolsVersion "30.0.0"

    defaultConfig {
        applicationId "com.example.simplesender"
        minSdkVersion 25
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    buildFeatures {
        viewBinding true
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.annotation:annotation:1.2.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.9.2'
    implementation group: 'com.alibaba', name: 'fastjson', version: '1.2.78'
    implementation group: 'com.google.guava', name: 'guava', version: '31.0.1-android'
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'

}

Run Code Online (Sandbox Code Playgroud)

我不知道为什么我无法生成带有签名的apk...

wil*_*iam 8

感谢您@Raj Suvariya@Nitish

问题已根据他们的善意指示得到解决。我如何解决这个问题如下所示:

首先我使用的是 AS 版本

Android Studio Arctic Fox | 2020.3.1 Patch 3
Run Code Online (Sandbox Code Playgroud)

如果您使用相同的 AS,当您尝试使用签名密钥生成签名 apk 时,您将找不到任何选择签名版本的选项,如下图所示(它们都有这 2 个选项)。

在此输入图像描述

构建完成后,APK 可以在我的设备中运行并且工作正常,但我无法将其部署到应用程序商店,因为应用程序商店告诉我 META-INF 中没有签名文件。

解决方案是Explicitly specify像这样的签名策略build.gradle,这里是代码。重要的代码是

            v1SigningEnabled true
            v2SigningEnabled true
Run Code Online (Sandbox Code Playgroud)

这是我的build.gradle文件

apply plugin: 'com.android.application'

android {
    signingConfigs {
        debug {
            storeFile file('D:\\CodeRepository\\app-key-store\\SimpleSender.jks')
            storePassword 'xxx'
            keyAlias 'simple-sender-key'
            keyPassword 'xxx'
            v1SigningEnabled true
            v2SigningEnabled true
        }
        release {
            storeFile file('D:\\CodeRepository\\app-key-store\\SimpleSender.jks')
            storePassword 'xxx'
            keyAlias 'simple-sender-key'
            keyPassword 'xxx'
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }

.....your other configs.....

}
Run Code Online (Sandbox Code Playgroud)



再次尝试运行生成签名的 apk,问题解决,部署到应用商店成功。