> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/android/collaboration/setup-a.md).

# Setting up realtime document collaboration in Android

Learn how to integrate Apryse collaboration package with Gradle and Android manual integration guide. Set minSdkVersion to 21+ and enable Java 8 features for optimal performance. Follow step-by-step i

## Prerequisites

* Minimum API: 21
* Java 8

## Step 1: Integration

### Integrate collaboration package with Gradle

1. Integrate Apryse core and the tools library as described in our [Gradle get started guide](/android/get-started/integration.md).
2. In your app module's `build.gradle` file (usually `app/build.gradle`), set the `minSdkVersion` to 21+ and enable compatibility for Java 8 features. Then, add the dependency for Apryse's collaboration package:

{% tabs %}
{% tab title="Groovy" %}
{% code lineNumbers="true" %}

```groovy
android {
    defaultConfig {
        minSdkVersion 21
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation "com.pdftron:collab:11.0.0"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Integrate collaboration package manually

1. Integrate Apryse core and tools packages as described in [Android manual integration guide](/android/get-started/integration.md).
2. Copy `pdftron-collab.aar` directly into your app module's `libs` directory. You will see other Apryse AARs here such as `pdftron.aar` and `tools.aar`
3. In your app module's `build.gradle` file (usually `app/build.gradle`), make sure the `minSdkVersion` is 21+ using Java 8 features. And add a dependency to Apryse collaboration package:

{% tabs %}
{% tab title="Groovy" %}
{% code lineNumbers="true" %}

```groovy
android {
    defaultConfig {
        minSdkVersion 21
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation "com.pdftron:collab@aar"

    // room
    implementation "android.arch.persistence.room:runtime:2.4.2"
    annotationProcessor "android.arch.persistence.room:compiler:2.4.2"
    implementation "android.arch.persistence.room:rxjava2:2.4.2"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Step 2: Add the viewer

1. Update your `AndroidManifest.xml` as described in **Step 1** of this guide.
2. Create the `CollabViewerTabHostFragment2`, and start it like any other Android Fragment.

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
// Create a viewer fragment using CollabViewerBuilder2 and add it to an activity
public void addViewerFragment(AppCompatActivity activity, Uri fileUri) {
    // Create a custom ViewerConfig used to initialize the viewer fragment
    ViewerConfig config = new ViewerConfig.Builder()
            .multiTabEnabled(false)
            .build();
    // Create the Fragment using CollabViewerBuilder2
    CollabViewerTabHostFragment2 tabHostFragment =
            CollabViewerBuilder2.withUri(fileUri)
                    .usingConfig(config)
                    .build(activity);
    // Add the Fragment to your activity
    FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.fragment_container, tabHostFragment, null);
    ft.commit();
}
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
// Create a viewer fragment using CollabViewerBuilder2 and add it to an activity
fun addViewerFragment(activity: AppCompatActivity, fileUri: Uri) {
    // Create a custom ViewerConfig used to initialize the viewer fragment
    val config = ViewerConfig.Builder()
            .multiTabEnabled(false)
            .build()
    // Create the Fragment using CollabViewerBuilder2
    val tabHostFragment =
            CollabViewerBuilder2.withUri(fileUri)
                    .usingConfig(config)
                    .build(activity)
    // Add the Fragment to your activity
    val ft = activity.supportFragmentManager.beginTransaction()
    ft.replace(R.id.fragment_container, tabHostFragment, null)
    ft.commit()
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

where `R.id.fragment_container` is the resource id of a layout in your activity that will contain your fragment:

**For example:**

{% tabs %}
{% tab title="XML" %}
{% code lineNumbers="true" %}

```xml
<?xml version="1.0" encoding="utf-8"?>
<!-- This FrameLayout will contain our viewer fragment -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent"/>
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Next steps

* [Connect with annotation database](/android/collaboration/server-a.md)
* [Customize collaboration UI](/android/collaboration/custom-ui.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/android/collaboration/setup-a.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
