Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit d4c77d6

Browse files
Documentation improvements. Avoid inheriting package_name and label.
1 parent ccb19e4 commit d4c77d6

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,34 @@ min_sdk_version = 26
110110
build_targets = [ "armv7-linux-androideabi", "aarch64-linux-android", "i686-linux-android", "x86_64-linux-android" ]
111111

112112
#
113-
# The following settings can be customized on a per bin/example basis. See multiple_targets example
113+
# The following value can be customized on a per bin/example basis. See multiple_targets example
114+
# If a value is not specified for a secondary target, it will inherit the value defined in the `package.metadata.android`
115+
# section unless otherwise noted.
114116
#
115117

116118
# The Java package name for your application.
117119
# Hyphens are converted to underscores.
120+
# Defaults to rust.<target_name> for binaries.
121+
# Defaults to rust.<package_name>.example.<target_name> for examples.
122+
# For example: for a binary "my_app", the default package name will be "rust.my_app"
123+
# Secondary targets will not inherit the value defined in the root android configuration.
118124
package_name = "rust.cargo.apk.advanced"
119125

120126
# The user-friendly name for your app, as displayed in the applications menu.
127+
# Defaults to the target name
128+
# Secondary targets will not inherit the value defined in the root android configuration.
121129
label = "My Android App"
122130

123-
# Path to your application's res/ folder.
131+
# Path to your application's resources folder.
132+
# If not specified, resources will not be included in the APK
124133
res = "path/to/res_folder"
125134

126135
# Virtual path your application's icon for any mipmap level.
136+
# If not specified, an icon will not be included in the APK.
127137
icon = "@mipmap/ic_launcher"
128138

129139
# Path to the folder containing your application's assets.
140+
# If not specified, assets will not be included in the APK
130141
assets = "path/to/assets_folder"
131142

132143
# If set to true, makes the app run in full-screen, by adding the following line
@@ -135,7 +146,8 @@ assets = "path/to/assets_folder"
135146
# Defaults to false.
136147
fullscreen = false
137148

138-
# The maximum supported OpenGL ES version , as claimed by the manifest. Defaults to 2.0.
149+
# The maximum supported OpenGL ES version , as claimed by the manifest.
150+
# Defaults to 2.0.
139151
# See https://developer.android.com/guide/topics/graphics/opengl.html#manifest
140152
opengles_version_major = 3
141153
opengles_version_minor = 2

cargo-apk/src/config.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ use std::path::PathBuf;
1616
use toml;
1717

1818
pub struct AndroidConfig {
19+
/// Name of the cargo package
20+
pub cargo_package_name: String,
21+
1922
/// Path to the manifest
2023
pub manifest_path: PathBuf,
2124
/// Path to the root of the Android SDK.
@@ -51,17 +54,19 @@ impl AndroidConfig {
5154
/// Builds the android target config based on the default target config and the specific target configs defined in the manifest
5255
pub fn resolve(&self, target: (TargetKind, String)) -> CargoResult<AndroidTargetConfig> {
5356
let primary_config = self.target_configs.get(&target);
54-
let package_name = target.1;
57+
let target_name = target.1;
58+
let is_default_target = target_name == self.cargo_package_name;
59+
let example = target.0 == TargetKind::ExampleBin;
5560

5661
Ok(AndroidTargetConfig {
5762
package_name: primary_config
5863
.and_then(|a| a.package_name.clone())
59-
.or_else(|| self.default_target_config.package_name.clone())
60-
.unwrap_or_else(|| format!("rust.{}", package_name)),
64+
.or_else(|| if is_default_target { self.default_target_config.package_name.clone() } else { None } )
65+
.unwrap_or_else(|| if example { format!("rust.{}.example.{}", self.cargo_package_name, target_name) } else { format!("rust.{}", target_name) } ),
6166
package_label: primary_config
6267
.and_then(|a| a.label.clone())
63-
.or_else(|| self.default_target_config.label.clone())
64-
.unwrap_or_else(|| package_name.clone()),
68+
.or_else(|| if is_default_target { self.default_target_config.label.clone() } else { None } )
69+
.unwrap_or_else(|| target_name.clone()),
6570
package_icon: primary_config
6671
.and_then(|a| a.icon.clone())
6772
.or_else(|| self.default_target_config.icon.clone()),
@@ -333,6 +338,7 @@ pub fn load(
333338

334339
// For the moment some fields of the config are dummies.
335340
Ok(AndroidConfig {
341+
cargo_package_name: package.name().to_string(),
336342
manifest_path: package.manifest_path().to_owned(),
337343
sdk_path: Path::new(&sdk_path).to_owned(),
338344
ndk_path: Path::new(&ndk_path).to_owned(),
@@ -380,6 +386,7 @@ struct TomlMetadata {
380386
}
381387

382388
#[derive(Debug, Clone, Deserialize)]
389+
#[serde(deny_unknown_fields)]
383390
struct TomlAndroid {
384391
android_version: Option<u32>,
385392
target_sdk_version: Option<u32>,
@@ -394,20 +401,23 @@ struct TomlAndroid {
394401
}
395402

396403
#[derive(Debug, Clone, Deserialize)]
404+
#[serde(deny_unknown_fields)]
397405
struct TomlFeature {
398406
name: String,
399407
required: Option<bool>,
400408
version: Option<String>,
401409
}
402410

403411
#[derive(Debug, Clone, Deserialize)]
412+
#[serde(deny_unknown_fields)]
404413
struct TomlPermission {
405414
name: String,
406415
max_sdk_version: Option<u32>,
407416
}
408417

409418
/// Configuration specific to a single cargo target
410419
#[derive(Debug, Clone, Deserialize)]
420+
#[serde(deny_unknown_fields)]
411421
struct TomlAndroidSpecificTarget {
412422
name: String,
413423

examples/advanced/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ min_sdk_version = 26
1919
build_targets = [ "armv7-linux-androideabi", "aarch64-linux-android", "i686-linux-android", "x86_64-linux-android" ]
2020

2121
#
22-
# The following settings can be customized on a per bin/example basis. See multiple_targets example
22+
# The following value can be customized on a per bin/example basis. See multiple_targets example
23+
# If a value is not specified for a secondary target, it will inherit the value defined in the `package.metadata.android`
24+
# section unless otherwise noted.
2325
#
2426

2527
# The Java package name for your application.

0 commit comments

Comments
 (0)