Jolzal
Jolzal

Reputation: 597

flutter pdf viewer Native libraries failed to load

Hello so i was using this package to show pdf in my app pub.dev/packages/flutter_full_pdf_viewer and pdf package pub.dev/packages/pdf to create the pdf.

This is the code i use to create the pdf and navigate to pdf viewer page :

Future<Uint8List> generateInvoice(
    PdfPageFormat pageFormat, SalesOrder salesOrder) async {
  final lorem = pw.LoremText();
  final invoice = Invoice(
    salesOrder: salesOrder,
    orders: salesOrder.listOrder.where((e)=>e.status==0).toList(),
    paymentInfo:
        '4509 Wiseman Street\nKnoxville, Tennessee(TN), 37929\n865-372-0425',
    baseColor: PdfColors.blueGrey800,
    accentColor: PdfColors.blueAccent700,
  );
  return await invoice.buildPdf(pageFormat);
}

createInvoice(SalesOrder salesOrder) async {
    var a = await DownloadsPathProvider.downloadsDirectory;
    print("path  = "+a.path);
    final String dir = "/storage/emulated/0/Download";
    final String path = '$dir/example.pdf';
    final File file = File(path);
    Uint8List invoice = await ig.generateInvoice(PdfPageFormat.a4, salesOrder);
    await file.writeAsBytes(invoice);
    Navigator.of(context)
        .push(MaterialPageRoute(builder: (context) => PdfScreen(path: path)));
 }

This is my pdf viewer screen

class PdfScreen extends StatelessWidget {
  final String path;
  PdfScreen({this.path});

  @override
  Widget build(BuildContext context) {
    print(path);
    return PDFViewerScaffold(path: path);
  }
}

this is my build gradle :

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }


    buildTypes {
        release {
            signingConfig signingConfigs.debug
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            ndk {
                abiFilters 'armeabi-v7a'
            }
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
}

it was working fine sometime but after a lot of changed in the app whenever i open the pdf viewer screen always become white, and this error come up :

E/com.shockwave.pdfium.PdfiumCore(32664): Native libraries failed to load - java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.test-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.test-2/lib/arm64, /data/app/com.example.test-2/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libmodpng.so"
    E/art     (32664): No implementation found for long com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(int, java.lang.String) (tried Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument and Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2)
E/PDFView (32664): load pdf error
E/PDFView (32664): java.lang.UnsatisfiedLinkError: No implementation found for long com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(int, java.lang.String) (tried Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument and Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2)

Thankyou so much

Upvotes: 1

Views: 1352

Answers (1)

Jolzal
Jolzal

Reputation: 597

I am not sure about why this is happening, but i resolve it by cleaning the flutter project. Thankyou

Upvotes: 1

Related Questions