Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.
Merged
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ with the regular `cargo build`.

This will build an Android package in `target/android-artifacts/<debug|release>/apk`.

### Compiling Multiple Binaries

`cargo apk build` supports building multiple binaries and examples using the same arguments as `cargo build`. It will produce an APK for each binary.

Android packages for bin targets are placed in `target/android-artifacts/<debug|release>/apk/examples`.
Android packages for example targets are placed in `target/android-artifacts/<debug|release>/apk/examples`.

### Testing on an Android emulator

Start the emulator, then run:
Expand Down Expand Up @@ -110,16 +117,16 @@ build_targets = [ "armv7-linux-androideabi", "aarch64-linux-android", "i686-linu
package_name = "rust.cargo.apk.advanced"

# The user-friendly name for your app, as displayed in the applications menu.
label = "Advanced android-rs-glue example"
label = "My Android App"

# Path to your application's res/ folder.
res = "res"
res = "path/to/res_folder"

# Virtual path your application's icon for any mipmap level.
icon = "@mipmap/ic_launcher"

# Path to the folder containing your application's assets.
assets = "assets"
assets = "path/to/assets_folder"

# If set to true, makes the app run in full-screen, by adding the following line
# as an XML attribute to the manifest's <application> tag :
Expand All @@ -144,6 +151,11 @@ opengles_version_minor = 2
"android:screenOrientation" = "unspecified"
"android:uiOptions" = "none"

# Adds a uses-feature element to the manifest
# Supported keys: name, required, version
# The glEsVersion attribute is not supported using this section.
# It can be specified using the opengles_version_major and opengles_version_minor values
# See https://developer.android.com/guide/topics/manifest/uses-feature-element
[[package.metadata.android.feature]]
name = "android.hardware.camera"

Expand All @@ -152,15 +164,14 @@ name = "android.hardware.vulkan.level"
version = "1"
required = false

# Request permissions. Note that android_version 23 and higher, Android requires the application
# to request permissions at runtime. There is currently no way to do this using a pure NDK based application.
# Adds a uses-permission element to the manifest.
# Note that android_version 23 and higher, Android requires the application to request permissions at runtime.
# There is currently no way to do this using a pure NDK based application.
# See https://developer.android.com/guide/topics/manifest/uses-permission-element
[[package.metadata.android.permission]]
name = "android.permission.WRITE_EXTERNAL_STORAGE"
maxSdkVersion = "18"

[[package.metadata.android.permission]]
name = "android.permission.CAMERA"

[dependencies.android_glue]
path = "../../glue"
```
4 changes: 0 additions & 4 deletions cargo-apk/injected-glue/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ pub const APP_CMD_PAUSE: i32 = 13;
pub const APP_CMD_STOP: i32 = 14;
pub const APP_CMD_DESTROY: i32 = 15;

extern {
pub fn app_dummy();
}

pub const MODE_BUFFER: i32 = 3;
pub const MODE_RANDOM: i32 = 1;
pub const MODE_STREAMING: i32 = 2;
Expand Down
1 change: 0 additions & 1 deletion cargo-apk/injected-glue/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ pub fn get_app<'a>() -> &'a mut ffi::android_app {
pub fn android_main2<F>(app: *mut ffi::android_app, main_function: F)
where F: FnOnce() + 'static + Send
{
unsafe { ffi::app_dummy() };
write_log("Entering android_main");

unsafe { ANDROID_APP = app; };
Expand Down
7 changes: 0 additions & 7 deletions examples/advanced/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions examples/advanced/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "advanced"
version = "0.1.0"
authors = ["Philip Alldredge <[email protected]"]
publish = false
edition = "2018"

[package.metadata.android]
# The target Android API level.
Expand Down Expand Up @@ -60,6 +61,11 @@ opengles_version_minor = 2
"android:screenOrientation" = "unspecified"
"android:uiOptions" = "none"

# Adds a uses-feature element to the manifest
# Supported keys: name, required, version
# The glEsVersion attribute is not supported using this section.
# It can be specified using the opengles_version_major and opengles_version_minor values
# See https://developer.android.com/guide/topics/manifest/uses-feature-element
[[package.metadata.android.feature]]
name = "android.hardware.camera"

Expand All @@ -68,14 +74,13 @@ name = "android.hardware.vulkan.level"
version = "1"
required = false

# Request permissions. Note that android_version 23 and higher, Android requires the application
# to request permissions at runtime. There is currently no way to do this using a pure NDK based application.
# Adds a uses-permission element to the manifest.
# Note that android_version 23 and higher, Android requires the application to request permissions at runtime.
# There is currently no way to do this using a pure NDK based application.
# See https://developer.android.com/guide/topics/manifest/uses-permission-element
[[package.metadata.android.permission]]
name = "android.permission.WRITE_EXTERNAL_STORAGE"
maxSdkVersion = "18"

[[package.metadata.android.permission]]
name = "android.permission.CAMERA"

[dependencies.android_glue]
path = "../../glue"
5 changes: 1 addition & 4 deletions examples/advanced/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate android_glue;

fn main() {
android_glue::write_log("main() has been called from advanced example");
loop {}
println!("main() has been called from advanced example");
}
2 changes: 2 additions & 0 deletions examples/basic/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/basic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "android_glue_example"
version = "0.1.0"
authors = ["Pierre Krieger <[email protected]>"]
edition = "2018"

[package.metadata.android]
label = "Basic android-rs-glue example"
Expand Down
3 changes: 0 additions & 3 deletions examples/basic/src/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate android_glue;

fn main() {
android_glue::write_log("main() has been called");
loop {}
}
1 change: 1 addition & 0 deletions examples/multiple_targets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "android_primary_bin"
version = "0.1.0"
authors = ["Philip Alldredge <[email protected]>"]
publish = false
edition = "2018"

[dependencies.android_glue]
path = "../../glue"
Expand Down
4 changes: 1 addition & 3 deletions examples/multiple_targets/examples/example1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
fn main() {
#[cfg(target_os = "android")]
android_glue::write_log("main() has been called on example1");
loop {}
println!("main() has been called on example1");
}
4 changes: 1 addition & 3 deletions examples/multiple_targets/src/bin/secondary_bin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
fn main() {
#[cfg(target_os = "android")]
android_glue::write_log("main() has been called on the secondary binary");
loop {}
println!("main() has been called on the secondary binary");
}
4 changes: 1 addition & 3 deletions examples/multiple_targets/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
fn main() {
#[cfg(target_os = "android")]
android_glue::write_log("main() has been called on the primary binary");
loop {}
println!("main() has been called on the primary binary");
}
12 changes: 7 additions & 5 deletions examples/use_assets/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions examples/use_assets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "android_glue_assets_example"
version = "0.1.0"
authors = ["Pierre Krieger <[email protected]>"]

[package.metadata.android]
label = "Using assets android-rs-glue example"
assets = "assets"

[dependencies.android_glue]
path = "../../glue"
[package]
name = "android_glue_assets_example"
version = "0.1.0"
authors = ["Pierre Krieger <[email protected]>"]
edition = "2018"

[package.metadata.android]
label = "Using assets android-rs-glue example"
assets = "assets"

[dependencies.android_glue]
path = "../../glue"
2 changes: 0 additions & 2 deletions examples/use_assets/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate android_glue;

mod fs;

use std::io::BufRead;
Expand Down
12 changes: 7 additions & 5 deletions examples/use_icon/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/use_icon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "android_glue_icon_example"
version = "0.1.0"
authors = ["Pierre Krieger <[email protected]>"]
edition = "2018"

[package.metadata.android]
label = "Using icon android-rs-glue example"
Expand Down
3 changes: 0 additions & 3 deletions examples/use_icon/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate android_glue;

fn main() {
android_glue::write_log("main() has been called, did you like the icon?");
loop {}
}