Skip to content

[Feat|Android] Support for embedding v2 #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dart_tool/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.2
3.32.0
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.0.1-45 - Jun 10, 2025
- Update Android to embedding v2

# 1.0.1-44 - May 28, 2025
- Update Android to v11.5.0

Expand Down
30 changes: 9 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,44 +80,32 @@ The following instructions are only applicable to Android development; click her
```diff
defaultConfig {
applicationId "com.example.myapp"
- minSdkVersion flutter.minSdkVersion
+ minSdkVersion 21
+ multiDexEnabled true
+ manifestPlaceholders += [pdftronLicenseKey:PDFTRON_LICENSE_KEY]
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

+ resValue("string", "PDFTRON_LICENSE_KEY", "\"LICENSE_KEY_GOES_HERE\"")
}
```

5. In your `myapp/android/gradle.properties` file, add the following line:
``` diff
# Add the PDFTRON_LICENSE_KEY variable here.
# For trial purposes leave it blank.
# For production add a valid commercial license key.
PDFTRON_LICENSE_KEY=
```

6. In your `myapp/android/app/src/main/AndroidManifest.xml` file, add the following lines:
5. In your `myapp/android/app/src/main/AndroidManifest.xml` file, add the following lines:
```diff
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">

<!-- Required if you want to work with online documents -->
+ <uses-permission android:name="android.permission.INTERNET" />
<!-- Required to read and write documents from device storage -->
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required if you want to record audio annotations -->
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
...
+ android:largeHeap="true"
+ android:usesCleartextTraffic="true">
+ android:largeHeap="true">

<!-- Add license key in meta-data tag here. This should be inside the application tag. -->
+ <meta-data
+ android:name="pdftron_license_key"
+ android:value="${pdftronLicenseKey}"/>
+ android:value="@string/PDFTRON_LICENSE_KEY" />
...
```

Expand All @@ -135,9 +123,9 @@ The following instructions are only applicable to Android development; click her
}
```

7. Follow the instructions outlined [in the Usage section](#usage).
8. Check that your Android device is running by running the command `flutter devices`. If none are available, follow the device set up instructions in the [Install](https://flutter.io/docs/get-started/install) guides for your platform.
9. Run the app with the command `flutter run`.
6. Follow the instructions outlined [in the Usage section](#usage).
7. Check that your Android device is running by running the command `flutter devices`. If none are available, follow the device set up instructions in the [Install](https://flutter.io/docs/get-started/install) guides for your platform.
8. Run the app with the command `flutter run`.

### iOS

Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.pdftron.pdftronflutter'
version '2.0'
version '3.0.0'

buildscript {
repositories {
Expand All @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.android.tools.build:gradle:8.0.2'
}
}

Expand All @@ -30,7 +30,7 @@ android {
compileSdk 34

defaultConfig {
minSdkVersion 19
minSdk = 21
vectorDrawables.useSupportLibrary = true
}
lintOptions {
Expand Down
4 changes: 4 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

<application>

<meta-data
android:name="flutterEmbedding"
android:value="2" />

<!-- Document viewer activity declaration-->
<activity
android:name=".FlutterDocumentActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.pdftron.pdftronflutter;

import android.content.Context;

import com.pdftron.pdftronflutter.factories.DocumentViewFactory;
import com.pdftron.pdftronflutter.helpers.PluginMethodCallHandler;

Expand All @@ -10,7 +8,6 @@
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.platform.PlatformViewRegistry;

/**
Expand All @@ -24,7 +21,8 @@ public class PdftronFlutterPlugin implements FlutterPlugin, ActivityAware {
private BinaryMessenger mMessenger;
private MethodChannel mMethodChannel;

public PdftronFlutterPlugin() { }
public PdftronFlutterPlugin() {
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
Expand All @@ -47,25 +45,15 @@ public void onAttachedToActivity(ActivityPluginBinding binding) {
}

@Override
public void onDetachedFromActivityForConfigChanges() { }
public void onDetachedFromActivityForConfigChanges() {
}

@Override
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) {
mRegistry.registerViewFactory(viewTypeId, new DocumentViewFactory(mMessenger, binding.getActivity()));
}

@Override
public void onDetachedFromActivity() { }

/**
* Plugin registration using Android embedding v1.
*/
public static void registerWith(Registrar registrar) {
final MethodChannel methodChannel = new MethodChannel(registrar.messenger(), "pdftron_flutter");
methodChannel.setMethodCallHandler(new PluginMethodCallHandler(registrar.messenger(), registrar.activeContext()));
registrar
.platformViewRegistry()
.registerViewFactory(viewTypeId,
new DocumentViewFactory(registrar.messenger(), registrar.activeContext()));
public void onDetachedFromActivity() {
}
}
67 changes: 0 additions & 67 deletions example/android/app/build.gradle

This file was deleted.

46 changes: 46 additions & 0 deletions example/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
id("com.android.application")
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}

android {
namespace = "com.pdftron.pdftronflutterexample"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.pdftron.pdftronflutterexample"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName

resValue("string", "PDFTRON_LICENSE_KEY", "\"LICENSE_KEY_GOES_HERE\"")
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
}
}
}

flutter {
source = "../.."
}
7 changes: 7 additions & 0 deletions example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
38 changes: 21 additions & 17 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pdftron.pdftronflutterexample">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<!-- Required to read and write documents from device storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required if you want to record audio annotations -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
android:label="pdftron_flutter_example"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:largeHeap="true"
android:requestLegacyExternalStorage="true"
android:usesCleartextTraffic="true">
android:icon="@mipmap/ic_launcher">

<!-- Add license key in meta-data tag here. This should be inside the application tag. -->
<meta-data
android:name="pdftron_license_key"
android:value="${pdftronLicenseKey}" />
android:value="@string/PDFTRON_LICENSE_KEY" />

<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/PDFTronAppTheme"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustPan">
Expand All @@ -33,20 +28,29 @@
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />

</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.

In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pdftron.pdftronflutterexample

import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity : FlutterFragmentActivity()
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />

<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
Loading