Skip to content

Commit

Permalink
Add support for android string resource id in application label. (#146)
Browse files Browse the repository at this point in the history
Fixes  #145

 * New android metadata field 'apk_name' used for apk file naming (fall back to artifact name).
 * Remove useless 'android:name' field from android manifest.
 * CHANGELOG.md, README.md and formatting fixes.
 * CHANGELOG.md version and notes fixed.
 * Rewrite changelog entry and remove date for *unreleased* version
  • Loading branch information
xzenodart authored May 6, 2021
1 parent 7936944 commit a8d7129
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cargo-apk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased

- Added `apk_name` field to android metadata for APK file naming (defaults to Rust library name if unspecified).
The application label is now no longer used for this purpose, and can contain a string resource ID from now on.

# 0.6.0 (2021-04-20)

- **Breaking:** uses `ndk-build`'s new (de)serialized `Manifest` struct to properly serialize a toml's `[package.metadata.android]` to an `AndroidManifest.xml`. The `[package.metadata.android]` now closely resembles the structure of [an android manifest file](https://developer.android.com/guide/topics/manifest/manifest-element). See [README](README.md) for an example of the new `[package.metadata.android]` structure and all manifest attributes that are currently supported.
Expand Down
4 changes: 4 additions & 0 deletions cargo-apk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ resources = "path/to/resources_folder"
# If not specified, assets will not be included in the APK.
assets = "path/to/assets_folder"

# Name for final APK file.
# Defaults to package name.
apk_name = "myapp"

# See https://developer.android.com/guide/topics/manifest/uses-sdk-element
#
# Defaults to a `min_sdk_version` of 23 and `target_sdk_version` is based on the ndk's default platform.
Expand Down
6 changes: 6 additions & 0 deletions cargo-apk/src/apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,16 @@ impl<'a> ApkBuilder<'a> {
)
.to_owned()
});
let apk_name = self
.manifest
.apk_name
.clone()
.unwrap_or_else(|| artifact.name().to_string());

let config = ApkConfig {
ndk: self.ndk.clone(),
build_dir: self.build_dir.join(artifact),
apk_name,
assets,
resources,
manifest,
Expand Down
3 changes: 3 additions & 0 deletions cargo-apk/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::path::Path;

pub struct Manifest {
pub version: String,
pub apk_name: Option<String>,
pub android_manifest: AndroidManifest,
pub build_targets: Vec<Target>,
pub assets: Option<String>,
Expand All @@ -24,6 +25,7 @@ impl Manifest {
.unwrap_or_default();
Ok(Self {
version: toml.package.version,
apk_name: metadata.apk_name,
android_manifest: metadata.android_manifest,
build_targets: metadata.build_targets,
assets: metadata.assets,
Expand All @@ -50,6 +52,7 @@ struct PackageMetadata {

#[derive(Clone, Debug, Default, Deserialize)]
struct AndroidMetadata {
apk_name: Option<String>,
#[serde(flatten)]
android_manifest: AndroidManifest,
#[serde(default)]
Expand Down
4 changes: 4 additions & 0 deletions ndk-build/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

- New `ApkConfig` field `apk_name` is now used for APK file naming, instead of the application label.

# 0.2.0 (2021-04-20)

- **Breaking:** refactored `Manifest` into a proper (de)serialization struct. `Manifest` now closely matches [`an android manifest file`](https://developer.android.com/guide/topics/manifest/manifest-element).
Expand Down
6 changes: 3 additions & 3 deletions ndk-build/src/apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::process::Command;
pub struct ApkConfig {
pub ndk: Ndk,
pub build_dir: PathBuf,
pub apk_name: String,
pub assets: Option<PathBuf>,
pub resources: Option<PathBuf>,
pub manifest: AndroidManifest,
Expand All @@ -22,12 +23,11 @@ impl ApkConfig {

fn unaligned_apk(&self) -> PathBuf {
self.build_dir
.join(format!("{}-unaligned.apk", self.manifest.application.label))
.join(format!("{}-unaligned.apk", self.apk_name))
}

fn apk(&self) -> PathBuf {
self.build_dir
.join(format!("{}.apk", self.manifest.application.label))
self.build_dir.join(format!("{}.apk", self.apk_name))
}

pub fn create_apk(&self) -> Result<UnalignedApk, NdkError> {
Expand Down

0 comments on commit a8d7129

Please sign in to comment.