在 Gluon 中自定义 AndroidManifest.xml

发布于 2025-01-10 15:00:30 字数 581 浏览 6 评论 0原文

如果我不在 Gluon 项目中创建 src/android/AndroidManifest.xml 文件,那么 mvn gluonfx:package 命令会为我创建一个具有一些相对合理的默认值的文件。但是,我需要对我的应用程序生成的 AndroidManifest.xml 进行一些更改(例如指示支持多种屏幕分辨率,并且我需要添加 BILLING 权限)。

如果我按照 gluonfx:package 期间的建议将生成的 AndroidManifest.xml 复制到 src/android/AndroidManifest.xml,则 Gluon 不再为我更新版本代码和版本名称字段。我也不确定手动编辑 AndroidManifest.xml 文件是否有任何其他副作用。

所以我的问题是:

  1. 管理 Gluon 项目的 AndroidManifest.xml 的最佳实践是什么?
  2. 作为 CI/CD 管道的一部分,人们如何处理更新手动编辑的文件中的版本代码和版本名称,而我不想为每个构建手动编辑 AndroidManifest.xml?
  3. 在 gluonfx:package 命令之外管理 AndroidManifest.xml 是否存在任何陷阱?

If I don't create a src/android/AndroidManifest.xml file in my Gluon project, then the mvn gluonfx:package command creates one for me with some relatively sensible defaults. However, I need to make some changes to the generated AndroidManifest.xml for my app (such as indicating support for multiple screen resolutions, and I need to add the BILLING permission).

If I copy the generated AndroidManifest.xml to src/android/AndroidManifest.xml as suggested during gluonfx:package, then Gluon no longer updates the version code and version name fields for me. I'm also not sure if there any any other side-effects to manually editing the AndroidManifest.xml file.

So my questions are:

  1. What's the best practice when it comes to managing AndroidManifest.xml for a Gluon project?
  2. How do folks deal with updating the version code and version name in a manually edited file as part of a CI/CD pipeline, where I don't want to have to manually edit AndroidManifest.xml for each build?
  3. Are there any pitfalls to managing the AndroidManifest.xml outside the gluonfx:package command?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难得心□动 2025-01-17 15:00:30

此处所述,您应该使用 来定义每个新版本所需或需要更新的值。

对于 Android,除了密钥库签名属性之外,您还可以定义:

  • 版本代码
  • 版本名称
  • 应用程序标签,

例如:

    <plugin>
                <groupId>com.gluonhq</groupId>
                <artifactId>gluonfx-maven-plugin</artifactId>
                <version>${gluonfx.maven.plugin.version}</version>
                <configuration>
                    <target>${gluonfx.target}</target>
                    <releaseConfiguration>
                        <versionCode>2</versionCode>
                        <versionName>3.0</versionName>
                        <appLabel>MyHelloFX</appLabel>
                    </releaseConfiguration>
...

因此,如果您需要将 AndroidManifest 添加到 src/Android (在target/gluonfx/aarch64-android/gensrc/android/AndroidManifest.xml),为了添加/修改其中的一部分,每当您在pom。

关于 CI/CD,请查看 HelloGluon CI 示例。

它没有自定义清单,但它展示了如何在 CI 环境中处理 ReleaseConfiguration 和更新发布值。

pom 定义了一些使用的属性通过releaseConfiguration块:

<properties>
        ...
        <main.class>com.gluonhq.hello.HelloGluonApp</main.class>
        <app.identifier>${main.class}</app.identifier>
        <app.description>The HelloGluon app</app.description>
        <version.code/>
        <provided.keystore.path/>
    </properties>
...
            <plugin>
                <groupId>com.gluonhq</groupId>
                <artifactId>gluonfx-maven-plugin</artifactId>
                <version>${gluonfx.maven.plugin.version}</version>
                <configuration>
