Android Studio 3.5.2 - 错误:您当前选择的变体 (app-release-unsigned.apk) 的 apk 未签名

JJJ*_*860 10 android android-studio android-buildconfig

一点背景。我几个月来一直在构建/调试/测试我的简单应用程序,没有任何问题。在 AVD 或我的实际 S9 手机上构建/安装。几个月来一切都很好。现在,准备好在 Play 商店发布我的第一个测试版(我的第一个应用程序)。因此,我按照“签署”我的应用程序的说明进行操作。那行得通,我将我的应用程序包上传到了 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'
}
Run Code Online (Sandbox Code Playgroud)

单击“FIX”按钮后,我将进入“运行/调试配置”对话框。从那里开始,我完全不知道需要做什么才能解决问题。

非常感谢任何帮助。

更新:必须擦除 AVD 数据并进行冷启动,问题解决了。

ozi*_*jnr 17

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

  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'
    }
    
    Run Code Online (Sandbox Code Playgroud)

用实际值替换占位符。


Ric*_*hez 11

你应该在定义它之后设置唱歌配置。虽然我想如果您打算将其用于发布,请将其命名为 debug 以外的其他名称:

buildTypes {
        release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

           signingConfig signingConfigs.debug
        }
    }
Run Code Online (Sandbox Code Playgroud)


Sur*_*r D 6

请确认以下各点均正常。

  1. 在左侧项目面板中
  • 单击应用程序并打开“打开模块设置”
  • 在let面板中选择Module并选择app
  • 在右侧面板中,您可以看到 3 个选项卡(属性、默认配置和签名配置)
  1. 在签名配置中检查下面的想法(如果您没有,请创建新密钥)
  • 在存储文件中设置 jks 文件位置
  • 还设置存储密码别名和密钥密码

在此输入图像描述

  1. 在默认配置中 - 只需检查您的应用程序 ID 是否正确

  2. 现在在左侧面板中检查以下想法

  • 选择“构建变体”并向下滚动到“签名配置”
  • 检查您是否选择了任何一个或请选择$signingConfigs.release

在此输入图像描述