pub struct Dexer { /* private fields */ }
Expand description
A builder for generating Android DEX bytecode by invoking d8
commands.
Currently incremental building options are not provided here.
If you need to customize the d8
command beyond what is provided here,
you can use the Dexer::command()
method to get a Command
that can be further customized with additional arguments.
Documentation on d8
options are based on
https://developer.android.com/tools/d8/.
Note: Newer JDK versions (including JDK 21 and above) may not work with
Android D8 from older build tools versions (below 35.0.0) if there are
anonymous classes in the Java code, which produce files like Cls$1.class
.
Implementations§
Source§impl Dexer
impl Dexer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Dexer
instance with default values,
which can be further customized using the builder methods.
Sourcepub fn run(&self) -> Result<ExitStatus>
pub fn run(&self) -> Result<ExitStatus>
Executes the java
command based on this Dexer
instance.
Sourcepub fn command(&self) -> Result<Command>
pub fn command(&self) -> Result<Command>
Returns a Command
based on this Dexer
instance
that can be inspected or customized before being executed.
Sourcepub fn java_home<P: AsRef<OsStr>>(&mut self, java_home: P) -> &mut Self
pub fn java_home<P: AsRef<OsStr>>(&mut self, java_home: P) -> &mut Self
Override the default JAVA_HOME
path.
If not set, the default path is found using the JAVA_HOME
env var.
Sourcepub fn android_d8_jar<P: AsRef<OsStr>>(
&mut self,
android_d8_jar_path: P,
) -> &mut Self
pub fn android_d8_jar<P: AsRef<OsStr>>( &mut self, android_d8_jar_path: P, ) -> &mut Self
Override the default d8.jar
path.
Otherwise, the default path is found using crate::android_d8_jar.
Sourcepub fn release(&mut self, release: bool) -> &mut Self
pub fn release(&mut self, release: bool) -> &mut Self
Compile DEX bytecode without debug information (including those enabled with
crate::DebugInfo when running crate::JavaBuild). However, d8
includes some
information that’s used when generating stacktraces and logging exceptions.
Sourcepub fn android_min_api(&mut self, api_level: u32) -> &mut Self
pub fn android_min_api(&mut self, api_level: u32) -> &mut Self
Specify the minimum Android API level you want the output DEX files to support.
Set it to 20
to disable the multidex feature, so it may be loaded by DexClassLoader
available on Android 7.1 and older versions without using the legacy multidex library.
This is also useful if you want to make sure of having only one classes.dex
output
file; still, it keeps compatible with newest Android versions.
Sourcepub fn no_desugaring(&mut self, no_desugaring: bool) -> &mut Self
pub fn no_desugaring(&mut self, no_desugaring: bool) -> &mut Self
Disable Java 8 language features. Use this flag only if you don’t intend to compile Java bytecode that uses language features introduced in Java 8.
Sourcepub fn android_jar<P: AsRef<OsStr>>(&mut self, android_jar_path: P) -> &mut Self
pub fn android_jar<P: AsRef<OsStr>>(&mut self, android_jar_path: P) -> &mut Self
Specify the path to the android.jar
of your Android SDK. This is required when
compiling bytecode that uses Java 8 language features.
If not set, the default path is found using crate::android_jar.
Sourcepub fn class_path<S: AsRef<OsStr>>(&mut self, class_path: S) -> &mut Self
pub fn class_path<S: AsRef<OsStr>>(&mut self, class_path: S) -> &mut Self
Specify classpath resources that d8
may require to compile your project’s DEX files.
In particular, d8
requires that you specify certain resources when compiling bytecode
that uses Java 8 language features.
This is usually the the path to all of your project’s Java bytecode, even if you don’t
intend to compile all of the bytecode into DEX bytecode.
Sourcepub fn out_dir<P: AsRef<OsStr>>(&mut self, out_dir: P) -> &mut Self
pub fn out_dir<P: AsRef<OsStr>>(&mut self, out_dir: P) -> &mut Self
Specify the desired path for the DEX output. By default, d8
outputs the DEX file(s)
in the current working directory.
Sourcepub fn file<P: AsRef<OsStr>>(&mut self, file: P) -> &mut Self
pub fn file<P: AsRef<OsStr>>(&mut self, file: P) -> &mut Self
Adds a compiled Java bytecode file that you want to convert into DEX bytecode.
The input bytecode can be in any combination of *.class
files or containers, such as
JAR, APK, or ZIP files.
Sourcepub fn files<P>(&mut self, files: P) -> &mut Self
pub fn files<P>(&mut self, files: P) -> &mut Self
Adds multiple compiled Java bytecode files that you want to convert into DEX bytecode.
This is the same as calling Dexer::file()
multiple times.
Sourcepub fn collect_classes<P: AsRef<OsStr>>(
&mut self,
class_path: P,
) -> Result<&mut Self>
pub fn collect_classes<P: AsRef<OsStr>>( &mut self, class_path: P, ) -> Result<&mut Self>
Searches and adds .class
files under class_path
directory recursively.
This is the same as calling Dexer::files()
for these files, usually more convenient.