Skip to content

Commit a0638d8

Browse files
Add android tests
1 parent d44f49e commit a0638d8

56 files changed

Lines changed: 1119 additions & 12 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-simulators.yaml

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ jobs:
88
name: Check for relevant changes
99
runs-on: ubuntu-latest
1010
outputs:
11-
should_run: ${{ steps.check.outputs.should_run }}
11+
react_native_simulator_should_run: ${{ steps.check.outputs.react_native_simulator_should_run }}
12+
capacitor_should_run: ${{ steps.check.outputs.capacitor_should_run }}
1213
steps:
1314
- uses: actions/checkout@v6
1415
with:
@@ -18,15 +19,21 @@ jobs:
1819
run: |
1920
git fetch origin ${{ github.base_ref }}
2021
if git diff --quiet origin/${{ github.base_ref }} -- packages/common packages/powersync-op-sqlite tools/powersynctests; then
21-
echo "should_run=false" >> $GITHUB_OUTPUT
22+
echo "react_native_simulator_should_run=false" >> $GITHUB_OUTPUT
2223
else
23-
echo "should_run=true" >> $GITHUB_OUTPUT
24+
echo "react_native_simulator_should_run=true" >> $GITHUB_OUTPUT
25+
fi
26+
27+
if git diff --quiet origin/${{ github.base_ref }} -- packages/capacitor pnpm-lock.yaml .github/workflows/test-simulators.yaml; then
28+
echo "capacitor_should_run=false" >> $GITHUB_OUTPUT
29+
else
30+
echo "capacitor_should_run=true" >> $GITHUB_OUTPUT
2431
fi
2532
2633
test-android:
2734
name: Test Android
2835
needs: check-changes
29-
if: ${{ needs.check-changes.outputs.should_run == 'true' }}
36+
if: ${{ needs.check-changes.outputs.react_native_simulator_should_run == 'true' }}
3037
runs-on: ubuntu-xl
3138
timeout-minutes: 30
3239
env:
@@ -112,12 +119,101 @@ jobs:
112119
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
113120
disable-animations: true
114121

