已尝试针对此问题找到的所有其他答案:您的 Android App Bundle is signed with the wrong key。确保您的 App Bundle 已签名 [..]

Have tried all other answers found for this problem: Your Android App Bundle is signed with the wrong key. Ensure that your App Bundle is signed [..]

我正在尝试将全新的应用程序上传到 Play 商店,但遇到了错误 "Your Android App Bundle is signed with the wrong key. Ensure that your App Bundle is signed with the correct signing key and try again"。我已尽力遵守并理解说明,并相信我已遵守。

https://developer.android.com/studio/publish/app-signing#generate-key 我完成了这些步骤并创建了一个新的 keystore.jks 文件。然后我继续下一步并使用相同的密钥签署我的应用程序,提供用于创建它的相同密码。我将它们的密钥别名保留为默认的 key0,并勾选了 'Export encrypted key for enrolling published apps in Google Play App Signing',尽管我还没有机会使用它导出的文件。我确保构建类型设置为发布,而不是调试,并制作了我的 app-release.aab 文件。

然后我继续进入下一节 'Opt in to app signing by Google Play'/'Opt in a new app'。第 1 步包含在我之前采取的步骤中。然后我登录到开发者帐户并导航到我设置的应用程序(只有一个与该帐户相关联),然后从右侧的导航转到应用程序发布页面。

我向下滚动到 'Internal test track' 并编辑版本。它设置为编辑而不是创建,因为最初我尝试上传一个 React Native 0.57 应用程序,发现我必须将它更新到更新的版本,然后商店才会接受它。我保留了名称和“此版本中有什么新功能?”部分,但删除了之前存在的应用程序并保存了页面。我还确保从 Artifact 库中删除了这个以前的版本,它现在是空的。

当我尝试上传我的 app-release.aab 文件时,我被告知 "Your Android App Bundle is signed with the wrong key. Ensure that your App Bundle is signed with the correct signing key and try again: SHA1: [...]"。这就是我现在卡住的地方。

我研究和尝试过的事情:

  1. 我已经尝试清理项目并重新创建密钥库文件并用它重建应用程序。同样错误的键结果。
  2. 我已经更改了 .jks 文件的位置,以防在其中进行一些缓存。同样错误的密钥结果。
  3. 我尝试从 android/app/debug.keystore 中删除 debug.keystore 文件,AS 不喜欢那样,没有它就无法成功构建包
  4. 我检查了一些可能已在 .gradle 文件中设置的可调试属性,debuggable = true 和 testCoverageEnabled = true(或其他一些值)。这些都没有设置。
  5. 我已确保通过上述步骤创建和签名时使用了相同的密码。同样错误的键结果。
  6. 哭着放弃。同样错误的键结果。
  7. 我了解到,在 gradle 文件中的任何位置指定 signingConfig 将覆盖您在捆绑包创建期间所做的选择,并且已将其注释掉以用于发布构建类型。上传后我被告知我的应用程序未签名。
  8. 我没有使用 AS,而是遵循了本指南:https://facebook.github.io/react-native/docs/signed-apk-android 并制作了一个 appname.keystore 文件,signingConfigs { release {..}} 为此条目并通过命令行创建 .aab gradlew bundleRelease 按照指示上传,然后上传。同样错误的键结果。

我完全迷路了。我不知道下一步该做什么。我发现和尝试的一切都失败了,我找不到更多的东西可以尝试了。请帮助我。

以下是我的 gradle 个文件:

android\app\build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
 *   bundleCommand: "ram-bundle",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.[..]"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        missingDimensionStrategy 'react-native-camera', 'general'
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }

        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation "com.google.android.gms:play-services-gcm:12.+"

    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.android.support:appcompat-v7:XX.X.+'

    implementation 'com.android.support:multidex:1.0.3'

    androidTestImplementation 'androidx.annotation:annotation:1.0.0'

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

android\build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        googlePlayServicesVersion = "16.+"
        firebaseVersion = "17.3.4"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:3.5.2')
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

project.configurations.all {
    resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.android.support'
                && !details.requested.name.contains('multidex') ) {
            details.useVersion "26.+"
        }
        if (details.requested.group == 'com.google.android.gms'
        && !details.requested.name.contains('multidex') && (
            !details.requested.name.contains('play-services-stats') ||
            !details.requested.name.contains('play-services-vision-image-label') ||
            !details.requested.name.contains('play-services-clearcut') ||
            !details.requested.name.contains('play-services-flags') ||
            !details.requested.name.contains('play-services-phenotype')
            )) {
            details.useVersion "12.+"
        }
        if (details.requested.group == 'com.google.android.gms'
        && !details.requested.name.contains('multidex') && (
            details.requested.name.contains('play-services-stats') ||
            details.requested.name.contains('play-services-vision-image-label') ||
            details.requested.name.contains('play-services-clearcut') ||
            details.requested.name.contains('play-services-flags') ||
            details.requested.name.contains('play-services-phenotype')
            )) {
            details.useVersion "+"
        }
        if (details.requested.group == 'com.google.firebase'
        && !details.requested.name.contains('multidex') && details.requested.name.contains('firebase-messaging')) {
            details.useVersion "12.+"
        }
    }
}

ext {
    googlePlayServicesVersion = "+" // default: "+"
    firebaseVersion = "+" // default: "+"
    // Other settings
    compileSdkVersion = 28 // default: 23
    buildToolsVersion = "28.0.3" // default: "23.0.1"
    targetSdkVersion = 28 // default: 23
    supportLibVersion = "28.0.0"
}

gradle.properties:

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

org.gradle.jvmargs=-Xmx4608m
android.useAndroidX=true
android.enableJetifier=true

MYAPP_UPLOAD_STORE_FILE=[...].keystore
MYAPP_UPLOAD_KEY_ALIAS=[...]
MYAPP_UPLOAD_STORE_PASSWORD=[...]
MYAPP_UPLOAD_KEY_PASSWORD=[...]

所以,这听起来好像您已经创建并签署了您的应用程序的 React Native 版本,具有相同的包标识符,并且尝试过,and/or 成功将二进制文件上传到您的 Google玩控制台。现在,您正尝试上传另一个二进制文件,使用不同的密钥签名,但具有相同的包标识符。对吗?

如果是这样,您将不得不将 App Name 和 Bundle Identifier 更改为全新的东西(除非您找到了一种方法来从您的控制台中完全删除所有以前对您的项目的引用并且 'add'而不是 'edit',我认为这是不可能的)。

此外,您应该检查您使用什么日期作为您的 'Release' 密钥库的到期日期。通常,他们有一个建议您使用的最大日期,大约是未来 100 年,但您必须 google 他们建议的确切日期。如果您的发布密钥库过早过期,您将无法在过期后构建发布版本。