mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
refactor(core): use absolute path for the tauri Android library (#6774)
This commit is contained in:
committed by
GitHub
parent
2969d1cbba
commit
cdad6e0837
6
.changes/refactor-tauri-android-dependency.md
Normal file
6
.changes/refactor-tauri-android-dependency.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri": patch
|
||||
"tauri-build": patch
|
||||
---
|
||||
|
||||
Changed how the `tauri-android` dependency is injected. This requires the `gen/android` project to be recreated.
|
||||
@@ -300,12 +300,20 @@ dependencies {"
|
||||
.to_string();
|
||||
|
||||
let plugins_json_path = project_dir.join(".tauri").join("plugins.json");
|
||||
let plugins: HashMap<String, mobile::PluginMetadata> = if plugins_json_path.exists() {
|
||||
let mut plugins: HashMap<String, mobile::PluginMetadata> = if plugins_json_path.exists() {
|
||||
let s = read_to_string(&plugins_json_path)?;
|
||||
serde_json::from_str(&s)?
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
|
||||
plugins.insert(
|
||||
"tauri-android".into(),
|
||||
mobile::PluginMetadata {
|
||||
path: var_os("DEP_TAURI_ANDROID_LIBRARY_PATH").map(PathBuf::from).expect("missing `DEP_TAURI_ANDROID_LIBRARY_PATH` environment variable; did you add `tauri` as a dependency to this crate?"),
|
||||
},
|
||||
);
|
||||
|
||||
for (plugin_name, plugin) in plugins {
|
||||
gradle_settings.push_str(&format!("include ':{plugin_name}'"));
|
||||
gradle_settings.push('\n');
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env::{var, var_os},
|
||||
fs::{copy, create_dir, create_dir_all, read_to_string, remove_dir_all, rename, write},
|
||||
fs::{copy, create_dir, create_dir_all, read_to_string, remove_dir_all, write},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
@@ -127,45 +127,6 @@ pub fn link_swift_library(name: &str, source: impl AsRef<Path>) {
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn inject_android_project(
|
||||
source: impl AsRef<Path>,
|
||||
target: impl AsRef<Path>,
|
||||
ignore_paths: &[&str],
|
||||
) -> Result<()> {
|
||||
let source = source.as_ref();
|
||||
let target = target.as_ref();
|
||||
|
||||
// keep build folder if it exists
|
||||
let build_path = target.join("build");
|
||||
let out_dir = if build_path.exists() {
|
||||
let out_dir = target.parent().unwrap().join(".tauri-tmp-build");
|
||||
let _ = remove_dir_all(&out_dir);
|
||||
rename(&build_path, &out_dir).context("failed to rename build directory")?;
|
||||
Some(out_dir)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
copy_folder(source, target, ignore_paths).context("failed to copy Android project")?;
|
||||
|
||||
if let Some(out_dir) = out_dir {
|
||||
rename(out_dir, &build_path).context("failed to restore build directory")?;
|
||||
}
|
||||
|
||||
let rerun_path = target.join("build.gradle.kts");
|
||||
let metadata = source.join("build.gradle.kts").metadata()?;
|
||||
filetime::set_file_mtime(
|
||||
&rerun_path,
|
||||
filetime::FileTime::from_last_modification_time(&metadata),
|
||||
)
|
||||
.context("failed to update build.gradle.kts mtime")?;
|
||||
|
||||
println!("cargo:rerun-if-changed={}", rerun_path.display());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn copy_folder(source: &Path, target: &Path, ignore_paths: &[&str]) -> Result<()> {
|
||||
let _ = remove_dir_all(target);
|
||||
|
||||
|
||||
@@ -151,12 +151,6 @@ fn main() {
|
||||
|
||||
if target_os == "android" {
|
||||
if let Some(project_dir) = var_os("TAURI_ANDROID_PROJECT_PATH").map(PathBuf::from) {
|
||||
tauri_build::mobile::inject_android_project(
|
||||
"./mobile/android",
|
||||
project_dir.join(".tauri").join("tauri-api"),
|
||||
&[],
|
||||
)
|
||||
.expect("failed to copy tauri-api Android project");
|
||||
let tauri_proguard = include_str!("./mobile/proguard-tauri.pro").replace(
|
||||
"$PACKAGE",
|
||||
&var("WRY_ANDROID_PACKAGE").expect("missing `WRY_ANDROID_PACKAGE` environment variable"),
|
||||
|
||||
@@ -85,7 +85,6 @@ dependencies {
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.4")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0")
|
||||
implementation(project(":tauri-android"))
|
||||
}
|
||||
|
||||
apply(from = "tauri.build.gradle.kts")
|
||||
|
||||
@@ -2,7 +2,4 @@ include ':app'
|
||||
{{~#each asset-packs}}
|
||||
include ':{{this}}'{{/each}}
|
||||
|
||||
include ':tauri-android'
|
||||
project(':tauri-android').projectDir = new File('./.tauri/tauri-api')
|
||||
|
||||
apply from: 'tauri.settings.gradle'
|
||||
|
||||
Reference in New Issue
Block a user