122+
test-capacitor-android:
123+
name: Test Capacitor Android
124+
needs: check-changes
125+
if: ${{ needs.check-changes.outputs.capacitor_should_run == 'true' }}
126+
runs-on: ubuntu-xl
127+
timeout-minutes: 30
128+
env:
129+
AVD_NAME: capacitor-avd-x86_64-31
130+
TEST_PLATFORM: android
131+
TEST_TARGET: emulator-5554
132+
TEST_SERVER_HOST: 10.0.2.2
133+
steps:
134+
- uses: actions/checkout@v6
135+
with:
136+
persist-credentials: false
137+
138+
- name: Enable KVM group perms
139+
run: |
140+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
141+
sudo udevadm control --reload-rules
142+
sudo udevadm trigger --name-match=kvm
143+
144+
- name: Setup Gradle
145+
uses: gradle/actions/setup-gradle@v4
146+
147+
- name: AVD Cache
148+
uses: actions/cache@v3
149+
id: capacitor-avd-cache
150+
with:
151+
path: |
152+
~/.android/avd/*
153+
~/.android/adb*
154+
key: capacitor-avd-31
155+
156+
- name: Set up JDK 17
157+
uses: actions/setup-java@v3
158+
with:
159+
java-version: 17
160+
distribution: 'adopt'
161+
cache: 'gradle'
162+
163+
- name: Enable Corepack
164+
run: corepack enable
165+
166+
- name: Setup Node.js
167+
uses: actions/setup-node@v6
168+
with:
169+
node-version-file: '.nvmrc'
170+
cache: pnpm
171+
172+
- name: Install dependencies
173+
run: pnpm install
174+
175+
- name: Install Capacitor example dependencies
176+
working-directory: ./packages/capacitor/example-app
177+
run: pnpm install
178+
179+
- name: Build Capacitor package
180+
run: pnpm --filter @powersync/capacitor build
181+
182+
- name: Initialize Android Folder
183+
run: mkdir -p ~/.android/avd
184+
185+
- name: Create AVD and generate snapshot for caching
186+
if: steps.capacitor-avd-cache.outputs.cache-hit != 'true'
187+
uses: reactivecircus/android-emulator-runner@v2.28.0
188+
with:
189+
api-level: 31
190+
force-avd-creation: false
191+
target: google_apis
192+
arch: x86_64
193+
disable-animations: false
194+
avd-name: $AVD_NAME
195+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
196+
script: echo "Generated AVD snapshot for caching."
197+
198+
- name: Run Capacitor Android browser tests
199+
uses: reactivecircus/android-emulator-runner@v2.28.0
200+
with:
201+
api-level: 31
202+
target: google_apis
203+
arch: x86_64
204+
avd-name: $AVD_NAME
205+
script: |
206+
pnpm exec vitest run --config vitest.config.ts
207+
force-avd-creation: false
208+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
209+
disable-animations: true
210+
115211
test-ios:
116212
name: Test iOS
117213
needs: check-changes
118214
# TODO: Re-enable iOS tests. They have been disabled because they are failing extremely frequently without
119215
# any apparent cause. In particular, it seems like even starting the simulator times out most of the time.
120-
if: ${{ false && needs.check-changes.outputs.should_run == 'true' }}
216+
if: ${{ false && needs.check-changes.outputs.react_native_simulator_should_run == 'true' }}
121217
runs-on: macOS-15
122218
timeout-minutes: 30
123219

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Using Android gitignore template: https://github.com/github/gitignore/blob/HEAD/Android.gitignore
2+
3+
# Built application files
4+
*.apk
5+
*.aar
6+
*.ap_
7+
*.aab
8+
9+
# Files for the ART/Dalvik VM
10+
*.dex
11+
12+
# Java class files
13+
*.class
14+
15+
# Generated files
16+
bin/
17+
gen/
18+
out/
19+
# Uncomment the following line in case you need and you don't have the release build type files in your app
20+
# release/
21+
22+
# Gradle files
23+
.gradle/
24+
build/
25+
26+
# Local configuration file (sdk path, etc)
27+
local.properties
28+
29+
# Proguard folder generated by Eclipse
30+
proguard/
31+
32+
# Log Files
33+
*.log
34+
35+
# Android Studio Navigation editor temp files
36+
.navigation/
37+
38+
# Android Studio captures folder
39+
captures/
40+
41+
# IntelliJ
42+
*.iml
43+
.idea/workspace.xml
44+
.idea/tasks.xml
45+
.idea/gradle.xml
46+
.idea/assetWizardSettings.xml
47+
.idea/dictionaries
48+
.idea/libraries
49+
# Android Studio 3 in .gitignore file.
50+
.idea/caches
51+
.idea/modules.xml
52+
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
53+
.idea/navEditor.xml
54+
55+
# Keystore files
56+
# Uncomment the following lines if you do not want to check your keystore files in.
57+
#*.jks
58+
#*.keystore
59+
60+
# External native build folder generated in Android Studio 2.2 and later
61+
.externalNativeBuild
62+
.cxx/
63+
64+
# Google Services (e.g. APIs or Firebase)
65+
# google-services.json
66+
67+
# Freeline
68+
freeline.py
69+
freeline/
70+
freeline_project_description.json
71+
72+
# fastlane
73+
fastlane/report.xml
74+
fastlane/Preview.html
75+
fastlane/screenshots
76+
fastlane/test_output
77+
fastlane/readme.md
78+
79+
# Version control
80+
vcs.xml
81+
82+
# lint
83+
lint/intermediates/
84+
lint/generated/
85+
lint/outputs/
86+
lint/tmp/
87+
# lint/reports/
88+
89+
# Android Profiling
90+
*.hprof
91+
92+
# Cordova plugins for Capacitor
93+
capacitor-cordova-android-plugins
94+
95+
# Copied web assets
96+
app/src/main/assets/public
97+
98+
# Generated Config files
99+
app/src/main/assets/capacitor.config.json
100+
app/src/main/assets/capacitor.plugins.json
101+
app/src/main/res/xml/config.xml
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build/*
2+
!/build/.npmkeep
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
namespace = "com.powersync.capacitor"
5+
compileSdk = rootProject.ext.compileSdkVersion
6+
defaultConfig {
7+
applicationId "com.powersync.capacitor"
8+
minSdkVersion rootProject.ext.minSdkVersion
9+
targetSdkVersion rootProject.ext.targetSdkVersion
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13+
aaptOptions {
14+
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
15+
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
16+
ignoreAssetsPattern = '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
17+
}
18+
}
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
}
26+
27+
repositories {
28+
flatDir{
29+
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
30+
}
31+
}
32+
33+
dependencies {
34+
implementation fileTree(include: ['*.jar'], dir: 'libs')
35+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
36+
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
37+
implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
38+
implementation project(':capacitor-android')
39+
testImplementation "junit:junit:$junitVersion"
40+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
41+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
42+
implementation project(':capacitor-cordova-android-plugins')
43+
}
44+
45+
apply from: 'capacitor.build.gradle'
46+
47+
try {
48+
def servicesJSON = file('google-services.json')
49+
if (servicesJSON.text) {
50+
apply plugin: 'com.google.gms.google-services'
51+
}
52+
} catch(Exception e) {
53+
logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
54+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
2+
3+
android {
4+
compileOptions {
5+
sourceCompatibility JavaVersion.VERSION_21
6+
targetCompatibility JavaVersion.VERSION_21
7+
}
8+
}
9+
10+
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
11+
dependencies {
12+
implementation project(':powersync-capacitor')
13+
implementation project(':capacitor-community-sqlite')
14+
15+
}
16+
17+
18+
if (hasProperty('postBuildExtras')) {
19+
postBuildExtras()
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.getcapacitor.myapp;
2+
3+
import static org.junit.Assert.*;
4+
5+
import android.content.Context;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
import androidx.test.platform.app.InstrumentationRegistry;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
15+
*/
16+
@RunWith(AndroidJUnit4.class)
17+
public class ExampleInstrumentedTest {
18+
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
23+
24+
assertEquals("com.getcapacitor.app", appContext.getPackageName());
25+
}
26+
}

0 commit comments

Comments
 (0)