Skip to content

Commit cdad6e0

Browse files
authored
refactor(core): use absolute path for the tauri Android library (#6774)
1 parent 2969d1c commit cdad6e0

File tree

6 files changed

+16
-51
lines changed

6 files changed

+16
-51
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch
3+
"tauri-build": patch
4+
---
5+
6+
Changed how the `tauri-android` dependency is injected. This requires the `gen/android` project to be recreated.

core/tauri-build/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,20 @@ dependencies {"
300300
.to_string();
301301

302302
let plugins_json_path = project_dir.join(".tauri").join("plugins.json");
303-
let plugins: HashMap<String, mobile::PluginMetadata> = if plugins_json_path.exists() {
303+
let mut plugins: HashMap<String, mobile::PluginMetadata> = if plugins_json_path.exists() {
304304
let s = read_to_string(&plugins_json_path)?;
305305
serde_json::from_str(&s)?
306306
} else {
307307
Default::default()
308308
};
309+
310+
plugins.insert(
311+
"tauri-android".into(),
312+
mobile::PluginMetadata {
313+
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?"),
314+
},
315+
);
316+
309317
for (plugin_name, plugin) in plugins {
310318
gradle_settings.push_str(&format!("include ':{plugin_name}'"));
311319
gradle_settings.push('\n');

core/tauri-build/src/mobile.rs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use std::{
66
collections::HashMap,
77
env::{var, var_os},
8-
fs::{copy, create_dir, create_dir_all, read_to_string, remove_dir_all, rename, write},
8+
fs::{copy, create_dir, create_dir_all, read_to_string, remove_dir_all, write},
99
path::{Path, PathBuf},
1010
};
1111

@@ -127,45 +127,6 @@ pub fn link_swift_library(name: &str, source: impl AsRef<Path>) {
127127
}
128128
}
129129

130-
#[doc(hidden)]
131-
pub fn inject_android_project(
132-
source: impl AsRef<Path>,
133-
target: impl AsRef<Path>,
134-
ignore_paths: &[&str],
135-
) -> Result<()> {
136-
let source = source.as_ref();
137-
let target = target.as_ref();
138-
139-
// keep build folder if it exists
140-
let build_path = target.join("build");
141-
let out_dir = if build_path.exists() {
142-
let out_dir = target.parent().unwrap().join(".tauri-tmp-build");
143-
let _ = remove_dir_all(&out_dir);
144-
rename(&build_path, &out_dir).context("failed to rename build directory")?;
145-
Some(out_dir)
146-
} else {
147-
None
148-
};
149-
150-
copy_folder(source, target, ignore_paths).context("failed to copy Android project")?;
151-
152-
if let Some(out_dir) = out_dir {
153-
rename(out_dir, &build_path).context("failed to restore build directory")?;
154-
}
155-
156-
let rerun_path = target.join("build.gradle.kts");
157-
let metadata = source.join("build.gradle.kts").metadata()?;
158-
filetime::set_file_mtime(
159-
&rerun_path,
160-
filetime::FileTime::from_last_modification_time(&metadata),
161-
)
162-
.context("failed to update build.gradle.kts mtime")?;
163-
164-
println!("cargo:rerun-if-changed={}", rerun_path.display());
165-
166-
Ok(())
167-
}
168-
169130
fn copy_folder(source: &Path, target: &Path, ignore_paths: &[&str]) -> Result<()> {
170131
let _ = remove_dir_all(target);
171132

core/tauri/build.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,6 @@ fn main() {
151151

152152
if target_os == "android" {
153153
if let Some(project_dir) = var_os("TAURI_ANDROID_PROJECT_PATH").map(PathBuf::from) {
154-
tauri_build::mobile::inject_android_project(
155-
"./mobile/android",
156-
project_dir.join(".tauri").join("tauri-api"),
157-
&[],
158-
)
159-
.expect("failed to copy tauri-api Android project");
160154
let tauri_proguard = include_str!("./mobile/proguard-tauri.pro").replace(
161155
"$PACKAGE",
162156
&var("WRY_ANDROID_PACKAGE").expect("missing `WRY_ANDROID_PACKAGE` environment variable"),

tooling/cli/templates/mobile/android/app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ dependencies {
8585
testImplementation("junit:junit:4.13.2")
8686
androidTestImplementation("androidx.test.ext:junit:1.1.4")
8787
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0")
88-
implementation(project(":tauri-android"))
8988
}
9089

9190
apply(from = "tauri.build.gradle.kts")

tooling/cli/templates/mobile/android/settings.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ include ':app'
22
{{~#each asset-packs}}
33
include ':{{this}}'{{/each}}
44

5-
include ':tauri-android'
6-
project(':tauri-android').projectDir = new File('./.tauri/tauri-api')
7-
85
apply from: 'tauri.settings.gradle'

0 commit comments

Comments
 (0)