Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit 6a96bfb

Browse files
authored
Merge pull request #243 from philip-alldredge/241_asset_loading
Fix asset subdirectory loading issue
2 parents 6d17cff + bc647fe commit 6a96bfb

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

cargo-apk/src/ops/build.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -64,44 +64,36 @@ fn build_apks(
6464
.join("build-tools")
6565
.join(&config.build_tools_version);
6666
let aapt_path = build_tools_path.join("aapt");
67-
let aapt2_path = build_tools_path.join("aapt2");
6867
let zipalign_path = build_tools_path.join("zipalign");
6968

70-
// Compile resources
71-
let compiled_resources_filename = "resources.zip";
72-
if let Some(res_path) = &target_config.res_path {
73-
process(&aapt2_path)
74-
.arg("compile")
75-
.arg("--dir")
76-
.arg(res_path)
77-
.arg("-o")
78-
.arg(compiled_resources_filename)
79-
.cwd(&target_directory)
80-
.exec()?;
69+
// Create unaligned APK which includes resources and assets
70+
let unaligned_apk_name = format!("{}_unaligned.apk", target.name());
71+
let unaligned_apk_path = target_directory.join(&unaligned_apk_name);
72+
if unaligned_apk_path.exists() {
73+
std::fs::remove_file(unaligned_apk_path)
74+
.map_err(|e| format_err!("Unable to delete APK file. {}", e))?;
8175
}
8276

83-
// Create unaligned APK which includes resources
84-
let unaligned_apk_name = format!("{}_unaligned.apk", target.name());
85-
let mut aapt2_link_cmd = process(&aapt2_path);
86-
aapt2_link_cmd
87-
.arg("link")
88-
.arg("-o")
77+
let mut aapt_package_cmd = process(&aapt_path);
78+
aapt_package_cmd
79+
.arg("package")
80+
.arg("-F")
8981
.arg(&unaligned_apk_name)
90-
.arg("--manifest")
82+
.arg("-M")
9183
.arg("AndroidManifest.xml")
9284
.arg("-I")
9385
.arg(&config.android_jar_path);
9486

95-
if target_config.res_path.is_some() {
96-
aapt2_link_cmd.arg(compiled_resources_filename);
87+
if let Some(res_path) = target_config.res_path {
88+
aapt_package_cmd.arg("-S").arg(res_path);
9789
}
9890

9991
// Link assets
10092
if let Some(assets_path) = &target_config.assets_path {
101-
aapt2_link_cmd.arg("-A").arg(assets_path);
93+
aapt_package_cmd.arg("-A").arg(assets_path);
10294
}
10395

104-
aapt2_link_cmd.cwd(&target_directory).exec()?;
96+
aapt_package_cmd.cwd(&target_directory).exec()?;
10597

10698
// Add shared libraries to the APK
10799
for shared_library in shared_libraries {

0 commit comments

Comments
 (0)