Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android test app #169

Merged
merged 8 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 71 additions & 5 deletions .github/workflows/android-appcenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ on:
push:
branches: [ main ]
paths:
- 'demo/android/Activity/cobra-activity-demo-app/build.gradle'
- 'binding/android/CobraTestApp/cobra-test-app/build.gradle'
- '.github/workflows/android-appcenter.yml'

pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- 'demo/android/Activity/cobra-activity-demo-app/build.gradle'
- 'binding/android/CobraTestApp/cobra-test-app/build.gradle'
- '.github/workflows/android-appcenter.yml'

defaults:
run:
working-directory: demo/android/Activity
working-directory: binding/android/CobraTestApp

jobs:
build:
Expand Down Expand Up @@ -46,6 +46,16 @@ jobs:
- name: Inject AccessKey
run: echo pvTestingAccessKey="${{secrets.PV_VALID_ACCESS_KEY}}" >> local.properties

- name: Inject Android keystore variables
run: |
echo storePassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties
echo keyPassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties
echo keyAlias=picovoice >> local.properties
echo storeFile=../picovoice.jks >> local.properties

- name: Setup Android keystore file
run: echo "${{secrets.ANDROID_RELEASE_KEYSTORE_FILE_B64}}" | base64 -d > picovoice.jks

- name: Build app
run: ./gradlew assembleDebug

Expand All @@ -57,7 +67,63 @@ jobs:
--token ${{secrets.APPCENTERAPITOKEN}}
--app "Picovoice/Cobra-Android-Activity"
--devices "Picovoice/android-min-max"
--app-path cobra-activity-demo-app/build/outputs/apk/debug/cobra-activity-demo-app-debug.apk
--app-path cobra-test-app/build/outputs/apk/debug/cobra-test-app-debug.apk
--test-series "cobra-android"
--locale "en_US"
--build-dir cobra-test-app/build/outputs/apk/androidTest/debug

