Quickstart
This guide will help you to get started with the Abra SDK package for Android.
Setup
The Android Library is published at: Maven Central
-
Open Android Studio.
-
Open the Gradle settings file of your project, e.g.
settings.gradle.kts
. -
Ensure Maven Central is included as repository in the
dependencyResolutionManagement
section.settings.gradle.ktsdependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
} -
Open the Gradle file of your module, e.g.
build.gradle.kts
. -
Add
ai.abra:abra-sdk:{VERSION}
asandroidTestImplementation
in thedependencies
section.settings.gradle.ktsdependencies {
androidTestImplementation("ai.abra:abra-sdk:1.1.0")
} -
Press
Sync now
to download and import the library.
tip
Check the release notes for available version.
Usage
After adding the library, you are ready to use it in your test target.
- Import the SDK:
import ai.abra.sdk.Abra
- Configure the SDK:
val config = AbraConfig(
license = "<YOUR-SDK-LICENSE>",
identifier = "<YOUR-APP-IDENTIFIER>"
)
val abra = Abra(config = config) - Configure the rules:
val abraRules = abra.abraRules {
all()
}
val googleRules = abra.googleRules {
all()
} - Perform an audit:
val results = abra.audit(rules)
Example
tip
Also check the Abra API for Android to learn how to upload results to the Abra Dashboard.
AbraTestCase.kt
package ai.abra.mobile.tests
import ai.abra.sdk.Abra
import ai.abra.sdk.AbraConfig
import ai.abra.sdk.rule.ResultType
import ai.abra.sdk.rule.Rule
import android.app.Instrumentation
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.uiautomator.UiDevice
import junit.framework.TestCase.assertNotNull
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Before
import org.junit.rules.ErrorCollector
@RunWith(AndroidJUnit4::class)
open class AbraTestCase {
private val LICENSE = "XXXXXXXXXX"
private val IDENTIFIER = "com.android.settings"
protected lateinit var instrumentation: Instrumentation
protected lateinit var device: UiDevice
protected lateinit var context: Context
protected lateinit var abra: Abra
protected lateinit var rules: List<Rule>
@get:org.junit.Rule
val collector = ErrorCollector()
@Before
open fun before() {
this.instrumentation = InstrumentationRegistry.getInstrumentation()
this.device = UiDevice.getInstance(instrumentation)
this.context = ApplicationProvider.getApplicationContext()
val config = AbraConfig(
license = LICENSE,
identifier = IDENTIFIER,
)
this.abra = Abra(config = config)
this.rules = abra.abraRules { all() } +
abra.googleRules { all() }
}
@Test
fun testAccessibility() {
val intent = context.packageManager.getLaunchIntentForPackage(IDENTIFIER)
assertNotNull("Launch intent must be available for $IDENTIFIER", intent)
context.startActivity(intent)
val results = abra.audit(rules)
results.forEach { result ->
collector.checkSucceeds {
if (result.metadata.type == ResultType.ERROR) {
throw AssertionError("${result.metadata.rule}: ${result.metadata.message}")
}
}
}
}
}
Results

