如何签名Flutter应用捆绑包以将其发布到Play Store?

huangapple go评论82阅读模式
英文:

How to sign Flutter app bundle in order to publish it to Play Store?

问题

我正在遵循这份指南,以打开Android Studio并选择 点击 Build > Generate Signed Bundle/APK

在Android Studio中没有 Build > Generate 菜单:

如何签名Flutter应用捆绑包以将其发布到Play Store?

我的Android Studio版本是最新的:

Android Studio Flamingo | 2022.2.1 Patch 2
Build #AI-222.4459.24.2221.10121639,构建于2023年5月12日
运行时版本:17.0.6+0-17.0.6b802.4-9586694 aarch64
VM:由JetBrains s.r.o.提供的OpenJDK 64位服务器VM
macOS 13.4
GC:G1 Young Generation,G1 Old Generation
内存:2280M
核心数:10
Metal渲染已启用
注册表:
    dart.server.additional.arguments=autosnapshotting-thresholdMb-200,increaseMb-100,dir-/Users/polinach/Downloads/analyzer_snapshots,dirLimitMb-10000,delaySec-20
    actionSystem.assertFocusAccessFromEdt=false
    external.system.auto.import.disabled=true
    actionSystem.fix.alt.gr=false
    actionSystem.getContextByRecentMouseEvent=true
    ide.text.editor.with.preview.show.floating.toolbar=false
    gradle.version.catalogs.dynamic.support=true

非捆绑插件:
    Dart (222.4582)
    io.flutter (74.0.2)

我漏掉了什么?

英文:

I am following the guidance to open Android Studio and to select click Build > Generate Signed Bundle/APK.

There is no menu Build > Generate in Android Studio:

如何签名Flutter应用捆绑包以将其发布到Play Store?

My Android Studio is freshest:

Android Studio Flamingo | 2022.2.1 Patch 2
Build #AI-222.4459.24.2221.10121639, built on May 12, 2023
Runtime version: 17.0.6+0-17.0.6b802.4-9586694 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.4
GC: G1 Young Generation, G1 Old Generation
Memory: 2280M
Cores: 10
Metal Rendering is ON
Registry:
    dart.server.additional.arguments=autosnapshotting-thresholdMb-200,increaseMb-100,dir-/Users/polinach/Downloads/analyzer_snapshots,dirLimitMb-10000,delaySec-20
    actionSystem.assertFocusAccessFromEdt=false
    external.system.auto.import.disabled=true
    actionSystem.fix.alt.gr=false
    actionSystem.getContextByRecentMouseEvent=true
    ide.text.editor.with.preview.show.floating.toolbar=false
    gradle.version.catalogs.dynamic.support=true

Non-Bundled Plugins:
    Dart (222.4582)
    io.flutter (74.0.2)

What am I missing?

答案1

得分: 1

在macOS或Linux上,使用以下命令:

keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA \
    -keysize 2048 -validity 10000 -alias upload

在Windows上,在PowerShell中使用以下命令:

keytool -genkey -v -keystore %userprofile%\upload-keystore.jks ^
    -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 ^
    -alias upload

注意:
keytool命令可能不在您的路径中 - 它是Java的一部分,作为Android Studio的一部分安装。对于具体的路径,请运行flutter doctor -v并找到在“Java binary at:”后打印的路径。然后使用该完全限定路径替换java(末尾)中的keytool。如果您的路径包含以空格分隔的名称,例如Program Files,请使用适合平台的名称表示法。例如,在Mac/Linux上使用Program\ Files,在Windows上使用"Program Files"。

-storetype JKS标签仅适用于Java 9或更新版本。从Java 9版本开始,默认的密钥库类型是PKS12。

创建一个名为[project]/android/key.properties的文件,其中包含对您的密钥库的引用。不包括尖括号(< >)。它们表示文本用作您的值的占位符。

storePassword=<从前一步骤中获取的密码>
keyPassword=<从前一步骤中获取的密码>
keyAlias=upload
storeFile=<密钥库文件位置>

storeFile 可能位于macOS上的/Users/<用户名>/upload-keystore.jks或Windows上的C:\\Users\\<用户名>\\upload-keystore.jks

  1. 在android块之前,将属性文件中的密钥库信息添加到项目中:
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

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

并将其替换为以下签名配置信息:

signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
}
buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}

注意:在更改gradle文件后,您可能需要运行flutter clean,以防止缓存的构建影响签名过程。

我只提供翻译,不提供其他内容。如果您需要更多帮助,请告诉我。

英文:

On macOS or Linux, use the following command:

  keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA \
      -keysize 2048 -validity 10000 -alias upload

On Windows, use the following command in PowerShell:

  keytool -genkey -v -keystore %userprofile%\upload-keystore.jks ^
      -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 ^
      -alias upload

> Note:
> The keytool command might not be in your path—it’s part of Java, which is installed as part of Android Studio. For the concrete path, run flutter doctor -v and locate the path printed after ‘Java binary at:’. Then use that fully qualified path replacing java (at the end) with keytool. If your path includes space-separated names, such as Program Files, use platform-appropriate notation for the names. For example, on Mac/Linux use Program\ Files, and on Windows use "Program Files".

> The -storetype JKS tag is only required for Java 9 or newer. As of the Java 9 release, the keystore type defaults to PKS12.

Create a file named [project]/android/key.properties that contains a reference to your keystore. Don’t include the angle brackets (< >). They indicate that the text serves as a placeholder for your values.

storePassword=&lt;password-from-previous-step&gt;
keyPassword=&lt;password-from-previous-step&gt;
keyAlias=upload
storeFile=&lt;keystore-file-location&gt;

The storeFile might be located at /Users/&lt;user name&gt;/upload-keystore.jks on macOS or C:\\Users\\&lt;user name&gt;\\upload-keystore.jks on Windows.

  1. Add the keystore information from your properties file before the android block:
   def keystoreProperties = new Properties()
   def keystorePropertiesFile = rootProject.file(&#39;key.properties&#39;)
   if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
   }

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

And replace it with the following signing configuration info:

   signingConfigs {
       release {
           keyAlias keystoreProperties[&#39;keyAlias&#39;]
           keyPassword keystoreProperties[&#39;keyPassword&#39;]
           storeFile keystoreProperties[&#39;storeFile&#39;] ? file(keystoreProperties[&#39;storeFile&#39;]) : null
           storePassword keystoreProperties[&#39;storePassword&#39;]
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
       }
   }

> Note: You might need to run flutter clean after changing the gradle file. This prevents cached builds from affecting the signing process.

I just following this link and I got the app to publish.
flutter offical

huangapple
  • 本文由 发表于 2023年6月19日 07:09:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76502832.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定