Integrating PSPDFKit Manually

To include PSPDFKit in your app, you’ll have to use a build system supporting the Android AAR library format — Gradle, Maven, or similar. The Eclipse IDE with the Ant build system is not supported.

Requirements

PSPDFKit is supported on Android devices with API 19 and newer, targeting the latest stable Android version P (API 28). PSPDFKit uses the Android support libraries to make many of the latest Android features available on older devices. You can target devices with API 19 and newer by setting the minSdkVersion inside your app’s build.gradle. Since PSPDFKit is developed and tested on the latest Android versions, set your compileSdkVersion and targetSdkVersion to those versions as well. Finally, you also need to enable Java 8 support for your project:

Copy
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 19
        targetSdkVersion 28
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Note: By targeting a minimum API of 19, your app is available on 96.4 percent of devices on the Google Play Store.

We recommend Android Studio 3.2 or higher as the IDE for development.

Automated Integration Using Gradle

The easiest way to integrate PSPDFKit into your app is by specifying it as a dependency inside your app’s build.gradle file.

  1. In your web browser, log in to https://customers.pspdfkit.com and navigate to the Your Licenses & Keys page. If you don’t yet have a customer account, you can also get an evaluation license.
  2. Locate your Android license and click Download PSPDFKit for Android, and then open the Use Gradle tab.
  3. Follow the instructions on the screen to integrate PSPDFKit into your app:
Copy
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
repositories {
    google()
    jcenter()
    ...

    maven {
        url 'https://customers.pspdfkit.com/maven/'

        credentials {
            username 'pspdfkit'
            password 'YOUR_MAVEN_KEY_GOES_HERE'
        }
    }
}

...

dependencies {
    ...
    compile 'com.pspdfkit:pspdfkit:5.0.1'
}

Note: If you are using a trial license, you need to add the com.pspdfkit:pspdfkit-demo:5.0.1 artifact instead.

If you encounter any problems during the integration, please let us know.

Example Catalog App

The example Catalog app contains a lot of useful examples for exploring the different features of PSPDFKit and getting started quickly. You can find the example Catalog sources inside the customer portal at https://customers.pspdfkit.com or by requesting an evaluation license of PSPDFKit.

Manual Library File Integration

  1. In your web browser, log in to https://customers.pspdfkit.com and navigate to the Your Licenses & Keys page. If you don’t yet have a customer account, you can also get an evaluation license.

  2. Locate your Android license and click Download PSPDFKit for Android.

  3. Download the PSPDFKit library zip bundle and extract it.

  4. Copy the PSPDFKit aar file into your project’s libs directory.

  5. Define the libs directory as a repository in your project’s build.gradle repositories section:

    build.gradle
    1
    2
    3
    4
    5
    6
    7
    
    repositories {
        jcenter()
    
        flatDir {
            dirs 'libs'
        }
    }
    
  6. Include PSPDFKit as a dependency in your project:

    Copy
    build.gradle
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    dependencies {
        ...
        compile 'com.pspdfkit:pspdfkit:[email protected]'
        compile 'com.android.support:support-v4:28.0.0'
        compile 'com.android.support:appcompat-v7:28.0.0'
        compile 'com.android.support:recyclerview-v7:28.0.0'
        compile 'com.android.support:cardview-v7:28.0.0'
        compile 'com.android.support:design:28.0.0'
        compile 'io.reactivex.rxjava2:rxjava:2.2.0'
        compile 'io.reactivex.rxjava2:rxandroid:2.1.0'
        compile 'com.getkeepsafe.relinker:relinker:1.2.2'
        compile 'com.facebook.device.yearclass:yearclass:2.0.0'
        compile 'org.jetbrains.kotlin:kotlin-stdlib:1.2.51'
    }
    

Note that Gradle looks for either pspdfkit.aar or pspdfkit-5.0.1.aar, so inclusion will not work if you rename the aar file. We’re also including the following optional libraries:

  • ReLinker to work around some versions of Android that have unreliable PackageManager implementations.
  • Device Year Class to optimize the low-resolution render strategy based on device specs and performance.

Nightly Builds

Nightly builds are shipped as zip files containing the PSPDFKit aar file and can be integrated using the manual library integration guide above. You can download the nightly zip file using the download link you received from the PSPDFKit customer support team.

Note: Nightly builds represent our current development snapshot (similar to Maven SNAPSHOT releases). They are primarily used during customer support to let you verify if a feature or bug fix is working as intended. Although nightly builds should be stable, they haven’t undergone the same quality control process of stable releases and are thus not meant for production apps. If you don’t have a nightly download link, don’t worry, since this is usually not required.

ProGuard

There is no need to specify additional ProGuard rules since PSPDFKit uses consumersProguardFiles to keep from obfuscating everything it requires. If you want to check out the rules, you should take a look into proguard.txt, which is located inside PSPDFKit aar:

1
2
3
    cd [YOUR_AAR_LOCATION]
    unzip [YOUR_AAR_NAME].aar -d aar-contents
    cat aar-contents/proguard.txt

Troubleshooting

If you’re getting java.lang.NoClassDefFoundError inside com.android.internal.os.ZygoteInit.main, this usually means the native library couldn’t be loaded. A common reason for this is either an invalid or too aggressive ProGuard configuration, or stale caches. Clean all intermediate build files (in Android Studio: Build > Clean Project) and rebuild your app to determine whether or not this is the case.