Skip to content

Commit cb58e24

Browse files
authored
Update Docker image and add CI test of it (#124)
* Update dockerfile * Alter dockerfile * Remove TTY and alter install command emulator doc * Fix android sdk resolution issues * Bump versions
1 parent d5d7c07 commit cb58e24

File tree

25 files changed

+128
-91
lines changed

25 files changed

+128
-91
lines changed

.github/docker/crossbundle.Dockerfile

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
1-
FROM eclipse-temurin:11.0.13_8-jdk
1+
FROM androidsdk/android-30
22
LABEL org.opencontainers.image.source https://github.com/dodorare/crossbow
33

44
RUN apt update -yq && apt upgrade -yq \
55
&& apt install -yq curl unzip wget cmake build-essential pkg-config libssl-dev libssl1.1
66

7-
# Install Android SDK
8-
ENV ANDROID_SDK_ROOT=/opt/android-sdk-linux
9-
RUN mkdir -p ${ANDROID_SDK_ROOT}/cmdline-tools \
10-
&& cd ${ANDROID_SDK_ROOT}/cmdline-tools \
11-
&& wget -q https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip \
12-
&& unzip -q commandlinetools-linux-8512546_latest.zip \
13-
&& rm commandlinetools-linux-8512546_latest.zip \
14-
&& mv cmdline-tools/ latest/ \
15-
&& chown -R root:root /opt
7+
# Install Android NDK
168
RUN ulimit -c unlimited
17-
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "platform-tools"
18-
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "platforms;android-30"
19-
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "build-tools;31.0.0"
20-
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "ndk;23.1.7779620"
21-
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --update
9+
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/sdkmanager "ndk;23.1.7779620"
10+
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/sdkmanager --update
2211
ENV ANDROID_NDK_ROOT=${ANDROID_SDK_ROOT}/ndk/23.1.7779620
2312

2413
# Install bundletool
25-
RUN wget -q https://github.com/google/bundletool/releases/download/1.8.2/bundletool-all-1.8.2.jar \
26-
&& mv bundletool-all-1.8.2.jar ${ANDROID_SDK_ROOT}/bundletool-all-1.8.2.jar
14+
RUN wget -q https://github.com/google/bundletool/releases/download/1.8.2/bundletool-all-1.8.2.jar
2715
ENV BUNDLETOOL_PATH=${ANDROID_SDK_ROOT}/bundletool-all-1.8.2.jar
2816

2917
RUN wget https://services.gradle.org/distributions/gradle-7.4-all.zip \

.github/workflows/ci.yml

+11
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ jobs:
6868
cd ~/example/
6969
crossbundle build android --apk --release --quad
7070
71+
build-example-in-docker:
72+
name: Build Crossbundle Example from Docker
73+
runs-on: ubuntu-latest
74+
steps:
75+
- uses: actions/checkout@master
76+
- name: Build Crossbundle image
77+
run: docker build -t tmp -f .github/docker/crossbundle.Dockerfile .
78+
- name: Build Crossbundle Example
79+
run: |
80+
docker run --rm -v "$(pwd)/:/src" -w /src/examples/macroquad-permissions tmp build android --quad --release
81+
7182
clean:
7283
name: Check code format
7384
runs-on: ubuntu-latest

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "crossbow"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
edition = "2021"
55
authors = ["DodoRare Team <support@dodorare.com>"]
66
description = "Cross-Platform Rust Toolkit for Games 🏹"
@@ -16,11 +16,11 @@ displaydoc = "0.2"
1616
anyhow = "1.0"
1717

1818
[target.'cfg(target_os = "android")'.dependencies]
19-
crossbow-android = { path = "platform/android", version = "0.1.6", optional = true }
19+
crossbow-android = { path = "platform/android", version = "0.1.7", optional = true }
2020
ndk-glue = "0.6.2"
2121

2222
[target.'cfg(target_os = "ios")'.dependencies]
23-
crossbow-ios = { path = "platform/ios", version = "0.1.6", optional = true }
23+
crossbow-ios = { path = "platform/ios", version = "0.1.7", optional = true }
2424

2525
[patch.crates-io]
2626
winit = { git = "https://github.com/rust-windowing/winit", rev = "f93f2c158bf527ed56ab2b6f5272214f0c1d9f7d" }

crossbundle/cli/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "crossbundle"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
edition = "2021"
55
authors = ["DodoRare Team <support@dodorare.com>"]
66
description = "Build and publish apps for Android/iOS"
@@ -18,7 +18,7 @@ name = "crossbundle"
1818
path = "src/main.rs"
1919

2020
[dependencies]
21-
crossbundle-tools = { path = "../tools", version = "0.1.6" }
21+
crossbundle-tools = { path = "../tools", version = "0.1.7" }
2222
android-tools = "0.2.9"
2323
clap = { version = "3.2.8", features = ["derive"] }
2424
serde = { version = "1.0", features = ["derive"] }

crossbundle/cli/src/commands/build/android.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ use crate::types::MIN_SDK_VERSION;
22

33
use super::{BuildContext, SharedBuildCommand};
44
use android_manifest::AndroidManifest;
5-
use android_tools::{
6-
java_tools::{JarSigner, Key},
7-
sdk_install_path,
8-
};
5+
use android_tools::java_tools::{JarSigner, Key};
96
use clap::Parser;
107
use crossbundle_tools::{
118
commands::android::{self, rust_compile},
@@ -77,6 +74,7 @@ impl AndroidBuildCommand {
7774
context: &BuildContext,
7875
export_path: &Option<PathBuf>,
7976
) -> crate::error::Result<(AndroidManifest, AndroidSdk, PathBuf)> {
77+
let sdk = AndroidSdk::from_env()?;
8078
let profile = self.shared.profile();
8179
let example = self.shared.example.as_ref();
8280
let (_, target_dir, package_name) = Self::needed_project_dirs(example, context)?;
@@ -89,9 +87,12 @@ impl AndroidBuildCommand {
8987
target_dir.join("android").join(&package_name)
9088
};
9189

92-
config.status("Generating gradle project")?;
93-
std::env::set_var("ANDROID_SDK_ROOT", sdk_install_path()?.to_str().unwrap());
90+
// Set ANDROID_SDK_ROOT if there's no one
91+
if std::env::var("ANDROID_SDK_ROOT").is_err() {
92+
std::env::set_var("ANDROID_SDK_ROOT", sdk.sdk_path());
93+
}
9494

95+
config.status("Generating gradle project")?;
9596
let gradle_project_path = android::gen_gradle_project(
9697
&android_build_dir,
9798
&context.android_config.assets,
@@ -100,7 +101,6 @@ impl AndroidBuildCommand {
100101
)?;
101102

102103
// Get AndroidManifest.xml from file or generate from Cargo.toml
103-
let (sdk, _, _) = Self::android_toolchain(context)?;
104104
let (android_manifest, _manifest_path) = Self::android_manifest(
105105
config,
106106
context,

crossbundle/cli/src/commands/install/command_line_tools.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use super::*;
2-
use android_tools::sdk_install_path;
32
use clap::Parser;
43
use crossbundle_tools::{
54
commands::android::{self, remove},
5+
tools::AndroidSdk,
66
utils::Config,
77
};
88
use std::path::{Path, PathBuf};
@@ -38,7 +38,8 @@ impl CommandLineToolsInstallCommand {
3838
)?;
3939
self.download_and_save_file(command_line_tools_download_url, &file_path)?;
4040

41-
let sdk_path = sdk_install_path()?;
41+
let sdk = AndroidSdk::from_env()?;
42+
let sdk_path = sdk.sdk_path();
4243

4344
if let Some(path) = &self.install_path {
4445
config.status_message(

crossbundle/cli/src/commands/install/sdkmanager.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::path::Path;
2-
3-
use android_tools::sdk_install_path;
41
use clap::Parser;
5-
use crossbundle_tools::{error::CommandExt, utils::Config, EXECUTABLE_SUFFIX_BAT};
2+
use crossbundle_tools::{
3+
error::CommandExt, tools::AndroidSdk, utils::Config, EXECUTABLE_SUFFIX_BAT,
4+
};
5+
use std::path::Path;
66

77
#[derive(Parser, Clone, Debug, Default)]
88
pub struct SdkManagerInstallCommand {
@@ -157,23 +157,24 @@ impl SdkManagerInstallCommand {
157157

158158
/// Run sdkmanager command with specified flags and options
159159
pub fn run(&self, _config: &Config) -> crate::error::Result<()> {
160-
let sdk_root = sdk_install_path()?;
161-
// Android studio install cmdline tools into SDK_ROOT/cmdline-tools/<version>/bin.
160+
let sdk = AndroidSdk::from_env()?;
161+
let sdk_path = sdk.sdk_path();
162+
// Android Studio installs cmdline-tools into $ANDROID_SDK_ROOT/cmdline-tools/<version>/bin.
162163
// Crossbundle install command ignores <version> directory so we need convert cmd-line-tools path to Option<T> to avoid confusion
163-
let cmdline_tools_path = std::path::PathBuf::from(&sdk_root)
164+
let cmdline_tools_path = std::path::PathBuf::from(&sdk_path)
164165
.join("cmdline-tools")
165166
.join("latest")
166167
.join("bin");
167168
if cmdline_tools_path.exists() {
168169
let sdkmanager_path =
169170
cmdline_tools_path.join(format!("sdkmanager{}", EXECUTABLE_SUFFIX_BAT));
170-
self.sdkmanager_command(&sdkmanager_path, Path::new(&sdk_root))?;
171+
self.sdkmanager_command(&sdkmanager_path, Path::new(&sdk_path))?;
171172
} else {
172-
let sdkmanager_path = std::path::PathBuf::from(&sdk_root)
173+
let sdkmanager_path = std::path::PathBuf::from(&sdk_path)
173174
.join("cmdline-tools")
174175
.join("bin")
175176
.join(format!("sdkmanager{}", EXECUTABLE_SUFFIX_BAT));
176-
self.sdkmanager_command(&sdkmanager_path, Path::new(&sdk_root))?;
177+
self.sdkmanager_command(&sdkmanager_path, Path::new(&sdk_path))?;
177178
};
178179
Ok(())
179180
}

crossbundle/tools/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "crossbundle-tools"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
edition = "2021"
55
authors = ["DodoRare Team <support@dodorare.com>"]
66
description = "Build and publish apps for Android/iOS"

crossbundle/tools/src/tools/android_ndk.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,29 @@ impl AndroidNdk {
2121
.or_else(|| std::env::var("ANDROID_NDK_HOME").ok())
2222
.or_else(|| std::env::var("NDK_HOME").ok());
2323
// Default ndk installation path
24-
if ndk_path.is_none()
24+
if let Some(ndk_path) = ndk_path {
25+
PathBuf::from(ndk_path)
26+
} else if ndk_path.is_none()
2527
&& sdk_path.is_some()
2628
&& sdk_path.as_ref().unwrap().join("ndk-bundle").exists()
2729
{
2830
sdk_path.unwrap().join("ndk-bundle")
29-
} else if let Some(ndk_path) = ndk_path {
30-
PathBuf::from(ndk_path)
3131
} else {
32-
PathBuf::from(ndk_install_path()?)
32+
let ndk_path = if let Some(sdk_path) = sdk_path {
33+
sdk_path.to_owned()
34+
} else {
35+
android_tools::sdk_install_path()?
36+
}
37+
.join("ndk");
38+
let ndk_ver = std::fs::read_dir(&ndk_path)
39+
.map_err(|_| Error::PathNotFound(ndk_path.clone()))?
40+
.filter_map(|path| path.ok())
41+
.filter(|path| path.path().is_dir())
42+
.filter_map(|path| path.file_name().into_string().ok())
43+
.filter(|name| name.chars().next().unwrap().is_ascii_digit())
44+
.max()
45+
.ok_or(AndroidError::AndroidNdkNotFound)?;
46+
ndk_path.join(ndk_ver)
3347
}
3448
};
3549
let build_tag = std::fs::read_to_string(ndk_path.join("source.properties"))
@@ -322,17 +336,3 @@ impl AndroidNdk {
322336
Ok(version_specific_libraries_path)
323337
}
324338
}
325-
326-
pub fn ndk_install_path() -> crate::error::Result<String> {
327-
let ndk_path = android_tools::sdk_install_path()?.join("ndk");
328-
let ndk_ver = std::fs::read_dir(&ndk_path)
329-
.map_err(|_| Error::PathNotFound(ndk_path.clone()))?
330-
.filter_map(|path| path.ok())
331-
.filter(|path| path.path().is_dir())
332-
.filter_map(|path| path.file_name().into_string().ok())
333-
.filter(|name| name.chars().next().unwrap().is_ascii_digit())
334-
.max()
335-
.ok_or(AndroidError::AndroidNdkNotFound)?;
336-
let ndk_install_path = ndk_path.join(ndk_ver).to_str().unwrap().to_string();
337-
Ok(ndk_install_path)
338-
}

crossbundle/tools/src/tools/android_sdk.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ impl AndroidSdk {
2121
.ok()
2222
.or_else(|| std::env::var("ANDROID_SDK_PATH").ok())
2323
.or_else(|| std::env::var("ANDROID_HOME").ok());
24-
PathBuf::from(
25-
sdk_path.unwrap_or(
26-
android_tools::sdk_install_path()?
27-
.to_str()
28-
.unwrap()
29-
.to_string(),
30-
),
31-
)
24+
if let Some(sdk_path) = sdk_path {
25+
PathBuf::from(sdk_path)
26+
} else {
27+
android_tools::sdk_install_path()?
28+
}
3229
};
3330
let build_deps_path = sdk_path.join("build-tools");
3431
let build_deps_version = std::fs::read_dir(&build_deps_path)

docs/src/install/android-linux.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,18 @@ To prepare to run your `Crossbow` app on an Android device, you need an Android
5757

5858
## Set up the Android emulator
5959

60-
To prepare to run and test your Flutter app on the Android emulator, follow these steps:
60+
To prepare to run and test your Crossbow app on the Android emulator, follow these steps if you want to install it from the console:
61+
62+
```sh
63+
# Run following command to install System Image for Android SDK 30
64+
crossbundle install sdk-manager --install "system-images;android-30;google_apis;x86_64"
65+
# Run this command to create a new emulator
66+
avdmanager create avd -n Phone -k "system-images;android-30;google_apis;x86_64"
67+
# And finally run this command to start the emulator
68+
emulator -avd=Phone
69+
```
70+
71+
If you want to install it from the GUI, follow these instructions:
6172

6273
1. Enable [`VM acceleration`](https://developer.android.com/studio/run/emulator-acceleration) on your machine.
6374
2. Launch **Android Studio**, click the **AVD Manager** icon, and select **Create Virtual Device**.

docs/src/install/android-macos.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,18 @@ To prepare to run your `crossbow` app on an Android device, you need an Android
5757

5858
## Set up the Android emulator
5959

60-
To prepare to run and test your Crossbow app on the Android emulator, follow these steps:
60+
To prepare to run and test your Crossbow app on the Android emulator, follow these steps if you want to install it from the console:
61+
62+
```sh
63+
# Run following command to install System Image for Android SDK 30
64+
crossbundle install sdk-manager --install "system-images;android-30;google_apis;x86_64"
65+
# Run this command to create a new emulator
66+
avdmanager create avd -n Phone -k "system-images;android-30;google_apis;x86_64"
67+
# And finally run this command to start the emulator
68+
emulator -avd=Phone
69+
```
70+
71+
If you want to install it from the GUI, follow these instructions:
6172

6273
1. Enable [`VM acceleration`](https://developer.android.com/studio/run/emulator-acceleration) on your machine.
6374
2. Launch **Android Studio**, click the **AVD Manager** icon, and select **Create Virtual Device**.

docs/src/install/android-windows.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,18 @@ To prepare to run your `Crossbow` app on an Android device, you need an Android
4848

4949
## Set up the Android emulator
5050

51-
To prepare to run and test your Crossbow app on the Android emulator, follow these steps:
51+
To prepare to run and test your Crossbow app on the Android emulator, follow these steps if you want to install it from the console:
52+
53+
```sh
54+
# Run following command to install System Image for Android SDK 30
55+
crossbundle install sdk-manager --install "system-images;android-30;google_apis;x86_64"
56+
# Run this command to create a new emulator
57+
avdmanager create avd -n Phone -k "system-images;android-30;google_apis;x86_64"
58+
# And finally run this command to start the emulator
59+
emulator -avd=Phone
60+
```
61+
62+
If you want to install it from the GUI, follow these instructions:
5263

5364
1. Enable [`VM acceleration`](https://developer.android.com/studio/run/emulator-acceleration) on your machine.
5465
2. Launch **Android Studio**, click the **AVD Manager** icon, and select **Create Virtual Device**.

docs/src/introduction.md

+6
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ A lot of functionality was inspired by [Godot](https://github.com/godotengine/go
2020
* **Simple**: Easy to start but flexible for strong devs.
2121
* **Capable**: It's possible to build plain **.apk/.aab** or **.app/.ipa**; or with help of *Gradle/XCode*.
2222
* **Rust**: Don't leave your *Rust* code - **everything** can be configured from `Cargo.toml`.
23+
24+
## Next steps
25+
26+
As the next steps we recommend you to install and setup `crossbundle` to be able to build, test, and run your project!
27+
28+
See [Getting Started](install/README.md) for more information.

examples/bevy-2d/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "bevy-2d"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
authors = ["DodoRare Team <support@dodorare.com>"]
55
edition = "2021"
66

77
[dependencies]
8-
crossbow = { version = "0.1.6", path = "../../" }
8+
crossbow = { version = "0.1.7", path = "../../" }
99
log = "0.4"
1010
anyhow = "1.0"
1111
bevy = { version = "0.7.0", features = ["mp3"] }

examples/bevy-3d/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "bevy-3d"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
authors = ["DodoRare Team <support@dodorare.com>"]
55
edition = "2021"
66

77
[dependencies]
8-
crossbow = { version = "0.1.6", path = "../../" }
8+
crossbow = { version = "0.1.7", path = "../../" }
99
log = "0.4"
1010
anyhow = "1.0"
1111
bevy = "0.7.0"

examples/bevy-explorer/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy-explorer"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
authors = ["DodoRare Team <support@dodorare.com>"]
55
edition = "2021"
66

examples/macroquad-3d/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "macroquad-3d"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
authors = ["DodoRare Team <support@dodorare.com>"]
55
edition = "2021"
66

77
[dependencies]
8-
crossbow = { version = "0.1.6", path = "../../" }
8+
crossbow = { version = "0.1.7", path = "../../" }
99
log = "0.4"
1010
anyhow = "1.0"
1111
macroquad = "0.3.7"

0 commit comments

Comments
 (0)