Struct Dexer

Source
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

Source

pub fn new() -> Self

Creates a new Dexer instance with default values, which can be further customized using the builder methods.

Source

pub fn run(&self) -> Result<ExitStatus>

Executes the java command based on this Dexer instance.

Source

pub fn command(&self) -> Result<Command>

Returns a Command based on this Dexer instance that can be inspected or customized before being executed.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn files<P>(&mut self, files: P) -> &mut Self
where P: IntoIterator, P::Item: AsRef<OsStr>,

Adds multiple compiled Java bytecode files that you want to convert into DEX bytecode.

This is the same as calling Dexer::file() multiple times.

Source

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.

Trait Implementations§

Source§

impl Clone for Dexer

Source§

fn clone(&self) -> Dexer

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dexer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Dexer

Source§

fn default() -> Dexer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Dexer

§

impl RefUnwindSafe for Dexer

§

impl Send for Dexer

§

impl Sync for Dexer

§

impl Unpin for Dexer

§

impl UnwindSafe for Dexer

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.