Skip to main content

Installation (Android)

alphaTab on Android renders and plays music notation in native apps built with Kotlin. It ships an AlphaTabView for classic Android layouts.

Installโ€‹

alphaTab is published on Maven Central under the coordinates net.alphatab:alphaTab:

Add the dependency to your build system:

repositories {
google()
mavenCentral()
// Pre-release snapshots:
// maven("https://central.sonatype.com/repository/maven-snapshots/")
}

dependencies {
implementation("net.alphatab:alphaTab:1.6.1")
// Pre-release snapshots:
// implementation("net.alphatab:alphaTab:1.7.0-SNAPSHOT")
}

Render your first scoreโ€‹

Once alphaTab is on the classpath, add the AlphaTabView control to any layout. This example places it inside a ConstraintLayout that fills the activity:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.alphatab.android.MainActivity">

<alphaTab.AlphaTabView
android:id="@+id/alphatab_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Get a reference to the view from your activity and use its api property to drive alphaTab:

import alphaTab.AlphaTabView

class MainActivity : ComponentActivity() {
private lateinit var alphaTabView: AlphaTabView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

alphaTabView = findViewById(R.id.alphatab_view)
val api = alphaTabView.api
// load a score, subscribe to events, drive playback here
}
}

More samples live at github.com/CoderLine/alphaTabSamplesAndroid.

Jetpack Composeโ€‹

alphaTab does not currently ship a Compose control. Two options:

Dependenciesโ€‹

alphaTab on Android carries a small number of third-party dependencies:

  • Rendering. Either the built-in Android Canvas or alphaSkia, which wraps the Skia engine used by Chrome. alphaSkia is the recommended engine and is significantly faster than the platform canvas.
  • Async. org.jetbrains.kotlinx:kotlinx-coroutines-core powers alphaTab's asynchronous operations.

Reach out on GitHub if you need alphaTab wired to a different UI framework or audio backend.