Skip to content

Commit

Permalink
[STAD-578] Remove flavors and fix emulator in CI
Browse files Browse the repository at this point in the history
Remove flavors
  • Loading branch information
hb0 authored Mar 20, 2024
2 parents 1989eaf + 5a16260 commit 6e38158
Show file tree
Hide file tree
Showing 61 changed files with 192 additions and 607 deletions.
68 changes: 57 additions & 11 deletions .github/workflows/gradle_connected-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,45 @@ on:
- main

jobs:
build:
androidTest:
# Faster, but MacOS costs 8 ct/min instead of 0.8 ct/min of on Linux.
# Unfortunately, `DataCapturingServiceTest.testDisconnectReconnect` fails on linux stack.
# But as this is a public repository, Github Actions are currently free of charge.
runs-on: macos-latest # as recommended in `actions/android-emulator-runner`
#runs-on: macos-latest # as recommended in `actions/android-emulator-runner`

# To test against multiple APIs
# But we had to add `free-disk-space` to fix emulator flakiness. It only runs on ubuntu.
runs-on: ubuntu-latest

timeout-minutes: 55
strategy:
matrix:
api-level: [ 28 ]

steps:
- name: Checkout commit
uses: actions/checkout@v3
# From https://github.com/android/nowinandroid/pull/1219/files to fix flaky emulator start
# See https://github.com/ReactiveCircus/android-emulator-runner/issues/324#issuecomment-1998737488
- name: Delete unnecessary tools 🔧
uses: jlumbroso/free-disk-space@v1.3.1
with:
android: false # Keep Don't remove Android tools
tool-cache: true # Remove image tool cache - rm -rf "$AGENT_TOOLSDIRECTORY"
dotnet: true # rm -rf /usr/share/dotnet
haskell: true # rm -rf /opt/ghc...
swap-storage: true # rm -f /mnt/swapfile (4GiB)
docker-images: false # Takes 16s (`nowinandroid`), enable if needed in the future
large-packages: false # includes google-cloud-sdk and it's slow

# Set up KVM permissions to enable efficient Android emulator runs by modifying udev rules for universal access.
# From https://github.com/android/nowinandroid/blob/main/.github/workflows/Build.yaml#L142
- name: Enable KVM group perms
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
ls /dev/kvm
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
Expand All @@ -47,8 +72,9 @@ jobs:
# run: ./gradlew build

# Add caching to speed up connected tests below (see `actions/android-emulator-runner`)
- name: Gradle cache
uses: gradle/gradle-build-action@v2
- name: Setup Gradle
uses: gradle/gradle-build-action@v3

#- name: AVD cache
# uses: actions/cache@v3
# id: avd-cache
Expand All @@ -66,14 +92,34 @@ jobs:
# disable-animations: true
# script: echo "Generated AVD snapshot for caching."

# From https://github.com/android/nowinandroid/blob/main/.github/workflows/Build.yaml#L142
- name: Build projects before running emulator
run: ./gradlew packageDebugAndroidTest

# Only execute mock tests to exclude `@FlakyTest`s (instead of running `connectedCheck`)
- name: Connected tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
force-avd-creation: false
emulator-options: -no-snapshot-save
# From https://github.com/android/nowinandroid >>>
arch: x86_64
disable-animations: true
script: ./gradlew :persistence:connectedDebugAndroidTest :datacapturing:connectedCyfaceMockDebugAndroidTest :synchronization:connectedCyfaceMockDebugAndroidTest :datacapturing:connectedMovebisMockDebugAndroidTest :synchronization:connectedMovebisMockDebugAndroidTest
disk-size: 6000M
heap-size: 600M
# <<<<
# default options are: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim
# Action recommendation: -no-snapshot-save -camera-back none
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
#avd-name: ubuntu-avd-28
#force-avd-creation: false
script: ./gradlew :persistence:connectedDebugAndroidTest :datacapturing:connectedDebugAndroidTest :synchronization:connectedDebugAndroidTest --daemon
# To execute a single test class
#script: ./gradlew :datacapturing:connectedCyfaceMockDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=de.cyface.datacapturing.DataCapturingServiceTest
#script: ./gradlew :datacapturing:connectedCyfaceMockDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=de.cyface.datacapturing.DataCapturingServiceTest --daemon