...
                   <releaseConfiguration>
                        <vendor>Gluon</vendor>
                        <description>${app.description}</description>
                        <packageType>${package.type}</packageType>
                        <!-- for macOS/iOS -->
                        <macAppStore>${mac.app.store}</macAppStore>
                        <bundleShortVersion>${bundle.short.version}</bundleShortVersion>
                        <bundleVersion>${bundle.version}</bundleVersion>
                        <!-- for Android -->
                        <versionCode>${version.code}</versionCode>
                        <providedKeyStorePath>${provided.keystore.path}</providedKeyStorePath>
...

这些属性最终是为每个配置文件

        <profile>
            <id>android</id>
            <properties>
                <gluonfx.target>android</gluonfx.target>
                <app.identifier>com.gluonhq.samples.hellogluon</app.identifier>
                <version.code>${env.GITHUB_RUN_NUMBER}</version.code>
...

运行 Android 时 job,使用所需的变量和秘密:

      - name: Gluon Build
        run: mvn -Pandroid gluonfx:build gluonfx:package
        env:
          GLUON_ANDROID_KEYSTOREPATH: ${{ steps.android_keystore_file.outputs.filePath }}
...

As documented here, you should use <releaseConfiguration/> to define the values that are required or need to be updated for each new release.

For Android, besides the keystore signing properties, you can also define:

  • version code
  • version name
  • app label

like:

    <plugin>
                <groupId>com.gluonhq</groupId>
                <artifactId>gluonfx-maven-plugin</artifactId>
                <version>${gluonfx.maven.plugin.version}</version>
                <configuration>
                    <target>${gluonfx.target}</target>
                    <releaseConfiguration>
                        <versionCode>2</versionCode>
                        <versionName>3.0</versionName>
                        <appLabel>MyHelloFX</appLabel>
                    </releaseConfiguration>
...

So in case you need to add the AndroidManifest to src/Android (the one that was generated in target/gluonfx/aarch64-android/gensrc/android/AndroidManifest.xml), in order to add/modify part of it, it will be always updated for those three values, whenever you change them in the pom.

About CI/CD, have a look at the HelloGluon CI sample.

It doesn't have a custom manifest, but it shows how to deal with ReleaseConfiguration and updating release values in a CI environment.

The pom defines some properties that are used by the releaseConfiguration block:

<properties>
        ...
        <main.class>com.gluonhq.hello.HelloGluonApp</main.class>
        <app.identifier>${main.class}</app.identifier>
        <app.description>The HelloGluon app</app.description>
        <version.code/>
        <provided.keystore.path/>
    </properties>
...
            <plugin>
                <groupId>com.gluonhq</groupId>
                <artifactId>gluonfx-maven-plugin</artifactId>
                <version>${gluonfx.maven.plugin.version}</version>
                <configuration>
...
                   <releaseConfiguration>
                        <vendor>Gluon</vendor>
                        <description>${app.description}</description>
                        <packageType>${package.type}</packageType>
                        <!-- for macOS/iOS -->
                        <macAppStore>${mac.app.store}</macAppStore>
                        <bundleShortVersion>${bundle.short.version}</bundleShortVersion>
                        <bundleVersion>${bundle.version}</bundleVersion>
                        <!-- for Android -->
                        <versionCode>${version.code}</versionCode>
                        <providedKeyStorePath>${provided.keystore.path}</providedKeyStorePath>
...

These properties are ultimately defined for each profile:

        <profile>
            <id>android</id>
            <properties>
                <gluonfx.target>android</gluonfx.target>
                <app.identifier>com.gluonhq.samples.hellogluon</app.identifier>
                <version.code>${env.GITHUB_RUN_NUMBER}</version.code>
...

When running the Android job, the required variables and secrets are used:

      - name: Gluon Build
        run: mvn -Pandroid gluonfx:build gluonfx:package
        env:
          GLUON_ANDROID_KEYSTOREPATH: ${{ steps.android_keystore_file.outputs.filePath }}
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文