首页 > 解决方案 > Android Studio 3.5.2 - 错误:您当前选择的变体 (app-release-unsigned.apk) 的 apk 未签名

问题描述

一点背景。几个月来我一直在构建/调试/测试我的简单应用程序,没有任何问题。在 AVD 或我实际的 S9 手机上构建/安装。几个月来一切都很好。现在,准备好在 Play 商店中发布我的第一个 beta 版本(我的第一个应用程序)。所以,我按照“签署”我的应用程序的说明进行操作。那行得通,我将我的应用程序包上传到了 Play 商店。现在我再也无法在 Android Studio 中构建/调试/安装了。

错误:您当前选择的变体 (app-release-unsigned.apk) 的 apk 未签名。请为此变体(版本)指定签名配置。

在此处输入图像描述

调试 (Shift+F9) 产生上述错误并显示“编辑配置”对话框。

在此处输入图像描述

我点击“修复”按钮,从那里我不知道该怎么做。或者如何使用这些不同的构建配置。

在此处输入图像描述

构建.gradle

apply plugin: 'com.android.application'

android {
    signingConfigs {
        debug {
            storeFile file(var)
            storePassword 'xxx'
            keyAlias = 'xxx'
            keyPassword 'xxx'
        }
    }
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.birdersdiary.mobile"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "b1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.preference:preference:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

单击“修复”按钮后,我将进入“运行/调试配置”对话框。从那里开始,我完全忘记了为了解决问题需要发生什么。

非常感谢任何帮助。

标签: androidandroid-studioandroid-buildconfig

解决方案


您可以通过执行以下任何操作来解决此问题

  1. 您需要将构建变体切换回调试,您可以通过在 Windows 上按住 Ctrl+Alt+A 或在 Mac 上按住 CMD+ALT+A 然后variant在搜索栏中输入,选择来执行此操作build variant,这将在左侧显示构建变体选项在您的 android studio 屏幕的一侧,那么您应该选择名称附加了调试的变体。

  2. 如果您想使用发布版本,您需要指示 android studio 如何找到密钥来签署 apk 将其添加到您的应用程序级build.gradle文件

    apply plugin: 'com.android.application'
    
    android {
     signingConfigs {
        debug {
            storeFile file(var)
            storePassword 'xxx'
            keyAlias = 'xxx'
            keyPassword 'xxx'
        }
        release {
            storeFile file(var)
            storePassword 'xxx'
            keyAlias = 'xxx'
            keyPassword 'xxx'
        }
    }
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.birdersdiary.mobile"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "b1.0"
        testInstrumentationRunner     "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
     }
    
    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.preference:preference:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    }
    

用实际值替换占位符。


推荐阅读