简体   繁体   English

Flutter 发布 apk 未被 Google Play 控制台接受

[英]Flutter release apk not accepted by Google Play Console

I created a key and keystore and signed my apk, following the instructions step by step from the official flutter page.我按照官方 flutter 页面上的说明一步一步创建了一个密钥和密钥库并签署了我的 apk。

But when I try to upload it to Google Play Console, I get this error:但是当我尝试将它上传到 Google Play Console 时,出现了这个错误:

"You uploaded an APK or Android App Bundle that was signed in debug mode. You need to sign your APK or Android App Bundle in release mode" “您上传了一个在调试模式下签名的 APK 或 Android App Bundle。您需要在发布模式下签署您的 APK 或 Android App Bundle”

A similar question is asked before, but it did not solve my issue.之前有人问过类似的问题,但没有解决我的问题。

Here is the relevant part of my app/build.gradle:这是我的 app/build.gradle 的相关部分:

android {
compileSdkVersion 28

lintOptions {
    disable 'InvalidPackage'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "my.package.name"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    //testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile file(keystoreProperties['storeFile'])
        storePassword keystoreProperties['storePassword']
    }
}

buildTypes {
    release {
        signingConfig signingConfigs.release

        minifyEnabled true
        useProguard true

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

Here is the screenshot of my Android Studio versions (Android SDK being red is not relevant.):这是我的 Android Studio 版本的屏幕截图(Android SDK 为红色与此无关。):

显示所用版本的 Android Studio 屏幕截图。

My output.json file:我的 output.json 文件:

[
  {
    "outputType": {
      "type": "APK"
    },
    "apkInfo": {
      "type": "MAIN",
      "splits": [
        
      ],
      "versionCode": 1,
      "versionName": "1.0.0",
      "enabled": true,
      "outputFile": "app-release.apk",
      "fullName": "release",
      "baseName": "release"
    },
    "path": "app-release.apk",
    "properties": {
      
    }
  }
]

No suggestions seemed to be working.似乎没有任何建议有效。 Then, a然后,一个

flutter clean扑干净

and all issues were solved.并且所有问题都解决了。 I could create an apk either through Android Studio or the command line.我可以通过 Android Studio 或命令行创建一个 apk。 Thanks to VikaS and Harsha pulikollu感谢 VikaS 和 Harsha pulikollu

You need to select release option while building APK您需要在构建 APK 时选择release选项

For Windows对于 Windows

在此处输入图片说明

For Apple对于苹果

在此处输入图片说明

flutter clean did not work for me either. flutter clean对我也不起作用。 So I manually signed the apk and it was accepted by Google Play Console.所以我手动签署了 apk 并被 Google Play Console 接受。 Found the directions here https://developer.android.com/studio/publish/app-signing#sign-manually在这里找到方向https://developer.android.com/studio/publish/app-signing#sign-manually

How to manually sign apk如何手动签署apk

To manually sign the apk you need to run the following commands in a terminal o in command prompt in Windows.要手动签署 apk,您需要在 Windows 的命令提示符下的终端 o 中运行以下命令。

1 - Make sure the apk is signed with debug keys: 1 - 确保使用调试密钥对 apk 进行签名:

<build-tools-path>/<sdk-vesion>/apksigner verify --print-certs app-release.apk (replace "app-release.apk" with your apk filename" <build-tools-path>/<sdk-vesion>/apksigner verify --print-certs app-release.apk (用你的apk文件名替换“app-release.apk”

If it is signed with debug keys, the output will be similar to如果使用调试密钥签名,则输出将类似于

Signer #1 certificate DN: C=US, O=Android, CN=Android Debug
Signer #1 certificate SHA-256 digest: 384cf54f892877ea6d934bbc335bf3aa61b8dd3d89e27feb49c0bc7e62b0bbb7
Signer #1 certificate SHA-1 digest: c7a8384ff8fe2d1e99dbdba45db93180ed53b9ff
Signer #1 certificate MD5 digest: ca13ad2688257283319bf2596f360f8c

2 - Run zipalign to align first byte and reduce RAM usage 2 - 运行 zipalign 以对齐第一个字节并减少 RAM 使用

<build-tools-path>/<sdk-vesion>/zipalign -v -p 4 app-release.apk app-aligned.apk

It will list the files and finish with a Verification succesful message.它将列出文件并以Verification succesful消息结束。

3 - Run appsigner to sign the app: 3 - 运行 appsigner 来签署应用程序:

<build-tools-path>/<sdk-vesion>/apksigner sign --ks <path to .jks file> --out app-signed.apk app-aligned.apk

It will prompt for the keystore password and silently finish the job.它将提示输入密钥库密码并静默完成工作。

4 - Verify if it is signed with your keys: 4 - 验证它是否使用您的密钥签名:

<build-tools-path>/<sdk-vesion>/apksigner verify --print-certs app-signed.apk

If it is correctly signed, the output will be similar to the fist step, but instead of "Android Debug" it will output your certificate's data.如果签名正确,输出将类似于第一步,但它会输出您的证书数据,而不是“Android Debug”。

This occurs when the apk or android app bundle is signed in debug mode and uploaded.当 apk 或 android 应用程序包在调试模式下签名并上传时,会发生这种情况。

So Make sure you have release in build.gradle所以请确保您在build.gradle 中发布

buildTypes {
    release {
        minifyEnabled true
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.
        signingConfig signingConfigs.release
    }
}

as well as just put yourkeystore.jks file in android/app/yourkeystore.jks so that you don't have to mention the full path.以及只需将yourkeystore.jks文件放在android/app/yourkeystore.jks 中,这样您就不必提及完整路径。

now the path will be现在路径将是

storePassword=yourkeystore
keyPassword=yourkeystore
keyAlias=yourkeystore
storeFile=yourkeystore.jks

这些是在扑扑中找到了build-tools-pathsdkvesion吗

Try尝试

flutter clean

flutter clean command is really helpful in many scenario whenever some absurd behavior is shown by the app.每当应用程序显示一些荒谬的行为时,flutter clean 命令在许多情况下都非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM