Skip to content

Commit c2d6b30

Browse files
authored
Fixing android compatibility (#104)
Fixes #105 — GenerateApi.generate() crashes on Android with PatternSyntaxException due to unescaped } in replaceAll regex pattern. Changes Fix Android regex crash: Replace replaceAll() (regex) with replace() (literal) in GenerateApi.java:74 Add Android CI: Run unit tests on real Android runtime via Gradle Managed Devices (ATD API 30) to catch ICU regex incompatibilities Add unit tests: New unit tests for GenerateApi, RecognizeApi, and ScanApi with JaCoCo coverage enforcement JDK matrix: CI now tests on both JDK 11 and JDK 21 Consolidate workflows: Merged Android test job into ci.yml with needs: test so it only runs after Maven tests pass Caching: Added gradle/actions/setup-gradle@v4 and AVD cache for faster Android CI runs Android test setup The android-test/ module reuses existing unit tests from src/test/java/api/ via Gradle sourceSets, running them as instrumented tests on a Pixel 2 API 30 ATD emulator managed by Gradle.
1 parent f7843ac commit c2d6b30

25 files changed

Lines changed: 1396 additions & 61 deletions

File tree

.github/workflows/check-badges.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ name: Check badges in README.md
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88

99
jobs:
1010
build-and-test:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v4
1515

16-
- name: Check badges in README.md
17-
run: ./scripts/check-badges.bash "README.md"
16+
- name: Check badges in README.md
17+
run: ./scripts/check-badges.bash "README.md"

.github/workflows/check-style.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ name: Java check style
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88

99
jobs:
1010
lint:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v4
15-
- uses: actions/setup-java@v3
16-
with:
17-
distribution: 'corretto'
18-
java-version: 11
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-java@v3
16+
with:
17+
distribution: "corretto"
18+
java-version: 11
1919

20-
- name: Lint with CheckStyle
21-
run: ./scripts/checkstyle.bash
20+
- name: Lint with CheckStyle
21+
run: ./scripts/checkstyle.bash

.github/workflows/ci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Java CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: test with Java version ${{ matrix.java-version }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
java-version: [11, 21]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Set up JDK ${{ matrix.java-version }}
20+
uses: actions/setup-java@v4
21+
with:
22+
# Use same in Dockerfile
23+
distribution: "corretto"
24+
java-version: ${{ matrix.java-version }}
25+
cache: "maven"
26+
27+
- name: Maven Compile
28+
run: mvn compile
29+
30+
- name: Test with Maven
31+
env:
32+
TEST_CONFIGURATION_ACCESS_TOKEN: ${{ secrets.TEST_CONFIGURATION_ACCESS_TOKEN }}
33+
run: |
34+
chmod +x scripts/*
35+
make build
36+
make test
37+
38+
android-test:
39+
needs: test
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- uses: actions/checkout@v4
44+
45+
- uses: actions/setup-java@v4
46+
with:
47+
distribution: "temurin"
48+
java-version: 17
49+
50+
- name: Setup Gradle
51+
uses: gradle/actions/setup-gradle@v4
52+
53+
- name: Build Java library JAR
54+
run: mvn package -Dmaven.test.skip=true
55+
56+
- name: Accept Android SDK Licenses
57+
run: yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses
58+
59+
- name: Enable KVM
60+
run: |
61+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
62+
sudo udevadm control --reload-rules
63+
sudo udevadm trigger --name-match=kvm
64+
65+
- name: Cache AVD
66+
uses: actions/cache@v4
67+
with:
68+
path: |
69+
~/.android/avd/*
70+
~/.android/adb*
71+
key: avd-pixel2-api30-atd
72+
73+
- name: Run Android Tests
74+
working-directory: android-test
75+
run: >
76+
./gradlew pixel2api30DebugAndroidTest
77+
-Pandroid.testoptions.manageddevices.emulator.gpu=swiftshader_indirect

.github/workflows/maven.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
build
1111
aspose-barcode-cloud.iml
1212
!tools/*
13+
!**/gradle-wrapper.jar
1314
.idea
15+
.gradle
16+
local.properties
1417

1518
**/configuration*.json
1619
snippets_test/

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ build:
2424
.PHONY: test
2525
test:
2626
mvn test
27+
mvn dependency:copy-dependencies -DoutputDirectory=target/lib/
2728
./scripts/run_snippets.sh
2829

2930
.PHONY: display-updates

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Aspose.BarCode Cloud SDK for Java
22

33
[![License](https://img.shields.io/github/license/aspose-barcode-cloud/aspose-barcode-cloud-java)](LICENSE)
4-
[![Java CI with Maven](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-java/actions/workflows/maven.yml/badge.svg?branch=main)](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-java/actions/workflows/maven.yml)
4+
[![Java CI with Maven](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-java/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-java/actions/workflows/ci.yml)
55
[![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Freleases.aspose.cloud%2Fjava%2Frepo%2Fcom%2Faspose%2Faspose-barcode-cloud%2Fmaven-metadata.xml)](https://releases.aspose.cloud/java/repo/com/aspose/aspose-barcode-cloud/)
66

77
- API version: 4.0

android-test/build.gradle

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
plugins {
2+
id 'com.android.library' version '9.1.0'
3+
}
4+
5+
android {
6+
namespace 'com.aspose.barcode.cloud.androidtest'
7+
compileSdk 35
8+
9+
defaultConfig {
10+
minSdk 23
11+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12+
}
13+
14+
compileOptions {
15+
sourceCompatibility JavaVersion.VERSION_1_8
16+
targetCompatibility JavaVersion.VERSION_1_8
17+
}
18+
19+
sourceSets {
20+
androidTest {
21+
java {
22+
srcDirs = ['../src/test/java']
23+
exclude 'com/aspose/barcode/cloud/test/**'
24+
exclude 'com/aspose/barcode/cloud/examples/**'
25+
}
26+
}
27+
}
28+
29+
testOptions {
30+
managedDevices {
31+
localDevices {
32+
pixel2api30 {
33+
device = "Pixel 2"
34+
apiLevel = 30
35+
systemImageSource = "aosp-atd"
36+
}
37+
}
38+
}
39+
}
40+
}
41+
42+
dependencies {
43+
implementation fileTree(
44+
dir: '../target',
45+
include: ['aspose-barcode-cloud-*.jar'],
46+
exclude: [
47+
'aspose-barcode-cloud-*-sources.jar',
48+
'aspose-barcode-cloud-*-javadoc.jar'
49+
]
50+
)
51+
implementation 'com.google.code.gson:gson:2.13.2'
52+
implementation 'io.gsonfire:gson-fire:1.9.0'
53+
implementation 'com.squareup.okhttp3:okhttp:5.3.2'
54+
implementation 'io.swagger:swagger-annotations:1.6.16'
55+
androidTestImplementation 'junit:junit:4.13.2'
56+
androidTestImplementation 'androidx.test:runner:1.5.2'
57+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
58+
}
57.8 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Fri Jan 27 19:13:42 YEKT 2023
2+
distributionBase=GRADLE_USER_HOME
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
4+
distributionPath=wrapper/dists
5+
zipStorePath=wrapper/dists
6+
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)