Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Inconsistent handling of app identifiers containing hyphens when building for Android #9707

Closed
Almost-Senseless-Coder opened this issue May 8, 2024 · 8 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@Almost-Senseless-Coder
Copy link

Describe the bug

Like most app development frameworks, Tauri uses reverse domain notation for the app identifiers.

Tauri only allows letters (a-z, A-Z), digits (0-9) and hyphens (-) in app identifiers. However, Android only allows underscores (_) in app identifiers, not hyphens; iOS, on the other hand, does allow hyphens, but no underscores.

Right now, this means that running cargo tauri android init panics if the app identifier contains hyphens or alternatively only contains of two parts (I think the latter is unintended, anyway).

To illustrate, let's assume I have an app identifier like tech.almost-senseless.jack-point. Trying to build this app for Android fails with a panic due to the hyphen in almost-senseless. Renaming it to tech.almostsenseless.jack-point or tech.almost-senseless works fine, though: In the first case, the generated Android package name and identifier would be tech.almostsenseless.jack_point, and in the latter case it would be tech.jack_point.

Evidently, the last part of the app identifier gets silently dropped and replaced with the product name, and in the product name, hyphens get replaced with underscores.

This has the side effect that running cargo tauri android init when the app identifier is com.tauri.dev works, by the way, because it becomes com.tauri.jack_point - I think that's not intended that way, is it?

So my problem boils down to that

  • Having hyphens in your app identifier shouldn't lead to a panic; rather, the hyphens should get replaced with underscores in the generated Android project.
  • The handling of the identifier should be more consistent, with the last part not getting silently dropped and replaced with the product name.

Reproduction

  • Create a Tauri project from any template, for instance using cargo create-tauri-app --beta. Please make sure mobile support was enabled.
  • Open tauri.conf.json and change the identifier to com.some-domain.some-app.
  • Run cargo tauri android init.

Expected behavior

The command should complete successfully, generating an Android project with the identifier com.some_domain.some_app.

Full tauri info output

WARNING: no lock files found, defaulting to npm

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 124.0.2478.80
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.80.0-nightly (e82c861d7 2024-05-04)
    ✔ cargo: 1.80.0-nightly (05364cb2f 2024-05-03)
    ✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
    ✔ Rust toolchain: nightly-x86_64-pc-windows-msvc (environment override by RUSTUP_TOOLCHAIN)
    - node: 20.11.0
    - npm: 10.5.0

[-] Packages
    - tauri [RUST]: 2.0.0-beta.17
    - tauri-build [RUST]: 2.0.0-beta.13
    - wry [RUST]: 0.39.3
    - tao [RUST]: 0.27.1
    - tauri-cli [RUST]: 2.0.0-beta.16
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 2.0.0-beta.16

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/


### Stack trace

```text
thread 'main' panicked at C:\Users\timjb\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tauri-cli-2.0.0-beta.16\src\mobile\mod.rs:322:6:
called `Result::unwrap()` on an `Err` value: DomainInvalid { domain: "almost-senseless.tech", cause: NotAsciiAlphanumeric { bad_chars: ['-'] } }

Additional context

No response

@loikki
Copy link

loikki commented Aug 19, 2024

Hi,
I am having the same issue. It used to be possible to have _ in the android application name but since the last updates, this is not possible anymore. I have published an android application with an underscore and now cannot update it anymore due to that. I would be happy with the solution proposed by almost-senseless-coder.

I think it is related to this change tauri-apps/cargo-mobile2@29921ff, but I am really not sure as I don't have a deep knowledge of the way tauri works.

@loikki
Copy link

loikki commented Aug 20, 2024

@FabianLars It looks like you don't have the manpower to handle that. What would be your preferred solution?

  • Allowing - in the identifier and converting it for Android
  • Having an option to manually specify the appid for android (and other OS will be implemented later if needed)?
  • Something else?

@FabianLars
Copy link
Member

I personally would lean towards the first option, but not sure. Let's ask @lucasfernog and @amrbashir

@lucasfernog
Copy link
Member

Hi, I am having the same issue. It used to be possible to have _ in the android application name but since the last updates, this is not possible anymore. I have published an android application with an underscore and now cannot update it anymore due to that. I would be happy with the solution proposed by almost-senseless-coder.

I think it is related to this change tauri-apps/cargo-mobile2@29921ff, but I am really not sure as I don't have a deep knowledge of the way tauri works.

I wonder how you manage to do so 😂 looks like we need even more changes to support _ in the package identifier

@loikki
Copy link

loikki commented Aug 21, 2024

Hi, I am having the same issue. It used to be possible to have _ in the android application name but since the last updates, this is not possible anymore. I have published an android application with an underscore and now cannot update it anymore due to that. I would be happy with the solution proposed by almost-senseless-coder.
I think it is related to this change tauri-apps/cargo-mobile2@29921ff, but I am really not sure as I don't have a deep knowledge of the way tauri works.

I wonder how you manage to do so 😂 looks like we need even more changes to support _ in the package identifier

I am good enough to break anything 😂

There was a few modifications required for my app in the build.gradle.kts which I managed by simply modifying it in my repository (including the appid). Unfortunately, there has been some changes in tauri that forces the appid in build.gradle.kts to match the identifier in the configuration file. If they don't match, I get an undefined reference to in Logger.kt. I tried making links, moving directories, copying files, ... but it does not work.

I know it is not something very standard, so I am ready to help if you need.

lucasfernog added a commit to tauri-apps/tao that referenced this issue Aug 21, 2024
* feat(macros): allow Android domain parts to have underscores

Ref tauri-apps/tauri#9707

* fill change file

* no need to unescape package

* Update .changes/android-package-underscores.md
@lucasfernog
Copy link
Member

Fix will be released soon. Note that you'll need to run cargo update in the src-tauri folder to apply it.

@loikki
Copy link

loikki commented Aug 21, 2024

Fix will be released soon. Note that you'll need to run cargo update in the src-tauri folder to apply it.

Thanks a lot for the quick fix!

@loikki
Copy link

loikki commented Aug 23, 2024

I can confirm that the fix works with tauri-cli rc7. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

4 participants