#![cfg(feature = "android")]
use crossbundle_tools::{commands::android::*, types::*};
#[test]
fn test_aapt2_compile() {
let tempfile = tempfile::tempdir().unwrap();
let compiled_res_dir = tempfile.path().to_path_buf();
assert!(compiled_res_dir.exists());
let user_dirs = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let dir = user_dirs.parent().unwrap().parent().unwrap().to_path_buf();
let res_path = dir
.join("assets")
.join("res")
.join("android")
.join("mipmap-hdpi");
assert!(res_path.exists());
let sdk = AndroidSdk::from_env().unwrap();
let compiled_res = sdk
.aapt2()
.unwrap()
.compile_incremental(&res_path, &compiled_res_dir)
.run()
.unwrap();
assert!(compiled_res.exists());
}
#[test]
fn test_aapt2_link() {
let tempfile = tempfile::tempdir().unwrap();
let tempdir = tempfile.path().to_path_buf();
assert!(tempdir.exists());
let sdk = AndroidSdk::from_env().unwrap();
let user_dirs = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let dir = user_dirs.parent().unwrap().parent().unwrap().to_path_buf();
let res_path = dir
.join("assets")
.join("res")
.join("android")
.join("mipmap-hdpi");
assert!(res_path.exists());
let aapt2_compile = sdk
.aapt2()
.unwrap()
.compile_incremental(dunce::simplified(&res_path), dunce::simplified(&tempdir));
let compiled_res = aapt2_compile.run().unwrap();
assert!(compiled_res.exists());
let mut android_manifest = android_manifest::AndroidManifest {
package: "com.crossbow.example".to_owned(),
..Default::default()
};
update_android_manifest_with_default(
&mut android_manifest,
Some("Example".to_owned()),
"example",
AndroidStrategy::NativeApk,
);
let manifest_path = save_android_manifest(&tempdir, &android_manifest).unwrap();
assert!(manifest_path.exists());
let apk_path = tempdir.join("test.apk");
let target_sdk_version = 31;
let mut aapt2_link =
sdk.aapt2()
.unwrap()
.link_inputs(&[compiled_res], &apk_path, &manifest_path);
aapt2_link
.android_jar(sdk.android_jar(target_sdk_version).unwrap())
.proto_format(true)
.auto_add_overlay(true)
.verbose(true);
aapt2_link.run().unwrap();
}