错误:您当前选择的变体(未知输出)的 apk 未签名。请为此变体指定签名配置(调试)

问题描述 投票:0回答:9

升级到 Android Studio Arctic Fox (2020.3.1) Canary 9 后,我无法运行测试。它会弹出

Edit Configurations
窗口以显示
Error: The app for your currently selected variant (Unknown output) is not signed. Please specify a signing configuration for this variant (debug).
消息。我似乎无法仅通过创建
.jks
并使用调试变体的发布签名配置来解决这个问题,就像大多数建议的帖子一样。我有点犹豫是降级还是尝试以某种方式解决它。以前有人遇到过这个问题吗?欢迎任何建议和意见。

Android Studio Arctic Fox (2020.3.1) Canary 10 版本也存在问题。

android android-studio unit-testing android-instrumentation build-variant
9个回答
203
投票

我也遇到过这种情况,可能是因为升级到 Gradle 7.0.0 后修改了默认签名配置。您无需降级 Gradle 即可修复此问题。要做到这一点,

转到文件菜单 > 项目结构Step Reference Image 1

然后转到模块部分 Step Reference Image 2

然后前往默认配置选项卡 Step Reference Image 3

向下滚动到签名配置,然后单击下拉菜单 Step Reference Image 4

从下拉列表中选择$signingConfigs.debug Step Reference Image 5

单击应用,然后单击确定,然后再次运行您的应用程序。

这解决了我的问题。希望它也适合你。


46
投票

对我有用的是在应用程序级别 build.gradle 上添加以下内容(对于本示例中的“release”变体):


android{
   
   signingConfigs {
       release {
           storeFile file("path to your keystore file")
           storePassword "your store password "
           keyAlias "your keystore alias"
           keyPassword "your key password"
       }
   }

   buildTypes {
       release {
           ...
           ...
           signingConfig signingConfigs.release
       }
   }   

}

16
投票

我遇到了同样的问题并看到了你的帖子。 幸运的是,我能够修复它。请按照以下步骤操作: 构建变体(左下角)> 活动构建变体 > 将其改回调试


5
投票

在应用程序级别的 build.gradle 文件中添加

defaultConfig{
    ...

    signingConfig signingConfigs.debug
}

defaultConfig 块内


1
投票

确保您没有在应用程序级别 build.grade 中使用signingConfig,或者尝试使用菜单栏中文件选项中的无效缓存/重新启动选项。


1
投票

如果 Android Gradle Plugin (AGP) 高于

7.0.0-alpha08
,则会出现此问题。所以降级到
7.0.0-alpha08
就可以解决问题。通过这样做,您还必须降级到 Android Studio Arctic Fox (2020.3.1) Canary 8,因为更高版本需要其相应的 AGP 或最新版本。我对降级解决方案不满意。但这是目前运行测试的唯一方法。

Android Studio 档案


0
投票

此问题现已在最新的 Android Studio 预览版(2020.3.1 Canary 15)中修复,使用 AGP 版本

7.0.0-alpha15


0
投票

对于 Kotlin dsl,请将其添加到您的 BuildType 部分中:

signingConfig = signingConfigs.getByName("debug")

0
投票

每个应用程序都需要使用密钥签名才能安装在设备上。 Android studio 自动签署

debug
构建,但如果您想安装
release
apk,则必须对其进行签名。

所以有不同的方式来签署apk。

方法 1: 使用

debug
凭据来签署
release
apk。在
app/build.gradle
文件中,您可以定义一个变量,如下所示:

android {
    // ...

    defaultConfig {
        // ...
        signingConfig signingConfigs.debug
    }
}

注意: 这只会使用与

release
签名相同的凭据来签署您的
debug
apk。在为发行版生成 aab 或 apk 时请记住这一点。

方法二:您也可以在

release
中单独对
app/build.gradle
apk进行签名。您还可以使用问题中所示的 GUI 进行签名:

android{
   // ...
   signingConfigs {
       // ...
       release {
           storeFile file("key-store-file-path")
           storePassword "key-store-password "
           keyAlias "key-alias"
           keyPassword "key-password"
       }
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.