# From https://github.com/android/nowinandroid/blob/main/.github/workflows/Build.yaml#L142
- name: Upload test reports
if: always()
uses: actions/upload-artifact@v4
with:
name: test-reports-${{ matrix.api-level }}
path: '**/build/reports/androidTests'
57 changes: 48 additions & 9 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ To use it as a dependency in your app you need to:
+
----
dependencies {
# To use the 'movebis' flavour, use: 'datacapturingmovebis'
implementation "de.cyface:datacapturing:$cyfaceAndroidBackendVersion"
# To use the 'movebis' flavour, use: 'synchronizationmovebis'
implementation "de.cyface:synchronization:$cyfaceAndroidBackendVersion"
# There is only one 'persistence' flavor
implementation "de.cyface:persistence:$cyfaceAndroidBackendVersion"
}
----
Expand Down Expand Up @@ -103,6 +100,48 @@ This SDK is compatible with our https://github.com/cyface-de/data-collector/rele

The following steps are required before you can start coding.

[[authenticator-and-sync-service]]]
==== Authenticator- and Sync Service

The SDK provides the CyfaceAuthenticatorService and CyfaceSyncService which authenticates with and uploads data
to a Cyface Collector API. The SDK implementing app can also implement services for different APIs.

Register the Authenticator- and Sync service which should be called by the system in the SDK
implementing app's `AndroidManifest.xml`, e.g. for the default implementations:

[source,xml]
----
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<service android:name="de.cyface.synchronization.CyfaceAuthenticatorService"
android:exported="false"
android:process=":sync">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
<service
android:name="de.cyface.synchronization.CyfaceSyncService"
android:exported="false"
android:process=":sync">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/sync_adapter" />
</service>
</application>
</manifest>
----

[[content-provider-authority]]
==== Content Provider Authority

Expand Down Expand Up @@ -136,7 +175,7 @@ application separately.
</manifest>
----

* Define your authority which you must use as parameter in `new Cyface-/MovebisDataCapturingService()`
* Define your authority which you must use as parameter in `new Cyface-/CustomDataCapturingService()`
(see sample below). This must be the same as defined in the `AndroidManifest.xml` above.

