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
impl ApkBuilder
Sourcepub fn native_activity(package: PackageName, library: LibraryName) -> Self
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.
pub fn manifest(&self) -> &Manifest
Sourcepub fn manifest_mut(&mut self) -> &mut Manifest
pub fn manifest_mut(&mut self) -> &mut Manifest
The manifest, for settings without a builder method.
pub fn resources(&self) -> &Resources
Sourcepub fn resources_mut(&mut self) -> &mut Resources
pub fn resources_mut(&mut self) -> &mut Resources
The resources, for values and files without a builder method.
Sourcepub fn label(&mut self, label: impl Into<String>) -> &mut Self
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).
pub fn version(&mut self, code: VersionCode, name: &str) -> &mut Self
pub fn min_sdk(&mut self, level: ApiLevel) -> &mut Self
pub fn target_sdk(&mut self, level: ApiLevel) -> &mut Self
pub fn permission(&mut self, name: PermissionName) -> &mut Self
pub fn debuggable(&mut self, debuggable: bool) -> &mut Self
Sourcepub fn string(
&mut self,
name: &str,
value: impl Into<String>,
) -> Result<&mut Self>
pub fn string( &mut self, name: &str, value: impl Into<String>, ) -> Result<&mut Self>
Adds the default value of string resource name.
Sourcepub fn localized_string(
&mut self,
name: &str,
locale: Locale,
value: impl Into<String>,
) -> Result<&mut Self>
pub fn localized_string( &mut self, name: &str, locale: Locale, value: impl Into<String>, ) -> Result<&mut Self>
Adds a translation of string resource name.
Sourcepub fn icon(
&mut self,
density: Density,
png: impl Into<Content>,
) -> Result<&mut Self>
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.
Sourcepub fn asset(
&mut self,
path: &str,
content: impl Into<Content>,
) -> Result<&mut Self>
pub fn asset( &mut self, path: &str, content: impl Into<Content>, ) -> Result<&mut Self>
Adds a file under assets/, read by apps through AAssetManager.
Sourcepub fn file(
&mut self,
path: ArchivePath,
content: impl Into<Content>,
options: Option<EntryOptions>,
) -> Result<&mut Self>
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).
Sourcepub fn dex(&mut self, content: impl Into<Content>) -> &mut Self
pub fn dex(&mut self, content: impl Into<Content>) -> &mut Self
Adds a DEX file (classes.dex, then classes2.dex, …).
Sourcepub fn native_library(
&mut self,
abi: Abi,
path: impl AsRef<Path>,
) -> Result<&mut Self>
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.
Sourcepub fn native_library_bytes(
&mut self,
abi: Abi,
name: LibraryName,
bytes: impl Into<Content>,
) -> Result<&mut Self>
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.
Sourcepub fn native_policy(&mut self, policy: NativePolicy) -> &mut Self
pub fn native_policy(&mut self, policy: NativePolicy) -> &mut Self
How native libraries are stored and checked.