mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-25 11:43:06 +03:00
refactor(core): generate TauriActivity on build script (#6783)
This commit is contained in:
parent
ecc9ac9603
commit
942249060e
5
.changes/generate-tauri-activity.md
Normal file
5
.changes/generate-tauri-activity.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Generate `TauriActivity` Kotlin class on the build script.
|
3
.github/workflows/test-android.yml
vendored
3
.github/workflows/test-android.yml
vendored
@ -2,7 +2,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
name: test mobile
|
||||
name: test android
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
@ -14,6 +14,7 @@ on:
|
||||
- '!tooling/cli/src/mobile/ios/**'
|
||||
- 'core/tauri-build/src/mobile.rs'
|
||||
- 'core/tauri/mobile/android/**'
|
||||
- 'core/tauri/mobile/android-codegen/**'
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
|
@ -13,7 +13,7 @@ exclude = [ "CHANGELOG.md", "/target" ]
|
||||
readme = "README.md"
|
||||
|
||||
[dependencies]
|
||||
wry = { version = "0.28.1", default-features = false, features = [ "file-drop", "protocol" ] }
|
||||
wry = { version = "0.28.2", default-features = false, features = [ "file-drop", "protocol" ] }
|
||||
tauri-runtime = { version = "0.13.0-alpha.4", path = "../tauri-runtime" }
|
||||
tauri-utils = { version = "2.0.0-alpha.4", path = "../tauri-utils" }
|
||||
uuid = { version = "1", features = [ "v4" ] }
|
||||
|
@ -9,6 +9,9 @@ use heck::ToSnakeCase;
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
use std::env::var_os;
|
||||
use std::fs::read_dir;
|
||||
use std::fs::read_to_string;
|
||||
use std::fs::write;
|
||||
use std::{
|
||||
env::var,
|
||||
path::{Path, PathBuf},
|
||||
@ -150,7 +153,46 @@ fn main() {
|
||||
}
|
||||
|
||||
if target_os == "android" {
|
||||
if let Some(project_dir) = var_os("TAURI_ANDROID_PROJECT_PATH").map(PathBuf::from) {
|
||||
if let Ok(kotlin_out_dir) = std::env::var("WRY_ANDROID_KOTLIN_FILES_OUT_DIR") {
|
||||
fn env_var(var: &str) -> String {
|
||||
std::env::var(var).unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"`{}` is not set, which is needed to generate the kotlin files for android.",
|
||||
var
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
let package = env_var("WRY_ANDROID_PACKAGE");
|
||||
let library = env_var("WRY_ANDROID_LIBRARY");
|
||||
|
||||
let kotlin_out_dir = PathBuf::from(&kotlin_out_dir)
|
||||
.canonicalize()
|
||||
.unwrap_or_else(move |_| {
|
||||
panic!("Failed to canonicalize `WRY_ANDROID_KOTLIN_FILES_OUT_DIR` path {kotlin_out_dir}")
|
||||
});
|
||||
|
||||
let kotlin_files_path =
|
||||
PathBuf::from(env_var("CARGO_MANIFEST_DIR")).join("mobile/android-codegen");
|
||||
println!("cargo:rerun-if-changed={}", kotlin_files_path.display());
|
||||
let kotlin_files =
|
||||
read_dir(kotlin_files_path).expect("failed to read Android codegen directory");
|
||||
|
||||
for file in kotlin_files {
|
||||
let file = file.unwrap();
|
||||
|
||||
let content = read_to_string(file.path())
|
||||
.expect("failed to read kotlin file as string")
|
||||
.replace("{{package}}", &package)
|
||||
.replace("{{library}}", &library);
|
||||
|
||||
let out_path = kotlin_out_dir.join(file.file_name());
|
||||
write(&out_path, content).expect("Failed to write kotlin file");
|
||||
println!("cargo:rerun-if-changed={}", out_path.display());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(project_dir) = var_os("WRY_ANDROID_PROJECT_PATH").map(PathBuf::from) {
|
||||
let tauri_proguard = include_str!("./mobile/proguard-tauri.pro").replace(
|
||||
"$PACKAGE",
|
||||
&var("WRY_ANDROID_PACKAGE").expect("missing `WRY_ANDROID_PACKAGE` environment variable"),
|
||||
|
@ -1,4 +1,10 @@
|
||||
package {{reverse-domain app.domain}}.{{snake-case app.name}}
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */
|
||||
|
||||
package {{package}}
|
||||
|
||||
import android.os.Bundle
|
||||
import app.tauri.plugin.PluginManager
|
4
examples/api/src-tauri/Cargo.lock
generated
4
examples/api/src-tauri/Cargo.lock
generated
@ -4001,9 +4001,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wry"
|
||||
version = "0.28.1"
|
||||
version = "0.28.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bc4072414a89ef95559d499f3b1930c773fb4457759ec78fe3a9849883ee22d"
|
||||
checksum = "77dbd1fe0556bf87517db301c9be2bdc18f6311c0826c73b2c80a7f79ac0e31f"
|
||||
dependencies = [
|
||||
"base64 0.13.1",
|
||||
"block",
|
||||
|
Loading…
Reference in New Issue
Block a user