如何解决flutter pdf 查看器本机库无法加载
你好,所以我使用这个包在我的应用程序 pub.dev/packages/flutter_full_pdf_viewer 和 pdf 包 pub.dev/packages/pdf 中显示 pdf 来创建 pdf。
这是我用来创建 pdf 并导航到 pdf 查看器页面的代码:
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)));
}
这是我的 pdf 查看器屏幕
class PdfScreen extends StatelessWidget {
final String path;
PdfScreen({this.path});
@override
Widget build(BuildContext context) {
print(path);
return PDFViewerScaffold(path: path);
}
}
这是我的构建 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'
}
它有时工作正常,但在应用程序中进行了大量更改后,每当我打开 pdf 查看器屏幕时总是会变白,并且出现此错误:
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)
非常感谢
解决方法
我不确定为什么会发生这种情况,但我通过清理 flutter 项目解决了这个问题。谢谢你
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。