refactor(core): generate TauriActivity on build script (#6783)

This commit is contained in:
Lucas Fernandes Nogueira 2023-04-24 07:17:59 -07:00 committed by GitHub
parent ecc9ac9603
commit 942249060e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
"tauri": patch
---
Generate `TauriActivity` Kotlin class on the build script.

View File

@ -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:

View File

@ -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" ] }

View File

@ -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"),

View File

@ -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

View File

@ -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",