build-integ:
name: Run Android Integration Tests on AppCenter
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js LTS
uses: actions/setup-node@v3
with:
node-version: lts/*

- name: Install AppCenter CLI
run: npm install -g appcenter-cli

- name: set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Copy test_resources
run: ./copy_test_resources.sh

- name: Inject AccessKey
run: echo pvTestingAccessKey="${{secrets.PV_VALID_ACCESS_KEY}}" >> local.properties

- name: Inject Android keystore variables
run: |
echo storePassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties
echo keyPassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties
echo keyAlias=picovoice >> local.properties
echo storeFile=../picovoice.jks >> local.properties

- name: Setup Android keystore file
run: echo "${{secrets.ANDROID_RELEASE_KEYSTORE_FILE_B64}}" | base64 -d > picovoice.jks

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build app
run: ./gradlew assembleRelease

- name: Build androidTest
run: ./gradlew assembleReleaseAndroidTest -DtestBuildType=integ

- name: Run tests on AppCenter
run: appcenter test run espresso
--token ${{secrets.APPCENTERAPITOKEN}}
--app "Picovoice/Cobra-Android-Activity"
--devices "Picovoice/android-min-max"
--app-path cobra-test-app/build/outputs/apk/release/cobra-test-app-release.apk
--test-series "cobra-android"
--locale "en_US"
--build-dir cobra-activity-demo-app/build/outputs/apk/androidTest/debug
--build-dir cobra-test-app/build/outputs/apk/androidTest/release
20 changes: 15 additions & 5 deletions .github/workflows/android-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

defaults:
run:
working-directory: demo/android/Activity
working-directory: binding/android/CobraTestApp

jobs:
build:
Expand All @@ -27,7 +27,7 @@ jobs:
device: [single-android, 32bit-android]
include:
- device: single-android
performanceThresholdSec: 0.003
performanceThresholdSec: 0.005
- device: 32bit-android
performanceThresholdSec: 0.015

Expand Down Expand Up @@ -57,6 +57,16 @@ jobs:
- name: Inject Number of Iterations
run: echo numTestIterations="100" >> local.properties

- name: Inject Android keystore variables
run: |
echo storePassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties
echo keyPassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties
echo keyAlias=picovoice >> local.properties
echo storeFile=../picovoice.jks >> local.properties

- name: Setup Android keystore file
run: echo "${{secrets.ANDROID_RELEASE_KEYSTORE_FILE_B64}}" | base64 -d > picovoice.jks

- name: Inject Performance Threshold
run: echo performanceThresholdSec="${{ matrix.performanceThresholdSec }}" >> local.properties

Expand All @@ -67,14 +77,14 @@ jobs:
run: ./gradlew assembleDebug

- name: Build androidTest
run: ./gradlew assembleAndroidTest
run: ./gradlew assembleAndroidTest -DtestBuildType=perf

- name: Run tests on AppCenter
run: appcenter test run espresso
--token ${{secrets.APPCENTERAPITOKEN}}
--app "Picovoice/Cobra-Android-Activity"
--devices "Picovoice/${{ matrix.device }}"
--app-path cobra-activity-demo-app/build/outputs/apk/debug/cobra-activity-demo-app-debug.apk
--app-path cobra-test-app/build/outputs/apk/debug/cobra-test-app-debug.apk
--test-series "cobra-android"
--locale "en_US"
--build-dir cobra-activity-demo-app/build/outputs/apk/androidTest/debug
--build-dir cobra-test-app/build/outputs/apk/androidTest/debug
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions binding/android/CobraTestApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/
.DS_Store
/build
/captures
.externalNativeBuild
release
test_resources

*.jks
!.dummy.jks
24 changes: 24 additions & 0 deletions binding/android/CobraTestApp/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ext {
defaultTargetSdkVersion = 31
}

buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
2 changes: 2 additions & 0 deletions binding/android/CobraTestApp/cobra-test-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
*.wav
124 changes: 124 additions & 0 deletions binding/android/CobraTestApp/cobra-test-app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
apply plugin: 'com.android.application'

Properties properties = new Properties()
if (rootProject.file("local.properties").exists()) {
properties.load(rootProject.file("local.properties").newDataInputStream())
if (project.hasProperty("pvTestingAccessKey")) {
properties.put("pvTestingAccessKey", project.getProperty("pvTestingAccessKey"))
}
if (project.hasProperty("numTestIterations")) {
properties.put("numTestIterations", project.getProperty("numTestIterations"))
}
if (project.hasProperty("performanceThresholdSec")) {
properties.put("performanceThresholdSec", project.getProperty("performanceThresholdSec"))
}

if (project.hasProperty("storePassword")) {
properties.put("storePassword", project.getProperty("storePassword"))
}
if (project.hasProperty("storeFile")) {
properties.put("storeFile", project.getProperty("storeFile"))
}
if (project.hasProperty("keyAlias")) {
properties.put("keyAlias", project.getProperty("keyAlias"))
}
if (project.hasProperty("keyPassword")) {
properties.put("keyPassword", project.getProperty("keyPassword"))
}
}

android {
compileSdkVersion defaultTargetSdkVersion

defaultConfig {
applicationId "ai.picovoice.cobra.testapp"
minSdkVersion 21
targetSdkVersion defaultTargetSdkVersion
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

resValue 'string', 'pvTestingAccessKey', properties.getProperty("pvTestingAccessKey", "")
resValue 'string', 'numTestIterations', properties.getProperty("numTestIterations", "")
resValue 'string', 'performanceThresholdSec', properties.getProperty("performanceThresholdSec", "")
}

signingConfigs {
release {
storePassword properties.getProperty("storePassword")
storeFile file(properties.getProperty("storeFile", ".dummy.jks"))
keyAlias properties.getProperty("keyAlias")
keyPassword properties.getProperty("keyPassword")
}
}

buildTypes {
debug {
signingConfig signingConfigs.release
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}

if (System.getProperty("testBuildType", "debug") == "integ") {
testBuildType("release")
}

sourceSets {
androidTest {
java {
if (System.getProperty("testBuildType", "debug") == "perf") {
exclude "**/CobraTest.java"
exclude "**/IntegrationTest.java"
} else if (System.getProperty("testBuildType", "debug") == "integ") {
exclude "**/CobraTest.java"
exclude "**/PerformanceTest.java"
} else {
exclude "**/IntegrationTest.java"
exclude "**/PerformanceTest.java"
}
}
}
}

task("copyAudio", type: Copy) {
description = "Copy audio resources"
from("$projectDir/../../../../res/audio/")
include("sample.wav")
into("$projectDir/src/main/assets/audio/")
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lint {
abortOnError false
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'ai.picovoice:cobra-android:1.2.0'

// Espresso UI Testing
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation('androidx.test.espresso:espresso-core:3.2.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation('com.microsoft.appcenter:espresso-test-extension:1.4')
androidTestImplementation('androidx.test.espresso:espresso-intents:3.5.1')
}

afterEvaluate {
tasks."mergeDebugAssets".dependsOn "copyAudio"
tasks."mergeReleaseAssets".dependsOn "copyAudio"
}
23 changes: 23 additions & 0 deletions binding/android/CobraTestApp/cobra-test-app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class com.google.** { *; }
-keep class com.microsoft.** { *; }
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
limitations under the License.
*/

package ai.picovoice.cobraactivitydemo;
package ai.picovoice.cobra.testapp;

import android.content.Context;
import android.content.res.AssetManager;
Expand Down
Loading