[英]how to generate signed apk in android studio
就我而言,我有我的簽名密鑰,並且我已經使用功能菜單build--->generate signed Bundle/Apk
生成了 apk
以下是我生成此 apk 的步驟:
第1步:
第2步:
最后:
當我將這個生成的發行版 apk 放入我的真實設備時,它會運行良好。
但是當我嘗試將這個apk發送到我的應用中心時,它說我在這個apk中沒有任何簽名文件。
根據在google上發現的許多問題,我注意到我的apk中實際上根本沒有簽名文件。 Android studio 的build--->generate signed Bundle/Apk
似乎根本不起作用,只有一個沒有生成簽名的版本。
我在android開發方面很新。 我想知道我的gradle設置是否有一些錯誤。
我的應用程序有 2 個gradle.build
文件,如下圖所示:
應用程序目錄外的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
}
並且 app 目錄中的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,當您嘗試使用您的簽名密鑰生成簽名的 apk 時,您將找不到任何選擇簽名版本的選項,如下圖所示(它們都有這兩個選項)。
構建完成后,APK可以在我的設備上運行並且運行正常,但我無法將其部署到應用商店,因為應用商店告訴我我在META-INF中沒有簽名文件。
解決方案是在build.gradle
Explicitly specify
的簽名策略,這里是代碼。 重要的代碼是
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.....
}
再次嘗試運行生成簽名的apk,問題解決,部署到應用商店成功。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.