Skip to content

Commit

Permalink
feat!: android as CDP source (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 authored Jul 24, 2024
2 parents 8dce9ba + 4bfb9af commit 772b489
Show file tree
Hide file tree
Showing 331 changed files with 11,510 additions and 9,213 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build-sample-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build sample apps
on:
pull_request: # build sample apps for every commit pushed to an open pull request (including drafts)
push:
branches: [main]
branches: [main, feature/*]
release: # build sample apps for every git tag created. These are known as "stable" builds that are suitable for people outside the mobile team.
types: [published]

Expand Down Expand Up @@ -59,9 +59,11 @@ jobs:
- "kotlin_compose"
include: # Add additional variables to each sample app build: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrixinclude
- sample-app: "java_layout"
cio-cdpapikey-secret-key: "CUSTOMERIO_JAVA_WORKSPACE_CDP_API_KEY"
cio-siteid-secret-key: "CUSTOMERIO_JAVA_WORKSPACE_SITE_ID"
cio-apikey-secret-key: "CUSTOMERIO_JAVA_WORKSPACE_API_KEY"
- sample-app: "kotlin_compose"
cio-cdpapikey-secret-key: "CUSTOMERIO_KOTLIN_WORKSPACE_CDP_API_KEY"
cio-siteid-secret-key: "CUSTOMERIO_KOTLIN_WORKSPACE_SITE_ID"
cio-apikey-secret-key: "CUSTOMERIO_KOTLIN_WORKSPACE_API_KEY"

Expand All @@ -86,6 +88,7 @@ jobs:
- name: Setup local.properties file for sample app
run: |
touch "samples/local.properties"
echo "cdpApiKey=${{ secrets[matrix.cio-cdpapikey-secret-key] }}" >> "samples/local.properties"
echo "siteId=${{ secrets[matrix.cio-siteid-secret-key] }}" >> "samples/local.properties"
echo "apiKey=${{ secrets[matrix.cio-apikey-secret-key] }}" >> "samples/local.properties"
Expand Down Expand Up @@ -122,4 +125,4 @@ jobs:
issue-number: ${{ github.event.pull_request.number }}
body: |
* ${{ matrix.sample-app }}: Build failed. See [CI job logs](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) to determine the issue and try re-building.
edit-mode: append # append new line to the existing PR comment to build a list of all sample app builds.
edit-mode: append # append new line to the existing PR comment to build a list of all sample app builds.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
module: [tracking, messagingpush, messaginginapp] # android modules
module: [core, datapipelines, messagingpush, messaginginapp, tracking-migration] # android modules
name: Android Lint (${{ matrix.module }})
steps:
- uses: actions/checkout@v4
Expand Down
60 changes: 47 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Tests

on: [push, pull_request]
on:
pull_request:
types: [opened, synchronize] # Don't rerun on `edited` to save time

jobs:
unit-test:
runs-on: ubuntu-latest
strategy:
matrix:
module: [tracking, messagingpush, messaginginapp, base]
module: [messagingpush, messaginginapp, base, datapipelines, core, tracking-migration]
name: Unit tests (${{ matrix.module }})
steps:
- uses: actions/checkout@v4
Expand All @@ -31,7 +33,7 @@ jobs:
if: ${{ always() }} # if running tests fails, we still want to parse the test results

instrumentation-test:
runs-on: macos-latest
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
# Add more samples here as they are added to the project.
Expand All @@ -40,22 +42,54 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-android
- name: Start emulator
# Enable KVM (Kernel-based Virtual Machine) for better performance by allowing hardware virtualization
- name: Enable KVM
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
# Cache Gradle dependencies to speed up the build process
- name: Gradle cache
uses: gradle/actions/setup-gradle@v3

# Cache the Android Virtual Device (AVD) to avoid recreating it each time
- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-31
restore-keys: |
avd-
# Create AVD and generate snapshot for caching if not already cached
- 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: 31
arch: x86_64
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -grpc 8554 -verbose -timezone America/New_York
disable-animations: true
script: echo "Generated AVD snapshot for caching."

- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
# Configuration options for the emulator for the best optimization.
api-level: 29
api-level: 31
cores: 3
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -grpc 8554 -verbose -timezone America/New_York
disable-animations: true
ram-size: 4096M
emulator-boot-timeout: 12000
target: default
arch: x86
emulator-build: 7425822 # https://github.com/ReactiveCircus/android-emulator-runner/issues/160
profile: Nexus 6
target: google_apis
arch: x86_64
# Run the instrumentation tests on the emulator.
script: ./gradlew :samples:${{ matrix.sample }}:connectedDebugAndroidTest
script: ./gradlew :samples:${{ matrix.sample }}:connectedDebugAndroidTest --no-daemon --stacktrace -PuseKsp=true --debug
- name: Publish test results
uses: mikepenz/action-junit-report@v4
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{
"assets": [
"CHANGELOG.md",
"sdk/src/main/java/io/customer/sdk/Version.kt",
"core/src/main/kotlin/io/customer/sdk/Version.kt",
"reports/sdk-binary-size.json"
],
"message": "chore: prepare for ${nextRelease.version}\n\n${nextRelease.notes}"
Expand Down
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</p>

![min Android SDK version is 21](https://img.shields.io/badge/min%20Android%20SDK-21-green)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.customer.android/tracking/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.customer.android/tracking)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.customer.android/datapipelines/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.customer.android/datapipelines)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](code_of_conduct.md)
[![codecov](https://codecov.io/gh/customerio/customerio-android/branch/develop/graph/badge.svg?token=PYV1XQTKGO)](https://codecov.io/gh/customerio/customerio-android)

Expand Down Expand Up @@ -52,15 +52,15 @@ We separated our SDK into packages to minimize our impact on your app's size. Yo

| Package | Required? | Description |
| :-- | :---: | :--- |
| `tracking` | Yes | [`identify`](https://customer.io/docs/sdk/android/identify/) people/devices and [send events](https://customer.io/docs/sdk/android/track-events/) (to trigger campaigns, track metrics, etc). |
| `datapipelines` | Yes | [`identify`](https://customer.io/docs/sdk/android/identify/) people/devices and [send events](https://customer.io/docs/sdk/android/track-events/) (to trigger campaigns, track metrics, etc). |
| `messaging-push-fcm` | No | [Push](https://customer.io/docs/sdk/android/push/) and [rich push](https://customer.io/docs/sdk/android/rich-push/) notifications using Google Firebase Cloud Messaging (FCM). |

```groovy
implementation 'io.customer.android:tracking:<version-here>'
implementation 'io.customer.android:datapipelines:<version-here>'
implementation 'io.customer.android:messaging-push-fcm:<version-here>'
```

Replace `version-here` with the the latest version: ![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.customer.android/tracking/badge.svg)
Replace `version-here` with the the latest version: ![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.customer.android/datapipelines/badge.svg)


## Initialize the SDK
Expand All @@ -71,27 +71,24 @@ Before you can use the Customer.io SDK, you need to initialize it. `CustomerIO`
class App : Application() {
override fun onCreate() {
super.onCreate()
val customerIO = CustomerIO.Builder(
siteId = "your-site-id",
apiKey = "your-api-key",
appContext = this
val customerIO = CustomerIOBuilder(
applicationContext = this,
cdpApiKey = "your-cdp-api-key"
).build()


}
}
```

The `Builder` for CustomerIO exposes configuration options for features such `region`,`timeout`.

```kotlin
val builder = CustomerIO.Builder(
siteId = "YOUR-SITE-ID",
apiKey = "YOUR-API-KEY",
appContext = this
val builder = CustomerIOBuilder(
applicationContext = this,
cdpApiKey = "your-cdp-api-key"
)
builder.setRegion(Region.EU)
// set the request timeout for all the API requests sent from SDK
builder.setRequestTimeout(8000L)
// set the number of events that should be queued before they are flushed to the server.
builder.setFlushAt(10)
builder.build()
```

Expand Down
2 changes: 1 addition & 1 deletion base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ dependencies {
implementation Dependencies.coroutinesCore
implementation Dependencies.androidxAnnotations

testImplementation Dependencies.junit4
testImplementation "junit:junit:4.13.2"
testImplementation Dependencies.kluentJava
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ buildscript {
dependencies {
classpath Dependencies.androidGradlePlugin
classpath Dependencies.kotlinGradlePlugin
classpath Dependencies.kotlinSerialization
classpath Dependencies.kotlinBinaryValidator
classpath Dependencies.gradleNexusPublishPlugin
classpath Dependencies.dokka
Expand Down
11 changes: 10 additions & 1 deletion buildSrc/src/main/kotlin/io.customer/android/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ object Dependencies {
const val coroutinesTest =
"org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.COROUTINES}"
const val espressoCore = "androidx.test.espresso:espresso-core:${Versions.ESPRESSO}"
const val espressoIntents = "androidx.test.espresso:espresso-intents:${Versions.ESPRESSO}"
const val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:${Versions.DOKKA}"
const val hiltGradlePlugin = "com.google.dagger:hilt-android-gradle-plugin:${Versions.HILT}"
const val firebaseMessaging =
Expand All @@ -30,17 +31,24 @@ object Dependencies {
"com.google.gms:google-services:${Versions.GOOGLE_SERVICES_PLUGIN}"
const val gradleNexusPublishPlugin =
"io.github.gradle-nexus:publish-plugin:${Versions.GRADLE_NEXUS_PUBLISH_PLUGIN}"
const val junit4 = "junit:junit:${Versions.JUNIT4}"
const val junit4 = "junit:junit"
const val junitBom = "org.junit:junit-bom:${Versions.JUNIT_BOM}"
const val junitJupiter = "org.junit.jupiter:junit-jupiter"
const val junitVintageEngine = "org.junit.vintage:junit-vintage-engine"
const val kluent = "org.amshove.kluent:kluent-android:${Versions.KLUENT}"
const val kotlinBinaryValidator =
"org.jetbrains.kotlinx:binary-compatibility-validator:${Versions.KOTLIN_BINARY_VALIDATOR}"
const val kotlinxSerializationJson = "org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.KOTLINX_SERIALIZATION_JSON}"
const val kluentJava = "org.amshove.kluent:kluent:${Versions.KLUENT}"
const val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.KOTLIN}"
const val kotlinSerialization = "org.jetbrains.kotlin:kotlin-serialization:${Versions.KOTLIN}"
const val timber = "com.jakewharton.timber:timber:${Versions.TIMBER}"
const val moshi = "com.squareup.moshi:moshi:${Versions.MOSHI}"
const val mockito = "org.mockito:mockito-core:${Versions.MOCKITO}"
const val mockitoAndroid = "org.mockito:mockito-android:${Versions.MOCKITO}"
const val mockitoKotlin = "org.mockito.kotlin:mockito-kotlin:${Versions.MOCKITO_KOTLIN}"
const val mockK = "io.mockk:mockk:${Versions.MOCKK}"
const val mockKAndroid = "io.mockk:mockk-android:${Versions.MOCKK}"
const val moshiCodeGen = "com.squareup.moshi:moshi-kotlin-codegen:${Versions.MOSHI}"
const val robolectric = "org.robolectric:robolectric:${Versions.ROBOLECTRIC}"
const val retrofit = "com.squareup.retrofit2:retrofit:${Versions.RETROFIT}"
Expand All @@ -49,4 +57,5 @@ object Dependencies {
const val okhttpMockWebserver = "com.squareup.okhttp3:mockwebserver:${Versions.OKHTTP}"
const val okhttpLoggingInterceptor =
"com.squareup.okhttp3:logging-interceptor:${Versions.OKHTTP}"
const val segment = "com.segment.analytics.kotlin:android:${Versions.SEGMENT}"
}
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/io.customer/android/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Versions {
internal const val APK_SCALE = "0.1.7"
internal const val COROUTINES = "1.6.4"
internal const val DOKKA = "1.5.0"
internal const val JUNIT4 = "4.13.2"
internal const val JUNIT_BOM = "5.9.3"
internal const val ESPRESSO = "3.4.0"
internal const val FIREBASE_MESSAGING = "23.1.0"
internal const val GRADLE_NEXUS_PUBLISH_PLUGIN = "1.3.0"
Expand All @@ -22,11 +22,14 @@ object Versions {
const val HILT = "2.44.2"
internal const val KLUENT = "1.72"
internal const val KOTLIN_BINARY_VALIDATOR = "0.14.0"
internal const val KOTLINX_SERIALIZATION_JSON = "1.5.1"
internal const val KOTLIN = "1.7.21"
internal const val MATERIAL_COMPONENTS = "1.4.0"
internal const val MOCKITO_KOTLIN = "4.0.0"
internal const val MOCKITO = "4.8.1"
internal const val MOCKK = "1.12.2"
internal const val MOSHI = "1.14.0"
internal const val SEGMENT = "1.16.3"
internal const val TIMBER = "5.0.0"
internal const val ROBOLECTRIC = "4.9"
internal const val OKHTTP = "4.11.0"
Expand Down
40 changes: 16 additions & 24 deletions common-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,22 @@ android {
}

dependencies {
// since all modules in project inherit the base tracking SDK, add it here to our shared testing module as all modules in project should have access to this module.
api project(':tracking')

// Non-testing tools that all modules use.
api Dependencies.retrofit
api Dependencies.moshi

// Testing tools that source code in this module require to compile.
// Since core module is the only required module by all modules, it is added as dependency here.
// No other module should be added as dependency to avoid false positive compilation.
implementation project(":core")
// Common test dependencies used by both JVM and Android tests
api Dependencies.androidxTestJunit
api Dependencies.androidxTestRunner
api Dependencies.androidxTestRules

api Dependencies.mockito
api Dependencies.mockitoKotlin
api Dependencies.robolectric

api Dependencies.kluent
api Dependencies.okhttpMockWebserver

// JUnit BOM to manage JUnit dependencies across the SDK
api platform(Dependencies.junitBom)
// Since JUnit4 is used by Robolectric in JVM tests, and by Android instrumentation tests
// in androidTest, we need to include it as api dependency to be available in both tests.
api Dependencies.junit4

// compile time bug when trying to run Android tests: https://github.com/Kotlin/kotlinx.coroutines/issues/2023
// Solution from: https://github.com/Kotlin/kotlinx.coroutines/tree/master/kotlinx-coroutines-debug#debug-agent-and-android
api(Dependencies.coroutinesTest) {
exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
}
}
// Compile only dependencies so common test classes can use them without exposing them to other modules
// Final dependencies are added to JVM and Android tests separately in the android-module-testing.gradle
compileOnly Dependencies.coroutinesTest
compileOnly Dependencies.espressoIntents
compileOnly Dependencies.junitJupiter
compileOnly Dependencies.mockK
compileOnly Dependencies.robolectric
}

This file was deleted.

Loading

0 comments on commit 772b489

Please sign in to comment.