diff --git a/.github/workflows/android_test.sh b/.github/workflows/android_test.sh index 400caf0..880e682 100755 --- a/.github/workflows/android_test.sh +++ b/.github/workflows/android_test.sh @@ -16,7 +16,7 @@ else adb shell am start -a android.intent.action.MAIN -n "rust.example.hello_world/android.app.NativeActivity" fi -sleep 30s +sleep 30 adb logcat *:E hello_world:V -d | tee ~/logcat.log diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f9207b8..93f2040 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,14 +18,6 @@ jobs: - { name: "cargo-apk", target: "x86_64-unknown-linux-gnu" } steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: ${{ matrix.crate.target }} - override: true - name: Publish ${{ matrix.crate.name }} - uses: actions-rs/cargo@v1 continue-on-error: true - with: - command: publish - args: --manifest-path ${{ matrix.crate.name }}/Cargo.toml --target ${{ matrix.crate.target }} --token ${{ secrets.cratesio_token }} + run: cargo publish --manifest-path ${{ matrix.crate.name }}/Cargo.toml --target ${{ matrix.crate.target }} --token ${{ secrets.cratesio_token }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9320fa3..a0ec6fc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -6,97 +6,80 @@ jobs: formatting: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - name: Format - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - uses: actions/checkout@v2 + - name: Format + run: cargo fmt --all -- --check clippy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - target: aarch64-linux-android - - name: Clippy - uses: actions-rs/cargo@v1 - with: - command: clippy + - uses: actions/checkout@v2 + - name: Install aarch64-linux-android Rust target + run: rustup target add aarch64-linux-android + - name: Clippy # Use one of our supported targets to lint all crates including # the target-specific `ndk` in one go. # This assumes our host-tools (cargo-apk and dependencies) # also compile cleanly under this target. - args: --all --all-targets --all-features --target aarch64-linux-android -- -Dwarnings + run: cargo clippy --all --all-targets --all-features --target aarch64-linux-android -- -Dwarnings check_msrv: - name: Check MSRV (1.60.0) + name: Check MSRV (1.64.0) runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - uses: dtolnay/rust-toolchain@1.60.0 + - uses: dtolnay/rust-toolchain@1.64.0 with: target: aarch64-linux-android - - uses: actions-rs/cargo@v1 - with: - command: check - # See comment above about using one of our supported targets. - args: --workspace --all-targets --all-features --target aarch64-linux-android + - name: Check + # See comment above about using one of our supported targets. + run: cargo check --workspace --all-targets --all-features --target aarch64-linux-android build: strategy: fail-fast: false matrix: - os: [ubuntu-latest] - rust-channel: ['stable', 'nightly'] + os: [ubuntu-latest] + rust-channel: ["stable", "nightly"] rust-target: - - 'armv7-linux-androideabi' - - 'aarch64-linux-android' - - 'i686-linux-android' - - 'x86_64-linux-android' + - "armv7-linux-androideabi" + - "aarch64-linux-android" + - "i686-linux-android" + - "x86_64-linux-android" include: - os: windows-latest - rust-channel: 'stable' - rust-target: 'aarch64-linux-android' + rust-channel: "stable" + rust-target: "aarch64-linux-android" - os: windows-latest - rust-channel: 'stable' - rust-target: 'x86_64-linux-android' + rust-channel: "stable" + rust-target: "x86_64-linux-android" runs-on: ${{ matrix.os }} name: Build apk steps: - - uses: actions/checkout@v2 - - - name: Installing Rust ${{ matrix.rust-channel }} w/ ${{ matrix.rust-target }} - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust-channel }} - target: ${{ matrix.rust-target }} - override: true - - - name: Install cargo-apk - run: - cargo install --path cargo-apk - - - name: Cargo apk build for target ${{ matrix.rust-target }} - run: cargo apk build -p examples --target ${{ matrix.rust-target }} --examples - - - uses: actions/upload-artifact@v2 - # Only need this for CI, unless users are interested in downloading - # a ready-made app that does nothing but printing "hello world". - if: ${{ matrix.rust-target == 'x86_64-linux-android' }} - name: Upload hello_world apk - with: - name: hello_world_${{ matrix.os }}_${{ matrix.rust-target }} - path: ./target/debug/apk/examples/hello_world.apk + - uses: actions/checkout@v2 + + - name: Installing Rust ${{ matrix.rust-channel }} w/ ${{ matrix.rust-target }} + run: | + rustup toolchain install ${{ matrix.rust-channel }} + rustup default ${{ matrix.rust-channel }} + rustup target add ${{ matrix.rust-target }} + + - name: Install cargo-apk + run: cargo install --path cargo-apk + + - name: Cargo apk build for target ${{ matrix.rust-target }} + run: cargo apk build -p examples --target ${{ matrix.rust-target }} --examples + + - uses: actions/upload-artifact@v2 + # Only need this for CI, unless users are interested in downloading + # a ready-made app that does nothing but printing "hello world". + if: ${{ matrix.rust-target == 'x86_64-linux-android' }} + name: Upload hello_world apk + with: + name: hello_world_${{ matrix.os }}_${{ matrix.rust-target }} + path: ./target/debug/apk/examples/hello_world.apk android_emulator: name: hello_world example on emulator @@ -114,112 +97,107 @@ jobs: profile: Nexus 6 steps: - - name: Checkout - uses: actions/checkout@v2 - - - uses: actions/download-artifact@v2 - name: Download hello_world APK - if: ${{ matrix.source_os != 'local' }} - id: download - with: - name: hello_world_${{ matrix.source_os }}_x86_64-linux-android - - - name: Install `cargo-apk` and add `x86_64-linux-android` target - if: ${{ matrix.source_os == 'local' }} - run: | - cargo install --path cargo-apk - rustup target add x86_64-linux-android - - - name: AVD cache - uses: actions/cache@v2 - id: avd-cache - with: - path: | - ~/.android/avd/* - ~/.android/adb* - # Bump the trailing number when making changes to the emulator setup below - key: avd-${{ env.api-level }}-1 - - - name: create AVD and generate snapshot for caching - if: steps.avd-cache.outputs.cache-hit != 'true' - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ env.api-level }} - arch: ${{ env.arch }} - target: ${{ env.target }} - profile: ${{ env.profile }} - emulator-options: ${{ env.emulator-options }} - disable-animations: true - force-avd-creation: false - script: echo "Generated AVD snapshot for caching." - - - name: Start hello_world example - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ env.api-level }} - arch: ${{ env.arch }} - target: ${{ env.target }} - profile: ${{ env.profile }} - emulator-options: -no-snapshot-save ${{ env.emulator-options }} - disable-animations: true - force-avd-creation: false - script: ./.github/workflows/android_test.sh "${{ steps.download.outputs.download-path }}" - - - name: Upload emulator logs - uses: actions/upload-artifact@v2 - if: ${{ always() }} - with: - name: log - path: ~/logcat.log + - name: Checkout + uses: actions/checkout@v2 + + - uses: actions/download-artifact@v2 + name: Download hello_world APK + if: ${{ matrix.source_os != 'local' }} + id: download + with: + name: hello_world_${{ matrix.source_os }}_x86_64-linux-android + + - name: Install `cargo-apk` and add `x86_64-linux-android` target + if: ${{ matrix.source_os == 'local' }} + run: | + cargo install --path cargo-apk + rustup target add x86_64-linux-android + + - name: AVD cache + uses: actions/cache@v2 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + # Bump the trailing number when making changes to the emulator setup below + key: avd-${{ env.api-level }}-1 + + - name: create AVD and generate snapshot for caching + if: steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ env.api-level }} + arch: ${{ env.arch }} + target: ${{ env.target }} + profile: ${{ env.profile }} + emulator-options: ${{ env.emulator-options }} + disable-animations: true + force-avd-creation: false + script: echo "Generated AVD snapshot for caching." + + - name: Start hello_world example + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ env.api-level }} + arch: ${{ env.arch }} + target: ${{ env.target }} + profile: ${{ env.profile }} + emulator-options: -no-snapshot-save ${{ env.emulator-options }} + disable-animations: true + force-avd-creation: false + script: ./.github/workflows/android_test.sh "${{ steps.download.outputs.download-path }}" + + - name: Upload emulator logs + uses: actions/upload-artifact@v2 + if: ${{ always() }} + with: + name: log + path: ~/logcat.log build-host: strategy: fail-fast: false matrix: - os: [ubuntu-latest] - rust-channel: ['stable', 'nightly'] + os: [ubuntu-latest] + rust-channel: ["stable", "nightly"] runs-on: ${{ matrix.os }} name: Host-side tests steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Installing Rust ${{ matrix.rust-channel }} - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust-channel }} - override: true + - name: Installing Rust ${{ matrix.rust-channel }} + run: | + rustup toolchain install ${{ matrix.rust-channel }} + rustup default ${{ matrix.rust-channel }} - - name: Test ndk-build - run: - cargo test -p ndk-build --all-features + - name: Test ndk-build + run: cargo test -p ndk-build --all-features - - name: Test cargo-apk - run: - cargo test -p cargo-apk --all-features + - name: Test cargo-apk + run: cargo test -p cargo-apk --all-features docs: strategy: fail-fast: false matrix: - os: [ubuntu-latest] - rust-channel: ['stable', 'nightly'] + os: [ubuntu-latest] + rust-channel: ["stable", "nightly"] runs-on: ${{ matrix.os }} name: Build-test docs steps: - - uses: actions/checkout@v2 - - - name: Installing Rust ${{ matrix.rust-channel }} - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust-channel }} - override: true - - - name: Document all crates - env: - RUSTDOCFLAGS: -Dwarnings - run: - cargo doc --all --all-features + - uses: actions/checkout@v2 + + - name: Installing Rust ${{ matrix.rust-channel }} + run: | + rustup toolchain install ${{ matrix.rust-channel }} + rustup default ${{ matrix.rust-channel }} + + - name: Document all crates + env: + RUSTDOCFLAGS: -Dwarnings + run: cargo doc --all --all-features diff --git a/cargo-apk/Cargo.toml b/cargo-apk/Cargo.toml index 12545b9..aac0847 100644 --- a/cargo-apk/Cargo.toml +++ b/cargo-apk/Cargo.toml @@ -9,7 +9,7 @@ keywords = ["android", "ndk", "apk"] documentation = "https://docs.rs/cargo-apk" homepage = "https://github.com/rust-mobile/cargo-apk" repository = "https://github.com/rust-mobile/cargo-apk" -rust-version = "1.60" +rust-version = "1.64" [dependencies] anyhow = "1.0.57" diff --git a/cargo-apk/src/apk.rs b/cargo-apk/src/apk.rs index a807135..f2549c4 100644 --- a/cargo-apk/src/apk.rs +++ b/cargo-apk/src/apk.rs @@ -333,7 +333,7 @@ impl<'a> ApkBuilder<'a> { let target_dir = self.build_dir.join(artifact); self.ndk.ndk_gdb( - &target_dir, + target_dir, "android.app.NativeActivity", self.device_serial.as_deref(), )?; diff --git a/ndk-build/CHANGELOG.md b/ndk-build/CHANGELOG.md index 9d1dd68..ade84da 100644 --- a/ndk-build/CHANGELOG.md +++ b/ndk-build/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased -- Add `android:extractNativeLibs`, `android:usesCleartextTraffic`, attributes to the manifest's `Application` element, and `android:alwaysRetainTaskState` to the `Activity` element. ([#15](https://github.com/rust-mobile/cargo-apk/pull/15)) +- Add `android:extractNativeLibs`, `android:usesCleartextTraffic` attributes to the manifest's `Application` element, and `android:alwaysRetainTaskState` to the `Activity` element. ([#15](https://github.com/rust-mobile/cargo-apk/pull/15)) +- Enable building from `android` host ([#29](https://github.com/rust-mobile/cargo-apk/pull/29)) # 0.9.0 (2022-11-23) diff --git a/ndk-build/src/ndk.rs b/ndk-build/src/ndk.rs index 962ce93..744dac3 100644 --- a/ndk-build/src/ndk.rs +++ b/ndk-build/src/ndk.rs @@ -239,12 +239,16 @@ impl Ndk { "darwin" } else if host_contains("windows") { "windows" + } else if host_contains("android") { + "android" } else if cfg!(target_os = "linux") { "linux" } else if cfg!(target_os = "macos") { "darwin" } else if cfg!(target_os = "windows") { "windows" + } else if cfg!(target_os = "android") { + "android" } else { return match host_os { Some(host_os) => Err(NdkError::UnsupportedHost(host_os)),