Skip to content

Commit

Permalink
Update Docker image and add CI test of it (#124)
Browse files Browse the repository at this point in the history
* Update dockerfile

* Alter dockerfile

* Remove TTY and alter install command emulator doc

* Fix android sdk resolution issues

* Bump versions
  • Loading branch information
enfipy authored Jul 28, 2022
1 parent d5d7c07 commit cb58e24
Show file tree
Hide file tree
Showing 25 changed files with 128 additions and 91 deletions.
22 changes: 5 additions & 17 deletions .github/docker/crossbundle.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
FROM eclipse-temurin:11.0.13_8-jdk
FROM androidsdk/android-30
LABEL org.opencontainers.image.source https://github.com/dodorare/crossbow

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

# Install Android SDK
ENV ANDROID_SDK_ROOT=/opt/android-sdk-linux
RUN mkdir -p ${ANDROID_SDK_ROOT}/cmdline-tools \
&& cd ${ANDROID_SDK_ROOT}/cmdline-tools \
&& wget -q https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip \
&& unzip -q commandlinetools-linux-8512546_latest.zip \
&& rm commandlinetools-linux-8512546_latest.zip \
&& mv cmdline-tools/ latest/ \
&& chown -R root:root /opt
# Install Android NDK
RUN ulimit -c unlimited
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "platform-tools"
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "platforms;android-30"
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "build-tools;31.0.0"
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "ndk;23.1.7779620"
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --update
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/sdkmanager "ndk;23.1.7779620"
RUN yes | ${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/sdkmanager --update
ENV ANDROID_NDK_ROOT=${ANDROID_SDK_ROOT}/ndk/23.1.7779620

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

RUN wget https://services.gradle.org/distributions/gradle-7.4-all.zip \
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ jobs:
cd ~/example/
crossbundle build android --apk --release --quad
build-example-in-docker:
name: Build Crossbundle Example from Docker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Build Crossbundle image
run: docker build -t tmp -f .github/docker/crossbundle.Dockerfile .
- name: Build Crossbundle Example
run: |
docker run --rm -v "$(pwd)/:/src" -w /src/examples/macroquad-permissions tmp build android --quad --release
clean:
name: Check code format
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crossbow"
version = "0.1.6"
version = "0.1.7"
edition = "2021"
authors = ["DodoRare Team <[email protected]>"]
description = "Cross-Platform Rust Toolkit for Games 🏹"
Expand All @@ -16,11 +16,11 @@ displaydoc = "0.2"
anyhow = "1.0"

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

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

[patch.crates-io]
winit = { git = "https://github.com/rust-windowing/winit", rev = "f93f2c158bf527ed56ab2b6f5272214f0c1d9f7d" }
Expand Down
4 changes: 2 additions & 2 deletions crossbundle/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crossbundle"
version = "0.1.6"
version = "0.1.7"
edition = "2021"
authors = ["DodoRare Team <[email protected]>"]
description = "Build and publish apps for Android/iOS"
Expand All @@ -18,7 +18,7 @@ name = "crossbundle"
path = "src/main.rs"

[dependencies]
crossbundle-tools = { path = "../tools", version = "0.1.6" }
crossbundle-tools = { path = "../tools", version = "0.1.7" }
android-tools = "0.2.9"
clap = { version = "3.2.8", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
Expand Down
14 changes: 7 additions & 7 deletions crossbundle/cli/src/commands/build/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use crate::types::MIN_SDK_VERSION;

use super::{BuildContext, SharedBuildCommand};
use android_manifest::AndroidManifest;
use android_tools::{
java_tools::{JarSigner, Key},
sdk_install_path,
};
use android_tools::java_tools::{JarSigner, Key};
use clap::Parser;
use crossbundle_tools::{
commands::android::{self, rust_compile},
Expand Down Expand Up @@ -77,6 +74,7 @@ impl AndroidBuildCommand {
context: &BuildContext,
export_path: &Option<PathBuf>,
) -> crate::error::Result<(AndroidManifest, AndroidSdk, PathBuf)> {
let sdk = AndroidSdk::from_env()?;
let profile = self.shared.profile();
let example = self.shared.example.as_ref();
let (_, target_dir, package_name) = Self::needed_project_dirs(example, context)?;
Expand All @@ -89,9 +87,12 @@ impl AndroidBuildCommand {
target_dir.join("android").join(&package_name)
};

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

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

// Get AndroidManifest.xml from file or generate from Cargo.toml
let (sdk, _, _) = Self::android_toolchain(context)?;
let (android_manifest, _manifest_path) = Self::android_manifest(
config,
context,
Expand Down
5 changes: 3 additions & 2 deletions crossbundle/cli/src/commands/install/command_line_tools.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::*;
use android_tools::sdk_install_path;
use clap::Parser;
use crossbundle_tools::{
commands::android::{self, remove},
tools::AndroidSdk,
utils::Config,
};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -38,7 +38,8 @@ impl CommandLineToolsInstallCommand {
)?;
self.download_and_save_file(command_line_tools_download_url, &file_path)?;

let sdk_path = sdk_install_path()?;
let sdk = AndroidSdk::from_env()?;
let sdk_path = sdk.sdk_path();

if let Some(path) = &self.install_path {
config.status_message(
Expand Down
21 changes: 11 additions & 10 deletions crossbundle/cli/src/commands/install/sdkmanager.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::Path;

use android_tools::sdk_install_path;
use clap::Parser;
use crossbundle_tools::{error::CommandExt, utils::Config, EXECUTABLE_SUFFIX_BAT};
use crossbundle_tools::{
error::CommandExt, tools::AndroidSdk, utils::Config, EXECUTABLE_SUFFIX_BAT,
};
use std::path::Path;

#[derive(Parser, Clone, Debug, Default)]
pub struct SdkManagerInstallCommand {
Expand Down Expand Up @@ -157,23 +157,24 @@ impl SdkManagerInstallCommand {

/// Run sdkmanager command with specified flags and options
pub fn run(&self, _config: &Config) -> crate::error::Result<()> {
let sdk_root = sdk_install_path()?;
// Android studio install cmdline tools into SDK_ROOT/cmdline-tools/<version>/bin.
let sdk = AndroidSdk::from_env()?;
let sdk_path = sdk.sdk_path();
// Android Studio installs cmdline-tools into $ANDROID_SDK_ROOT/cmdline-tools/<version>/bin.
// Crossbundle install command ignores <version> directory so we need convert cmd-line-tools path to Option<T> to avoid confusion
let cmdline_tools_path = std::path::PathBuf::from(&sdk_root)
let cmdline_tools_path = std::path::PathBuf::from(&sdk_path)
.join("cmdline-tools")
.join("latest")
.join("bin");
if cmdline_tools_path.exists() {
let sdkmanager_path =
cmdline_tools_path.join(format!("sdkmanager{}", EXECUTABLE_SUFFIX_BAT));
self.sdkmanager_command(&sdkmanager_path, Path::new(&sdk_root))?;
self.sdkmanager_command(&sdkmanager_path, Path::new(&sdk_path))?;
} else {
let sdkmanager_path = std::path::PathBuf::from(&sdk_root)
let sdkmanager_path = std::path::PathBuf::from(&sdk_path)
.join("cmdline-tools")
.join("bin")
.join(format!("sdkmanager{}", EXECUTABLE_SUFFIX_BAT));
self.sdkmanager_command(&sdkmanager_path, Path::new(&sdk_root))?;
self.sdkmanager_command(&sdkmanager_path, Path::new(&sdk_path))?;
};
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crossbundle/tools/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crossbundle-tools"
version = "0.1.6"
version = "0.1.7"
edition = "2021"
authors = ["DodoRare Team <[email protected]>"]
description = "Build and publish apps for Android/iOS"
Expand Down
36 changes: 18 additions & 18 deletions crossbundle/tools/src/tools/android_ndk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,29 @@ impl AndroidNdk {
.or_else(|| std::env::var("ANDROID_NDK_HOME").ok())
.or_else(|| std::env::var("NDK_HOME").ok());
// Default ndk installation path
if ndk_path.is_none()
if let Some(ndk_path) = ndk_path {
PathBuf::from(ndk_path)
} else if ndk_path.is_none()
&& sdk_path.is_some()
&& sdk_path.as_ref().unwrap().join("ndk-bundle").exists()
{
sdk_path.unwrap().join("ndk-bundle")
} else if let Some(ndk_path) = ndk_path {
PathBuf::from(ndk_path)
} else {
PathBuf::from(ndk_install_path()?)
let ndk_path = if let Some(sdk_path) = sdk_path {
sdk_path.to_owned()
} else {
android_tools::sdk_install_path()?
}
.join("ndk");
let ndk_ver = std::fs::read_dir(&ndk_path)
.map_err(|_| Error::PathNotFound(ndk_path.clone()))?
.filter_map(|path| path.ok())
.filter(|path| path.path().is_dir())
.filter_map(|path| path.file_name().into_string().ok())
.filter(|name| name.chars().next().unwrap().is_ascii_digit())
.max()
.ok_or(AndroidError::AndroidNdkNotFound)?;
ndk_path.join(ndk_ver)
}
};
let build_tag = std::fs::read_to_string(ndk_path.join("source.properties"))
Expand Down Expand Up @@ -322,17 +336,3 @@ impl AndroidNdk {
Ok(version_specific_libraries_path)
}
}

pub fn ndk_install_path() -> crate::error::Result<String> {
let ndk_path = android_tools::sdk_install_path()?.join("ndk");
let ndk_ver = std::fs::read_dir(&ndk_path)
.map_err(|_| Error::PathNotFound(ndk_path.clone()))?
.filter_map(|path| path.ok())
.filter(|path| path.path().is_dir())
.filter_map(|path| path.file_name().into_string().ok())
.filter(|name| name.chars().next().unwrap().is_ascii_digit())
.max()
.ok_or(AndroidError::AndroidNdkNotFound)?;
let ndk_install_path = ndk_path.join(ndk_ver).to_str().unwrap().to_string();
Ok(ndk_install_path)
}
13 changes: 5 additions & 8 deletions crossbundle/tools/src/tools/android_sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ impl AndroidSdk {
.ok()
.or_else(|| std::env::var("ANDROID_SDK_PATH").ok())
.or_else(|| std::env::var("ANDROID_HOME").ok());
PathBuf::from(
sdk_path.unwrap_or(
android_tools::sdk_install_path()?
.to_str()
.unwrap()
.to_string(),
),
)
if let Some(sdk_path) = sdk_path {
PathBuf::from(sdk_path)
} else {
android_tools::sdk_install_path()?
}
};
let build_deps_path = sdk_path.join("build-tools");
let build_deps_version = std::fs::read_dir(&build_deps_path)
Expand Down
13 changes: 12 additions & 1 deletion docs/src/install/android-linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ To prepare to run your `Crossbow` app on an Android device, you need an Android

## Set up the Android emulator

To prepare to run and test your Flutter app on the Android emulator, follow these steps:
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:

```sh
# Run following command to install System Image for Android SDK 30
crossbundle install sdk-manager --install "system-images;android-30;google_apis;x86_64"
# Run this command to create a new emulator
avdmanager create avd -n Phone -k "system-images;android-30;google_apis;x86_64"
# And finally run this command to start the emulator
emulator -avd=Phone
```

If you want to install it from the GUI, follow these instructions:

1. Enable [`VM acceleration`](https://developer.android.com/studio/run/emulator-acceleration) on your machine.
2. Launch **Android Studio**, click the **AVD Manager** icon, and select **Create Virtual Device**.
Expand Down
13 changes: 12 additions & 1 deletion docs/src/install/android-macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ To prepare to run your `crossbow` app on an Android device, you need an Android

## Set up the Android emulator

To prepare to run and test your Crossbow app on the Android emulator, follow these steps:
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:

```sh
# Run following command to install System Image for Android SDK 30
crossbundle install sdk-manager --install "system-images;android-30;google_apis;x86_64"
# Run this command to create a new emulator
avdmanager create avd -n Phone -k "system-images;android-30;google_apis;x86_64"
# And finally run this command to start the emulator
emulator -avd=Phone
```

If you want to install it from the GUI, follow these instructions:

1. Enable [`VM acceleration`](https://developer.android.com/studio/run/emulator-acceleration) on your machine.
2. Launch **Android Studio**, click the **AVD Manager** icon, and select **Create Virtual Device**.
Expand Down
13 changes: 12 additions & 1 deletion docs/src/install/android-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,18 @@ To prepare to run your `Crossbow` app on an Android device, you need an Android

## Set up the Android emulator

To prepare to run and test your Crossbow app on the Android emulator, follow these steps:
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:

```sh
# Run following command to install System Image for Android SDK 30
crossbundle install sdk-manager --install "system-images;android-30;google_apis;x86_64"
# Run this command to create a new emulator
avdmanager create avd -n Phone -k "system-images;android-30;google_apis;x86_64"
# And finally run this command to start the emulator
emulator -avd=Phone
```

If you want to install it from the GUI, follow these instructions:

1. Enable [`VM acceleration`](https://developer.android.com/studio/run/emulator-acceleration) on your machine.
2. Launch **Android Studio**, click the **AVD Manager** icon, and select **Create Virtual Device**.
Expand Down
6 changes: 6 additions & 0 deletions docs/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ A lot of functionality was inspired by [Godot](https://github.com/godotengine/go
* **Simple**: Easy to start but flexible for strong devs.
* **Capable**: It's possible to build plain **.apk/.aab** or **.app/.ipa**; or with help of *Gradle/XCode*.
* **Rust**: Don't leave your *Rust* code - **everything** can be configured from `Cargo.toml`.

## Next steps

As the next steps we recommend you to install and setup `crossbundle` to be able to build, test, and run your project!

See [Getting Started](install/README.md) for more information.
4 changes: 2 additions & 2 deletions examples/bevy-2d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "bevy-2d"
version = "0.1.6"
version = "0.1.7"
authors = ["DodoRare Team <[email protected]>"]
edition = "2021"

[dependencies]
crossbow = { version = "0.1.6", path = "../../" }
crossbow = { version = "0.1.7", path = "../../" }
log = "0.4"
anyhow = "1.0"
bevy = { version = "0.7.0", features = ["mp3"] }
Expand Down
4 changes: 2 additions & 2 deletions examples/bevy-3d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "bevy-3d"
version = "0.1.6"
version = "0.1.7"
authors = ["DodoRare Team <[email protected]>"]
edition = "2021"

[dependencies]
crossbow = { version = "0.1.6", path = "../../" }
crossbow = { version = "0.1.7", path = "../../" }
log = "0.4"
anyhow = "1.0"
bevy = "0.7.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy-explorer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy-explorer"
version = "0.1.6"
version = "0.1.7"
authors = ["DodoRare Team <[email protected]>"]
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions examples/macroquad-3d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "macroquad-3d"
version = "0.1.6"
version = "0.1.7"
authors = ["DodoRare Team <[email protected]>"]
edition = "2021"

[dependencies]
crossbow = { version = "0.1.6", path = "../../" }
crossbow = { version = "0.1.7", path = "../../" }
log = "0.4"
anyhow = "1.0"
macroquad = "0.3.7"
Expand Down
Loading

0 comments on commit cb58e24

Please sign in to comment.