[source,java]
Expand Down Expand Up @@ -165,11 +204,11 @@ public class Constants {

The core of our SDK is the `DataCapturingService` which controls the capturing process.

We provide two interfaces for this service: `CyfaceDataCapturingService` and `MovebisDataCapturingService`.
Unless you are part of the _Movebis project_ `CyfaceDataCapturingService` is your candidate.
We provide a default interface for this service: `CyfaceDataCapturingService`.
Unless you need a custom `DataCapturingService` extension, use this one.

To keep this documentation lightweight, we currently only use `MovebisDataCapturingService` in the samples
but the interface for `CyfaceDataCapturingService` is mostly the same.
NOTE: This documentation is out of date as it describes a former extension `MovebisDataCapturingService`
in the samples but the interface for `CyfaceDataCapturingService` is mostly the same.

The following steps are required to communicate with this service.

Expand Down Expand Up @@ -889,7 +928,7 @@ The sub-package `content` implements a `ContentProvider` to allow `Synchronizati

==== Synchronization

The `SyncService` uploads measurements to the https://github.com/cyface-de/data-collector[Cyface Collector] & informs about the upload progress.
The `CyfaceSyncService` uploads measurements to the https://github.com/cyface-de/data-collector[Cyface Collector] & informs about the upload progress.

==== Testutils

Expand Down
28 changes: 1 addition & 27 deletions datacapturing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ plugins {
// use `:datacapturing:publishToMavenLocal` instead of `publishToMavenLocal` (see custom task `publishAll`)
// Don't move to root `build.gradle` as this forces SDK and camera_service to define this, too.
// Keep version in sync with other modules!
id 'de.cyface.android-publish' version '1.0.8'
id 'de.cyface.android-publish' version '1.1.0'
id 'kotlin-android'
id 'kotlin-kapt'
}
Expand All @@ -52,32 +52,6 @@ android {
]
}

// Specifies the flavor dimensions you want to use. The order in which you
// list each dimension determines its priority, from highest to lowest,
// when Gradle merges variant sources and configurations. You must assign
// each product flavor you configure to one of the flavor dimensions.
flavorDimensions "project", "mode"

productFlavors {
// Configurations in the "project" product flavors override those in "mode"
// flavors and the defaultConfig block. Gradle determines the priority
// between flavor dimensions based on the order in which they appear next
// to the flavorDimensions property above--the first dimension has a higher
// priority than the second, and so on.
movebis {
dimension "project"
}
cyface {
dimension "project"
}
mock {
dimension "mode"
}
full {
dimension "mode"
}
}

buildTypes {
release {
// Enable in app module to generate a single mapping.xml which can be uploaded to PlayStore
Expand Down
13 changes: 13 additions & 0 deletions datacapturing/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,18 @@
android:process=":persistence_process"
android:syncable="true"
tools:replace="android:authorities"/>

<!-- Some connected Android tests needs this to create a test account, or else we get -->
<!-- SecurityException: ... cannot explicitly add accounts of type: ... -->
<service android:name="de.cyface.synchronization.CyfaceAuthenticatorService"
android:exported="false"
android:process=":sync"> <!-- should be fine to use the sync process -->
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import de.cyface.persistence.model.MeasurementStatus
import de.cyface.persistence.model.Modality
import de.cyface.persistence.strategy.DefaultDistanceCalculation
import de.cyface.persistence.strategy.DefaultLocationCleaning
import de.cyface.synchronization.Constants.AUTH_TOKEN_TYPE
import de.cyface.uploader.exception.SynchronisationException
import de.cyface.utils.Validate

Expand Down Expand Up @@ -105,6 +104,7 @@ class MovebisDataCapturingService internal constructor(
* running.
*/
private val preMeasurementLocationManager: LocationManager?
private val AUTH_TOKEN_TYPE = "de.cyface.jwt"

/**
* A listener for location updates, which it passes through to the user interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class DataCapturingServiceTest {
@After
@Throws(NoSuchMeasurementException::class)
fun tearDown() {
if (isDataCapturingServiceRunning) {
if (oocut != null && isDataCapturingServiceRunning) {

// Stop zombie
// Do not reuse the lock/condition!
Expand Down Expand Up @@ -1229,4 +1229,4 @@ We should consider refactoring the code before to use startCommandReceived as in
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,4 @@ class PingPongTest {
CoreMatchers.`is`(CoreMatchers.equalTo(false))
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void shutdownDataCapturingService() throws SynchronisationException {
@SuppressWarnings("unused") // This is called by the SDK implementing app after an account was created
public void startWifiSurveyor() throws SetupException {
try {
// We require SDK users (other than Movebis) to always have exactly one account available
// We require SDK users (other than SR) to always have exactly one account available
final Account account = getWiFiSurveyor().getAccount();
getWiFiSurveyor().startSurveillance(account);
} catch (SynchronisationException e) {
Expand Down
24 changes: 0 additions & 24 deletions datacapturing/src/main/res/values-it/strings.xml

This file was deleted.

10 changes: 9 additions & 1 deletion persistence/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ plugins {
// use `:datacapturing:publishToMavenLocal` instead of `publishToMavenLocal` (see custom task `publishAll`)
// Don't move to root `build.gradle` as this forces SDK and camera_service to define this, too.
// Keep version in sync with other modules!
id 'de.cyface.android-publish' version '1.0.8'
id 'de.cyface.android-publish' version '1.1.0'
id 'kotlin-android'
id 'kotlin-kapt'
}
Expand Down Expand Up @@ -89,6 +89,14 @@ android {
}*/
}

// Required when executing connected tests
configurations {
configureEach {
// collides with hamcrest-all
exclude group: "org.hamcrest", module: "hamcrest-core"
}
}

dependencies {
// Android dependencies
implementation "androidx.annotation:annotation:$rootProject.ext.androidxAnnotationVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class DatabaseMigratorTest {
DatabaseMigrator.MIGRATION_14_15,
DatabaseMigrator.MIGRATION_15_16,
DatabaseMigrator.MIGRATION_16_17,
migrator!!.MIGRATION_17_18
migrator!!.MIGRATION_17_18,
DatabaseMigrator.MIGRATION_18_19,
)
}

Expand Down Expand Up @@ -849,7 +850,7 @@ class DatabaseMigratorTest {

// Assert
// Loading from the newly added table must work (STAD-85)
db!!.execSQL("SELECT * FROM events;")
db.execSQL("SELECT * FROM events;")
}

/**
Expand Down Expand Up @@ -895,7 +896,7 @@ class DatabaseMigratorTest {

// Assert
// Loading from the newly added table must work (STAD-85)
db!!.execSQL("SELECT * FROM events;")
db.execSQL("SELECT * FROM events;")

// Make sure the relevant data from before the upgrade still exists
var cursor: Cursor? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import de.cyface.persistence.model.Pressure
Attachment::class
],
// version 18 imported data from `v6.1` database into `measures.17` and migrated `measures` to Room
// version 19 adds the attachments table
version = 19
//autoMigrations = [] // test this feature on the next version change
)
Expand Down
Loading

0 comments on commit 6e38158

Please sign in to comment.