Skip to content

Commit

Permalink
feat: compose sdk (#149)
Browse files Browse the repository at this point in the history
* feat(compose): add compose SDK

* feat(compose): add UI tests and move common plugins to gradle/shared/code-quality.gradle

* ci: do compilation test with compile-api=34

* ci: run test-minified after test-ui

* chore: move compose example activity to separate module and rename compose->compose-sdk

* chore: make sdk as transitive dependency for compose-sdk

* ci: migrate to arm64 emulator

* ci: switch to ubuntu-runner beause macos-latest arm64 broken

* ci: enable KVM group permissions for emulator run

* ci: parallel should be preinstalled on ubuntu runner

* ci: downgrade emulator api to 28 to check if it affect stability

* chore: move avd creation/run into separate action

* ci: use recent avd for benchmark tests

* chore: rename compose-app -> example-compose-app

* ci: upload bencmark logs on failure

* chore: replace DisposableEffect with Dialog+AndroidView

* chore: add loading indicator to example-compose-app

* test: bench on 28 emulator

* ci: move back to macos-13 for benchmarking job

* chore: move compose UI tests to test module

* fix: put back compose-sdk/src/test directory

* fix: compose tests for releaseAndroidTests variant

* ci: fix avd cache key to respect runner os

* chore: upgrade buildscript deps

* ci: fix deprecation warning for gradle/gradle-build-action

* chore: upload test/build for investigation

* fix: inferredKeepRules.pro lookup in test module

* chore: remove developers section from MavenPublication

* ci: uninstall com.hcaptcha.sdk.bench.test before benchTest
  • Loading branch information
CAMOBAP authored Jun 26, 2024
1 parent e161a2a commit 08b8399
Show file tree
Hide file tree
Showing 50 changed files with 1,067 additions and 294 deletions.
68 changes: 68 additions & 0 deletions .github/actions/android-emulator-run/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: android-emulator-run
description: Do run script after emulator boot (use cached AVD or create a new one)

inputs:
script:
description: Script to run after emulator booted
required: true
arch:
description: Emulator arch, supported values depends on runner
required: true
default: x86_64
target:
description: Emulator target. Supported `default` or `google_apis` values
required: true
default: default
profile:
description: Emulator profile
required: true
default: Nexus 6
api-level:
description: Emulator API level
required: true
default: '28'
boot-options:
description: Emulator boot options
required: true
default: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none

runs:
using: "composite"
steps:
- name: Cache AVD
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-api-${{ runner.os }}-${{ inputs.api-level }}-target-${{ inputs.target }}
- if: runner.os == 'Linux'
name: Enable KVM group perms
shell: bash
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: 'Create AVD'
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
arch: ${{ inputs.arch }}
target: ${{ inputs.target }}
profile: ${{ inputs.profile }}
api-level: ${{ inputs.api-level }}
emulator-options: ${{ inputs.boot-options }}
force-avd-creation: false
disable-animations: false
script: echo "Generated AVD snapshot for caching."
- uses: reactivecircus/android-emulator-runner@v2
with:
arch: ${{ inputs.arch }}
target: ${{ inputs.target }}
profile: ${{ inputs.profile }}
api-level: ${{ inputs.api-level }}
emulator-options: ${{ inputs.boot-options }}
force-avd-creation: false
disable-animations: true
script: ${{ inputs.script }}
160 changes: 38 additions & 122 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v3
- uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false
- name: 'Build'
Expand All @@ -41,7 +41,7 @@ jobs:

build-matrix:
name: 'Build (target:${{ matrix.target }} compile:${{ matrix.compile }} appcompat: ${{ matrix.appcompat }})'
needs: [ test ]
needs: test
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -50,16 +50,16 @@ jobs:
- compile: 34
target: 34
appcompat: 1.6.1
- compile: 33
- compile: 34
target: 33
appcompat: 1.5.1
- compile: 32
- compile: 34
target: 32
appcompat: 1.4.2
- compile: 32
- compile: 34
target: 30
appcompat: 1.3.1
- compile: 30
- compile: 34
target: 30
appcompat: 1.3.1
steps:
Expand All @@ -68,7 +68,7 @@ jobs:
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v3
- uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false
- run: |
Expand All @@ -78,55 +78,22 @@ jobs:
test-ui:
name: 'Test UI'
runs-on: macos-latest
needs: test
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
api-level: [29]
target: [default]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v3
- uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false
- name: 'Cache AVD'
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-api-${{ matrix.api-level }}-target-${{ matrix.target }}
- name: 'Create AVD'
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/[email protected]
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
disable-animations: false
arch: x86_64
profile: Nexus 6
script: echo "Generated AVD snapshot for caching."
- name: 'Tests'
uses: reactivecircus/[email protected]
- name: Run tests
uses: ./.github/actions/android-emulator-run
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
disable-animations: true
arch: x86_64
profile: Nexus 6
script: |
brew install parallel
parallel --retries 3 ::: "./gradlew test:connectedCheck"
script: "parallel --retries 3 ::: './gradlew test:connectedCheck'"
- if: failure()
uses: actions/upload-artifact@v4
with:
Expand All @@ -137,55 +104,22 @@ jobs:
test-minified:
name: 'Test UI Minified'
runs-on: macos-latest
needs: [ test-ui ]
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
api-level: [29]
target: [default]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v3
- uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false
- name: 'Cache AVD'
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-api-${{ matrix.api-level }}-target-${{ matrix.target }}
- name: 'Create AVD'
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/[email protected]
- name: Run tests
uses: ./.github/actions/android-emulator-run
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
disable-animations: false
arch: x86_64
profile: Nexus 6
script: echo "Generated AVD snapshot for caching."
- name: 'Tests'
uses: reactivecircus/[email protected]
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
disable-animations: true
arch: x86_64
profile: Nexus 6
script: |
brew install parallel
parallel --retries 3 ::: "./gradlew test:connectedCheck -P testingMinimizedBuild=true -P android.enableR8.fullMode=false"
script: "parallel --retries 3 ::: './gradlew test:connectedCheck -P testingMinimizedBuild=true -P android.enableR8.fullMode=false'"
- if: failure()
uses: actions/upload-artifact@v4
with:
Expand All @@ -196,52 +130,34 @@ jobs:
test-benchmark:
name: 'Test Benchmark'
runs-on: macos-latest
needs: test
# ubuntu-latest fails with JNI ERROR (app bug): weak global reference table overflow (max=51200)
# macos-latest i.e. macos-14 https://github.com/ReactiveCircus/android-emulator-runner/issues/324
runs-on: macos-13
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
api-level: [29]
target: [default]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v3
- uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false
- name: 'Cache AVD'
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-api-${{ matrix.api-level }}-target-${{ matrix.target }}
- name: 'Create AVD'
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/[email protected]
- name: Run tests
uses: ./.github/actions/android-emulator-run
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
disable-animations: false
arch: x86_64
profile: Nexus 6
script: echo "Generated AVD snapshot for caching."
- uses: reactivecircus/[email protected]
api-level: 29
script: |
adb uninstall com.hcaptcha.sdk.bench.test || true
./gradlew benchmark:connectedReleaseAndroidTest
- if: failure()
uses: actions/upload-artifact@v4
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
disable-animations: true
arch: x86_64
profile: Nexus 6
script: ./gradlew benchmark:connectedReleaseAndroidTest
name: androidTest-benchmark-results
path: |
benchmark/build/outputs/androidTest-results
benchmark/build/reports/androidTests
- name: Diff benchmark result
id: diff-benchmark
uses: ./.github/actions/android-benchmark-diff
Expand Down Expand Up @@ -284,7 +200,7 @@ jobs:
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v3
- uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false
- uses: actions/cache@v4
Expand All @@ -310,7 +226,7 @@ jobs:
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v3
- uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false
- name: 'Build'
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/sdk/gradle.properties
/.idea
.DS_Store
/build
build
/captures
.externalNativeBuild
.cxx
Expand Down
4 changes: 2 additions & 2 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ with:
```groovy
dependencies {
// ...
implementation "com.github.hCaptcha:hcaptcha-android-sdk:BRANCH_NAME-SNAPSHOT"
implementation "com.github.hCaptcha.hcaptcha-android-sdk:sdk:BRANCH_NAME-SNAPSHOT"
// or
implementation "com.github.hCaptcha:hcaptcha-android-sdk:pull/PR_NUMBER/head-SNAPSHOT"
implementation "com.github.hCaptcha.hcaptcha-android-sdk:sdk:pull/PR_NUMBER/head-SNAPSHOT"
}
```
1. Build `example-app` for `release` variant
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,28 @@ repositories {
}
// Add hCaptcha sdk dependency inside the app's build.gradle file
dependencies {
<b>implementation 'com.github.hcaptcha:hcaptcha-android-sdk:x.y.z'</b>
// For Android View
<b>implementation 'com.github.hCaptcha.hcaptcha-android-sdk:sdk:x.y.z'</b>
// For Jetpack Compose
<b>implementation 'com.github.hCaptcha.hcaptcha-android-sdk:compose-sdk:x.y.z'</b>
}
</pre>

*Note: replace `x.y.z` with one from [Release](https://github.com/hCaptcha/hcaptcha-android-sdk/releases) (e.g. `1.0.0`).*

### Legacy (versions < 5.0)

<pre>
// Register JitPack Repository inside the root build.gradle file
repositories {
<b>maven { url 'https://jitpack.io' }</b>
}
// Add hCaptcha sdk dependency inside the app's build.gradle file
dependencies {
<b>implementation 'com.github.hcaptcha:hcaptcha-android-sdk:x.y.z'</b>
}
</pre>

## Requirements

| Platform | Requirements |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public void onLoaded() {
latch.countDown();
}
},
new TestHCaptchaStateListener(),
webView
);
});
Expand Down
Loading

0 comments on commit 08b8399

Please sign in to comment.