Skip to content

Commit

Permalink
Add dexes to AAB (#19)
Browse files Browse the repository at this point in the history
Adds precompiled dex files to the AAB by adding the directories containing the precompiled dex files to the input of the `mergeDexRelease` gradle task. The `mergeDexRelease` gradle task takes a file collection called `dexDirs` as input. The files in that file collection will all be merged together into a single dex file which is then packaged into the AAB.
  • Loading branch information
maxded authored Dec 6, 2024
1 parent f920c1c commit fcef13f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions xbuild/src/gradle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,36 @@ pub fn build(env: &BuildEnv, libraries: Vec<(Target, PathBuf)>, out: &Path) -> R
dependencies.push_str(&format!("implementation '{}'\n", dep));
}

let mut dexes = String::new();
for dex in &env.config().android().dexes {
let mut path = env.cargo().package_root().join(dex);

// Pop the filename and use the directory.
//
// This is needed as we must provide a directory to `DexMergingTask::dexDirs`
path.pop();

let path = path.display().to_string().replace(r"\", r"/");

let external_lib = format!(r#"task.dexDirs.from("{path}")"#);
dexes.push_str(&external_lib);
dexes.push_str("\n");
}

let dexes = if !dexes.is_empty() {
format!(
r#"
afterEvaluate {{
tasks.named("mergeDexRelease").configure {{ task ->
{dexes}
}}
}}
"#
)
} else {
String::new()
};

let asset_packs = if config.assets.is_empty() {
""
} else {
Expand Down Expand Up @@ -94,6 +124,8 @@ pub fn build(env: &BuildEnv, libraries: Vec<(Target, PathBuf)>, out: &Path) -> R
dependencies {{
{dependencies}
}}
{dexes}
"#,
package = package,
target_sdk = target_sdk,
Expand Down

0 comments on commit fcef13f

Please sign in to comment.