打包发布版时报错 Error: The apk for your currently selected variant cannot be signed. Please specify a signing configuration for this variant (release).
当直接运行release版本时,报错
Error: The apk for your currently selected variant cannot be signed. Please specify a signing configuration for this variant (release).
解决报错:要在配置里添加签名
android { signingConfigs { debug { storeFile file('D:\\KotlinDemo\\MyTest\\mykeystore.jks') storePassword '123' keyPassword '123' keyAlias 'key0' } release { storeFile file('D:\\KotlinDemo\\MyTest\\mykeystore.jks') storePassword '123' keyAlias 'key0' keyPassword '123' } } namespace 'com.example.mytest' compileSdk 33 defaultConfig { applicationId "com.example.mytest" minSdk 21 targetSdk 33 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }
解决步骤
点击右侧File → Project Structure →Modules →app→加号 添加名为release的签名配置,填写完点击OK
再点击Build Variants →app →Build Types → release(如果没有就点击加号添加)→Signing Config →选择刚才的release →OK
我们会看到app下的build.gradle增加了,以下代码,问题就解决了