|
@@ -1,7 +1,7 @@
|
|
|
use std::{
|
|
|
env::var,
|
|
|
fs::{self, rename},
|
|
|
- path::{PathBuf, MAIN_SEPARATOR},
|
|
|
+ path::{Path, PathBuf},
|
|
|
};
|
|
|
|
|
|
use anyhow::Result;
|
|
@@ -29,50 +29,18 @@ impl PluginBuilder {
|
|
|
if target_os == "android" {
|
|
|
if let Some(path) = self.android_path {
|
|
|
let manifest_dir = var("CARGO_MANIFEST_DIR").map(PathBuf::from).unwrap();
|
|
|
- if let (Ok(out_dir), Ok(gradle_settings_path), Ok(app_build_gradle_path)) = (
|
|
|
- var("TAURI_PLUGIN_OUTPUT_PATH"),
|
|
|
- var("TAURI_GRADLE_SETTINGS_PATH"),
|
|
|
- var("TAURI_APP_GRADLE_BUILD_PATH"),
|
|
|
- ) {
|
|
|
+ if let Ok(project_dir) = var("TAURI_ANDROID_PROJECT_PATH") {
|
|
|
let source = manifest_dir.join(path);
|
|
|
let pkg_name = var("CARGO_PKG_NAME").unwrap();
|
|
|
|
|
|
println!("cargo:rerun-if-env-changed=TAURI_PLUGIN_OUTPUT_PATH");
|
|
|
println!("cargo:rerun-if-env-changed=TAURI_GRADLE_SETTINGS_PATH");
|
|
|
- println!("cargo:rerun-if-changed={out_dir}{MAIN_SEPARATOR}{pkg_name}",);
|
|
|
- println!("cargo:rerun-if-changed={gradle_settings_path}");
|
|
|
- println!("cargo:rerun-if-changed={app_build_gradle_path}");
|
|
|
-
|
|
|
- let out_dir = PathBuf::from(out_dir);
|
|
|
- let target = out_dir.join(&pkg_name);
|
|
|
-
|
|
|
- // keep build folder if it exists
|
|
|
- let build_path = target.join("build");
|
|
|
- let out_dir = if build_path.exists() {
|
|
|
- let out_dir = out_dir.join(".tauri-plugin-build");
|
|
|
- rename(&build_path, &out_dir)?;
|
|
|
- Some(out_dir)
|
|
|
- } else {
|
|
|
- None
|
|
|
- };
|
|
|
-
|
|
|
- let _ = fs::remove_dir_all(&target);
|
|
|
-
|
|
|
- for entry in walkdir::WalkDir::new(&source) {
|
|
|
- let entry = entry?;
|
|
|
- let rel_path = entry.path().strip_prefix(&source)?;
|
|
|
- let dest_path = target.join(rel_path);
|
|
|
- if entry.file_type().is_dir() {
|
|
|
- fs::create_dir(dest_path)?;
|
|
|
- } else {
|
|
|
- fs::copy(entry.path(), dest_path)?;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- if let Some(out_dir) = out_dir {
|
|
|
- rename(out_dir, &build_path)?;
|
|
|
- }
|
|
|
+ let project_dir = PathBuf::from(project_dir);
|
|
|
|
|
|
+ inject_android_project(source, project_dir.join("tauri-plugins").join(&pkg_name))?;
|
|
|
+
|
|
|
+ let gradle_settings_path = project_dir.join("tauri.settings.gradle");
|
|
|
let gradle_settings = fs::read_to_string(&gradle_settings_path)?;
|
|
|
let include = format!(
|
|
|
"include ':{pkg_name}'
|
|
@@ -85,6 +53,7 @@ project(':{pkg_name}').projectDir = new File('./tauri-plugins/{pkg_name}')"
|
|
|
)?;
|
|
|
}
|
|
|
|
|
|
+ let app_build_gradle_path = project_dir.join("app").join("tauri.build.gradle.kts");
|
|
|
let app_build_gradle = fs::read_to_string(&app_build_gradle_path)?;
|
|
|
let implementation = format!(r#"implementation(project(":{pkg_name}"))"#);
|
|
|
let target = "dependencies {";
|
|
@@ -101,3 +70,38 @@ project(':{pkg_name}').projectDir = new File('./tauri-plugins/{pkg_name}')"
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+#[doc(hidden)]
|
|
|
+pub fn inject_android_project(source: impl AsRef<Path>, target: impl AsRef<Path>) -> 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");
|
|
|
+ rename(&build_path, &out_dir)?;
|
|
|
+ Some(out_dir)
|
|
|
+ } else {
|
|
|
+ None
|
|
|
+ };
|
|
|
+
|
|
|
+ let _ = fs::remove_dir_all(target);
|
|
|
+
|
|
|
+ for entry in walkdir::WalkDir::new(source) {
|
|
|
+ let entry = entry?;
|
|
|
+ let rel_path = entry.path().strip_prefix(source)?;
|
|
|
+ let dest_path = target.join(rel_path);
|
|
|
+ if entry.file_type().is_dir() {
|
|
|
+ fs::create_dir(dest_path)?;
|
|
|
+ } else {
|
|
|
+ fs::copy(entry.path(), dest_path)?;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if let Some(out_dir) = out_dir {
|
|
|
+ rename(out_dir, &build_path)?;
|
|
|
+ }
|
|
|
+
|
|
|
+ Ok(())
|
|
|
+}
|