Skip to main content

ApkBuilder

Struct ApkBuilder 

Source
pub struct ApkBuilder { /* private fields */ }
Expand description

An APK under construction.

Settings apply to one Manifest document, which is checked and then compiled exactly as it stands when the APK is written.

use apk::build::ApkBuilder;
use apk::res::Density;
use apk::sign::{Signer, SigningIdentity};
use apk::{Abi, ApiLevel, LibraryName, PackageName};

let mut app = ApkBuilder::native_activity(PackageName::try_new("org.example.game")?, LibraryName::try_new("game")?);
app.label("Game")
    .version(3.try_into()?, "1.2.0")
    .min_sdk(ApiLevel::LOLLIPOP)
    .permission("android.permission.INTERNET".parse()?)
    .localized_string("app_name", "fr".parse()?, "Jeu")?
    .icon(Density::XHDPI, std::fs::read("icon.png")?)?
    .asset("levels/1.json", std::fs::read("levels/1.json")?)?
    .native_library(Abi::Arm64V8a, "target/aarch64-linux-android/release/libgame.so")?
    .sign_with(Signer::new(SigningIdentity::from_pem_file("release.pem")?));
app.write("game.apk")?;

Implementations§

Source§

impl ApkBuilder

Source

pub fn new(manifest: Manifest) -> Self

Starts an APK from a complete manifest.

Source

pub fn native_activity(package: PackageName, library: LibraryName) -> Self

Starts a launchable app whose android.app.NativeActivity runs lib<library>.so. The app has no Java code.

Source

pub fn manifest(&self) -> &Manifest

Source

pub fn manifest_mut(&mut self) -> &mut Manifest

The manifest, for settings without a builder method.

Source

pub fn resources(&self) -> &Resources

Source

pub fn resources_mut(&mut self) -> &mut Resources

The resources, for values and files without a builder method.

Source

pub fn label(&mut self, label: impl Into<String>) -> &mut Self

Sets the app name shown by the launcher (string resource app_name, which can be translated with localized_string).

Source

pub fn version(&mut self, code: VersionCode, name: &str) -> &mut Self

Source

pub fn min_sdk(&mut self, level: ApiLevel) -> &mut Self

Source

pub fn target_sdk(&mut self, level: ApiLevel) -> &mut Self

Source

pub fn permission(&mut self, name: PermissionName) -> &mut Self

Source

pub fn debuggable(&mut self, debuggable: bool) -> &mut Self

Source

pub fn string( &mut self, name: &str, value: impl Into<String>, ) -> Result<&mut Self>

Adds the default value of string resource name.

Source

pub fn localized_string( &mut self, name: &str, locale: Locale, value: impl Into<String>, ) -> Result<&mut Self>

Adds a translation of string resource name.

Source

pub fn icon( &mut self, density: Density, png: impl Into<Content>, ) -> Result<&mut Self>

Adds a PNG launcher icon (@mipmap/ic_launcher) for one density.

Source

pub fn asset( &mut self, path: &str, content: impl Into<Content>, ) -> Result<&mut Self>

Adds a file under assets/, read by apps through AAssetManager.

Source

pub fn file( &mut self, path: ArchivePath, content: impl Into<Content>, options: Option<EntryOptions>, ) -> Result<&mut Self>

Adds any file at an exact archive path, stored with options (or the default for its extension).

Source

pub fn dex(&mut self, content: impl Into<Content>) -> &mut Self

Adds a DEX file (classes.dex, then classes2.dex, …).

Source

pub fn native_library( &mut self, abi: Abi, path: impl AsRef<Path>, ) -> Result<&mut Self>

Adds a native library from a file named lib<name>.so.

Source

pub fn native_library_bytes( &mut self, abi: Abi, name: LibraryName, bytes: impl Into<Content>, ) -> Result<&mut Self>

Adds a native library from memory as lib<name>.so.

Source

pub fn native_policy(&mut self, policy: NativePolicy) -> &mut Self

How native libraries are stored and checked.

Source

pub fn sign_with(&mut self, signer: Signer) -> &mut Self

Signs the APK when it is written, for the manifest’s SDK range.

Source

pub fn write(self, output: impl AsRef<Path>) -> Result<(), Error>

Completes the manifest, checks the whole configuration, and writes the APK to output atomically. The target is replaced only after validation and writing succeed.

Trait Implementations§

Source§

impl Clone for ApkBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ApkBuilder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.