在我的例子中,我有我的签名 key ,并且我已经使用功能菜单生成了 apkbuild--->generate signed Bundle/Apk
以下是我生成此 apk 的步骤:
第 1 步:
第 2 步:
最后:
当我把这个生成的release apk放到我的真实设备上时,它会很好地工作。
但是当我试图将这个apk发送到我的申请中心时,它说我在这个apk中没有任何签名文件。
根据在google上发现的许多问题,我注意到我的apk中实际上根本没有签名文件。似乎 Android studio 的 build--->generate signed Bundle/Apk
根本不起作用,只有一个没有生成签名的版本。
我是 android 开发的新手。我想知道我的 gradle 设置是否有错误。
我的应用程序有 2 个 gradle.build
文件,如下图所示:
app 目录外的 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
}
应用目录中的gradle.build
文件是:
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'
}
不知道为什么不能生成带签名的apk...
最佳答案
感谢 @Raj Suvariya
和 @Nitish
根据他们的善意指示,问题得到了解决。我如何解决这个问题如下所示:
首先,我使用的是 AS 版本
Android Studio Arctic Fox | 2020.3.1 Patch 3
如果您使用相同的 AS,当您尝试使用您的签名 key 生成签名的 apk 时,您将找不到任何选择签名版本的选项,如下图所示(它们都有这 2 个选项)。
完成构建后,APK 可以在我的设备中运行并且工作正常,但我无法将其部署到应用商店,因为应用商店告诉我我在 META-INF 中没有签名文件。
解决方案是在 build.gradle
中明确指定
签名策略,代码如下。重要的代码是
v1SigningEnabled true
v2SigningEnabled true
这是我的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.....
}
再次尝试运行generate signed apk,问题解决,部署到应用商店成功。
关于android - 如何在android studio中生成签名的apk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69738029/