mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-25 11:43:06 +03:00
* fix(android): use identifier as Android package name * update android_binding and android_fn interface * chore: rename TAURI_ANDROID_PACKAGE_PREFIX to TAURI_ANDROID_PACKAGE_NAME * revert back to split prefix and app_name * rename `domain` to `identifier` * add change log * simplify reverse config identifier * Update .changes/mobile-use-identifier-as-id.md * Update core/tauri-build/src/lib.rs * lint * cargo-mobile2 0.12 * fmt --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
parent
8a1ae2deaf
commit
1df5cdeb06
9
.changes/mobile-use-identifier-as-id.md
Normal file
9
.changes/mobile-use-identifier-as-id.md
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
"tauri": patch:breaking
|
||||
"tauri-build": patch:breaking
|
||||
"tauri-cli": patch:breaking
|
||||
"@tauri-apps/cli": patch:breaking
|
||||
"tauri-macros": patch:breaking
|
||||
---
|
||||
|
||||
Use `tauri.conf.json > identifier` to set the `PackageName` in Android and `BundleId` in iOS.
|
@ -459,13 +459,15 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
|
||||
let last = s.clone().count() - 1;
|
||||
let mut android_package_prefix = String::new();
|
||||
for (i, w) in s.enumerate() {
|
||||
if i == 0 || i != last {
|
||||
if i == last {
|
||||
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={}", w);
|
||||
} else {
|
||||
android_package_prefix.push_str(w);
|
||||
android_package_prefix.push('_');
|
||||
}
|
||||
}
|
||||
android_package_prefix.pop();
|
||||
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_PREFIX={android_package_prefix}");
|
||||
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_PREFIX={android_package_prefix}");
|
||||
|
||||
if let Some(project_dir) = var_os("TAURI_ANDROID_PROJECT_PATH").map(PathBuf::from) {
|
||||
mobile::generate_gradle_files(project_dir)?;
|
||||
|
@ -37,9 +37,14 @@ pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let function_name = &function.sig.ident;
|
||||
|
||||
let mut error = None;
|
||||
let domain = get_env_var("TAURI_ANDROID_PACKAGE_PREFIX", |r| r, &mut error, &function);
|
||||
let domain = get_env_var(
|
||||
"TAURI_ANDROID_PACKAGE_NAME_PREFIX",
|
||||
|r| r,
|
||||
&mut error,
|
||||
&function,
|
||||
);
|
||||
let app_name = get_env_var(
|
||||
"CARGO_PKG_NAME",
|
||||
"TAURI_ANDROID_PACKAGE_NAME_APP_NAME",
|
||||
|r| r.replace('-', "_"),
|
||||
&mut error,
|
||||
&function,
|
||||
|
@ -129,17 +129,17 @@ pub type WryHandle = tauri_runtime_wry::WryHandle<EventLoopMessage>;
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! android_binding {
|
||||
($domain:ident, $package:ident, $main: ident, $wry: path) => {
|
||||
($domain:ident, $app_name:ident, $main:ident, $wry:path) => {
|
||||
use $wry::{
|
||||
android_setup,
|
||||
prelude::{JClass, JNIEnv, JString},
|
||||
};
|
||||
|
||||
::tauri::wry::android_binding!($domain, $package, $wry);
|
||||
::tauri::wry::android_binding!($domain, $app_name, $wry);
|
||||
|
||||
::tauri::tao::android_binding!(
|
||||
$domain,
|
||||
$package,
|
||||
$app_name,
|
||||
WryActivity,
|
||||
android_setup,
|
||||
$main,
|
||||
|
16
examples/api/src-tauri/Cargo.lock
generated
16
examples/api/src-tauri/Cargo.lock
generated
@ -3007,7 +3007,7 @@ checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f"
|
||||
|
||||
[[package]]
|
||||
name = "tauri"
|
||||
version = "2.0.0-beta.19"
|
||||
version = "2.0.0-beta.20"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@ -3057,7 +3057,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-build"
|
||||
version = "2.0.0-beta.15"
|
||||
version = "2.0.0-beta.16"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cargo_toml",
|
||||
@ -3079,7 +3079,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-codegen"
|
||||
version = "2.0.0-beta.15"
|
||||
version = "2.0.0-beta.16"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"brotli",
|
||||
@ -3104,7 +3104,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-macros"
|
||||
version = "2.0.0-beta.15"
|
||||
version = "2.0.0-beta.16"
|
||||
dependencies = [
|
||||
"heck 0.5.0",
|
||||
"proc-macro2",
|
||||
@ -3116,7 +3116,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin"
|
||||
version = "2.0.0-beta.15"
|
||||
version = "2.0.0-beta.16"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"glob",
|
||||
@ -3152,7 +3152,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime"
|
||||
version = "2.0.0-beta.16"
|
||||
version = "2.0.0-beta.17"
|
||||
dependencies = [
|
||||
"dpi",
|
||||
"gtk",
|
||||
@ -3169,7 +3169,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime-wry"
|
||||
version = "2.0.0-beta.16"
|
||||
version = "2.0.0-beta.17"
|
||||
dependencies = [
|
||||
"cocoa",
|
||||
"gtk",
|
||||
@ -3191,7 +3191,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-utils"
|
||||
version = "2.0.0-beta.15"
|
||||
version = "2.0.0-beta.16"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"brotli",
|
||||
|
71
tooling/cli/Cargo.lock
generated
71
tooling/cli/Cargo.lock
generated
@ -483,9 +483,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cargo-mobile2"
|
||||
version = "0.11.0"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6eb3459f8fb1fd0e12ca229db09cd763befe00827061cc5aaf6bdf173dad37c"
|
||||
checksum = "79fadc84c218c513afcace5b0115bf615fb1c64dac782c1978f1620491339d7d"
|
||||
dependencies = [
|
||||
"colored",
|
||||
"core-foundation",
|
||||
@ -495,7 +495,7 @@ dependencies = [
|
||||
"embed-resource",
|
||||
"english-numbers",
|
||||
"freedesktop_entry_parser",
|
||||
"handlebars 4.5.0",
|
||||
"handlebars",
|
||||
"heck 0.5.0",
|
||||
"home",
|
||||
"ignore",
|
||||
@ -1795,20 +1795,6 @@ dependencies = [
|
||||
"crunchy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "handlebars"
|
||||
version = "4.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "faa67bab9ff362228eb3d00bd024a4965d8231bbb7921167f0cfa66c6626b225"
|
||||
dependencies = [
|
||||
"log",
|
||||
"pest",
|
||||
"pest_derive",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "handlebars"
|
||||
version = "5.1.0"
|
||||
@ -4862,7 +4848,7 @@ dependencies = [
|
||||
"dunce",
|
||||
"flate2",
|
||||
"glob",
|
||||
"handlebars 5.1.0",
|
||||
"handlebars",
|
||||
"heck 0.5.0",
|
||||
"hex",
|
||||
"image",
|
||||
@ -4912,7 +4898,7 @@ dependencies = [
|
||||
"dunce",
|
||||
"env_logger",
|
||||
"glob",
|
||||
"handlebars 5.1.0",
|
||||
"handlebars",
|
||||
"heck 0.5.0",
|
||||
"html5ever",
|
||||
"ignore",
|
||||
@ -5872,15 +5858,14 @@ checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "5.0.0"
|
||||
version = "6.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9bf3ea8596f3a0dd5980b46430f2058dfe2c36a27ccfbb1845d6fbfcd9ba6e14"
|
||||
checksum = "8211e4f58a2b2805adfbefbc07bab82958fc91e3836339b1ab7ae32465dce0d7"
|
||||
dependencies = [
|
||||
"either",
|
||||
"home",
|
||||
"once_cell",
|
||||
"rustix 0.38.31",
|
||||
"windows-sys 0.48.0",
|
||||
"winsafe",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -5916,11 +5901,11 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.54.0"
|
||||
version = "0.56.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49"
|
||||
checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132"
|
||||
dependencies = [
|
||||
"windows-core 0.54.0",
|
||||
"windows-core 0.56.0",
|
||||
"windows-targets 0.52.5",
|
||||
]
|
||||
|
||||
@ -5935,14 +5920,38 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.54.0"
|
||||
version = "0.56.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65"
|
||||
checksum = "4698e52ed2d08f8658ab0c39512a7c00ee5fe2688c65f8c0a4f06750d729f2a6"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-result",
|
||||
"windows-targets 0.52.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.56.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.56.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.1.1"
|
||||
@ -6148,6 +6157,12 @@ dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winsafe"
|
||||
version = "0.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"
|
||||
|
||||
[[package]]
|
||||
name = "x25519-dalek"
|
||||
version = "2.0.1"
|
||||
|
@ -39,7 +39,7 @@ name = "cargo-tauri"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
cargo-mobile2 = { version = "0.11", default-features = false }
|
||||
cargo-mobile2 = { version = "0.12", default-features = false }
|
||||
jsonrpsee = { version = "0.22", features = [ "server" ] }
|
||||
jsonrpsee-core = "0.22"
|
||||
jsonrpsee-client-transport = { version = "0.22", features = [ "ws" ] }
|
||||
|
@ -133,17 +133,13 @@ pub fn get_config(
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
set_var(
|
||||
"WRY_ANDROID_PACKAGE",
|
||||
format!("{}.{}", app.reverse_domain(), app.name_snake()),
|
||||
);
|
||||
set_var("WRY_ANDROID_PACKAGE", app.reverse_identifier());
|
||||
set_var("WRY_ANDROID_LIBRARY", app.lib_name());
|
||||
set_var("TAURI_ANDROID_PROJECT_PATH", config.project_dir());
|
||||
|
||||
let src_main_dir = config.project_dir().join("app/src/main").join(format!(
|
||||
"java/{}/{}",
|
||||
app.reverse_domain().replace('.', "/"),
|
||||
app.name_snake()
|
||||
"java/{}",
|
||||
app.reverse_identifier().replace('.', "/"),
|
||||
));
|
||||
if config.project_dir().exists() {
|
||||
if src_main_dir.exists() {
|
||||
|
@ -109,8 +109,8 @@ pub fn gen(
|
||||
);
|
||||
map.insert("windows", cfg!(windows));
|
||||
|
||||
let domain = config.app().reverse_domain().replace('.', "/");
|
||||
let package_path = format!("java/{}/{}", domain, config.app().name_snake());
|
||||
let identifier = config.app().reverse_identifier().replace('.', "/");
|
||||
let package_path = format!("java/{}", identifier);
|
||||
|
||||
map.insert("package-path", &package_path);
|
||||
|
||||
|
@ -288,24 +288,21 @@ fn read_options(identifier: &str) -> CliOptions {
|
||||
}
|
||||
|
||||
pub fn get_app(config: &TauriConfig, interface: &AppInterface) -> App {
|
||||
let mut s = config.identifier.rsplit('.');
|
||||
let app_name = s.next().unwrap_or("app").to_string();
|
||||
let mut domain = String::new();
|
||||
for w in s {
|
||||
domain.push_str(w);
|
||||
domain.push('.');
|
||||
}
|
||||
if domain.is_empty() {
|
||||
domain.clone_from(&config.identifier);
|
||||
if domain.is_empty() {
|
||||
log::error!("Bundle identifier set in `tauri.conf.json > identifier` cannot be empty");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
domain.pop();
|
||||
let identifier = config
|
||||
.identifier
|
||||
.rsplit('.')
|
||||
.collect::<Vec<&str>>()
|
||||
.join(".");
|
||||
|
||||
if identifier.is_empty() {
|
||||
log::error!("Bundle identifier set in `tauri.conf.json > identifier` cannot be empty");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
let app_name = interface.app_settings().app_name().unwrap_or(app_name);
|
||||
let app_name = interface
|
||||
.app_settings()
|
||||
.app_name()
|
||||
.unwrap_or_else(|| "app".into());
|
||||
let lib_name = interface
|
||||
.app_settings()
|
||||
.lib_name()
|
||||
@ -315,7 +312,7 @@ pub fn get_app(config: &TauriConfig, interface: &AppInterface) -> App {
|
||||
name: app_name,
|
||||
lib_name: Some(lib_name),
|
||||
stylized_name: config.product_name.clone(),
|
||||
domain,
|
||||
identifier,
|
||||
asset_dir: None,
|
||||
template_pack: None,
|
||||
};
|
||||
|
@ -8,10 +8,10 @@ plugins {
|
||||
|
||||
android {
|
||||
compileSdk = 33
|
||||
namespace = "{{reverse-domain app.domain}}.{{snake-case app.name}}"
|
||||
namespace = "{{reverse-domain app.identifier}}"
|
||||
defaultConfig {
|
||||
manifestPlaceholders["usesCleartextTraffic"] = "false"
|
||||
applicationId = "{{reverse-domain app.domain}}.{{snake-case app.name}}"
|
||||
applicationId = "{{reverse-domain app.identifier}}"
|
||||
minSdk = {{android.min-sdk-version}}
|
||||
targetSdk = 33
|
||||
versionCode = 1
|
||||
|
@ -1,3 +1,3 @@
|
||||
package {{reverse-domain app.domain}}.{{snake-case app.name}}
|
||||
package {{reverse-domain app.identifier}}
|
||||
|
||||
class MainActivity : TauriActivity()
|
@ -1,6 +1,6 @@
|
||||
name: {{app.name}}
|
||||
options:
|
||||
bundleIdPrefix: {{reverse-domain app.domain}}
|
||||
bundleIdPrefix: {{reverse-domain app.identifier}}
|
||||
deploymentTarget:
|
||||
iOS: {{apple.ios-version}}
|
||||
fileGroups: [{{join file-groups}}]
|
||||
@ -11,7 +11,7 @@ settingGroups:
|
||||
app:
|
||||
base:
|
||||
PRODUCT_NAME: {{app.stylized-name}}
|
||||
PRODUCT_BUNDLE_IDENTIFIER: {{reverse-domain app.domain}}.{{app.name}}
|
||||
PRODUCT_BUNDLE_IDENTIFIER: {{reverse-domain app.identifier}}
|
||||
{{#if apple.development-team}}
|
||||
DEVELOPMENT_TEAM: {{apple.development-team}}
|
||||
{{/if}}
|
||||
|
Loading…
Reference in New Issue
Block a user