Creating a new project
Open Android Studio and select File > New > New Project… to create a new project for your application:
-
Choose the correct template for your project. In this example, you’ll use Empty Views Activity:
-
When prompted, choose your app name (Nutrient Demo) and set the Save location, Language, and Minimum SDK of your choice:
-
Click Finish to save the project to your default project location.
Adding Nutrient to your project
-
In the
settings.gradle.kts
file at the root of your project, add the Nutrient Maven repository:
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url = uri("https://my.nutrient.io/maven") } } }
-
In your
app/build.gradle.kts
file, add the Nutrient dependency:
dependencies {
implementation("com.pspdfkit:pspdfkit:2024.8.1")
}
Configuring your build
Nutrient is supported on Android devices running API level 21 and newer and targeting the latest stable Android API version (API 35). Furthermore, Nutrient requires apps to enable, at minimum, Java 8 language features to build — though we recommend the default 17.
Inside your app/build.gradle.kts
file, make sure to have the following configuration:
android { compileSdk = 35 defaultConfig { applicationId = "com.example.app" minSdk = 21 targetSdk = 35 } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = "17" } }
With
minSdk
set to21
, your app is available on more than 98.6 percent of devices on the Google Play Store (last update: October 2023).
Displaying a PDF
To verify Nutrient was successfully integrated into your app, try opening a PDF file with the ready-to-use PdfActivity
:
-
Copy a PDF document into the assets directory of your Android project — for example, to
src/main/assets/my-document.pdf
. -
Add
PdfActivity
to your app’sAndroidManifest.xml
:
<application> ... <activity android:name="com.pspdfkit.ui.PdfActivity" android:windowSoftInputMode="adjustNothing" /> </application>
-
You can now start
PdfActivity
with the document from your assets directory:
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContentView(R.layout.activity_main) ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) insets } val uri = Uri.parse("file:///android_asset/my-document.pdf") val config = PdfActivityConfiguration.Builder(this).build() PdfActivity.showDocument(this, uri, config) } }
-
PdfActivity
will now present the document from your assets directory.
Note that the
android_assets
folder is read-only and is used as a simple example. For actual usage, you might want to copy the file to a local folder first for full read and write privileges. You can read more about this in our guide on opening PDFs from URLs and in Google’s Data and file storage overview.