2

I am getting a strange error when trying to integrate with PDFTron i.e PDFNet Android SDK:

UnsatisfiedLinkError: Couldn't load PDFNetC: findLibrary returned null. Expected armv7a, found cpu_info: abi: armeabi-v7a

I have already checked this link.

Most likely the native library provided by PDFNet Android SDK is not included in my project correctly. Inside the lib folder I the downloaded package, there are native libraries and java library that both need to be included to my project.

Created a folder called jniLibs in main folder and place all .so (with corresponding folder structure) inside the jniLibs folder, i.e.:

enter image description here

This will allow Android Studio to automatically recognize the native library path.

I also specified product flavor to filter which .so to use, such as:

productFlavors {
    armv7a {
        ndk {
            abiFilters "armeabi-v7a"
        }
    }
    arm {
        ndk {
            abiFilters "armeabi"
        }
    }
    x86 {
        ndk {
            abiFilters "x86"
        }
    }
    armv8 {
        ndk {
            abiFilters "arm64-v8a"
        }
    }
    x86_64 {
        ndk {
            abiFilters "x86_64"
        }
    }
    fat {
        ndk {
            abiFilters "armeabi-v7a", "armeabi", "arm64-v8a", "x86", "x86_64"
        }
    }
}

Then I specified the jniLibs directory inside build.gradle file of your project, i.e.:

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        res.srcDirs = ['res']
        jniLibs.srcDirs = ['libs']
        svg.srcDir 'src/main/svg'
    }
}
Community
  • 1
  • 1
Maveňツ
  • 1
  • 12
  • 50
  • 89
  • 1
    I used this library in my project. I copied libPDFNetC.so file in "jni/libs/armeabi" folder and in .mk file "include $(CLEAR_VARS) LOCAL_MODULE := libPDFNetC # this libs path is relative to my jni files, so, src/main/jni/libs/libPrecompiledLib.a LOCAL_SRC_FILES := libs/armeabi/libPDFNetC.so include $(PREBUILT_SHARED_LIBRARY)" wrote this. It works properly in my project. – Kush Patel Dec 23 '16 at 06:14
  • @KushPatel can you post answer with proper explaination? – Maveňツ Dec 23 '16 at 06:23
  • @MaňishYadav done. I think it should work – Kush Patel Dec 23 '16 at 06:28
  • If you are using standard jniLib structure (i.e. jniLibs in main as shown in your first screenshot), you don't need to specify it in sourceSets anymore. The one in sourceSets is conflicting with the standard structure. See https://groups.google.com/forum/?fromgroups#!topicsearchin/pdfnet-sdk/android$20AND$20author$3Asgong@pdftron.com/pdfnet-sdk/0t_3-pN5jG4 – Shirley G Dec 23 '16 at 18:52

2 Answers2

1

Import PDFTron Library Project in Android Studio. Use that Library Project in your application.For this use compile project(':libraries:PDFViewCtrlTools') in your application's build.gradle.

Now copy libPDFNetC.so file to "jni/libs/armeabi" folder in your application.

in your application.mk write this.

APP_ABI := armeabi-v7a
APP_CPPFLAGS += -std=c++11 -exception
APP_STL := gnustl_shared
APP_PLATFORM=android-19
APP_OPTIM := debug
NDK_TOOLCHAIN_VERSION := 4.8

in your Android.mk file add this

include $(CLEAR_VARS)
LOCAL_MODULE    := libPDFNetC
# this libs path is relative to my jni files, so, src/main/jni/libs/libPrecompiledLib.a
LOCAL_SRC_FILES := libs/armeabi/libPDFNetC.so
include $(PREBUILT_SHARED_LIBRARY)

Edit:

PDFDoc doc = PDFDoc(InputStream var1)

may be by using this method you can open PDF from url.

Code:

PDFViewCtrl mPDFViewCtrl = (PDFViewCtrl) view.findViewById(R.id.pdfViewer);
PDFDoc doc = new PDFDoc(filePath);
mPDFViewCtrl.setDoc(doc);

xml

<pdftron.PDF.PDFViewCtrl
    android:id="@+id/pdfViewer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical|horizontal"
    android:visibility="gone"/>
Maveňツ
  • 1
  • 12
  • 50
  • 89
Kush Patel
  • 1,228
  • 1
  • 13
  • 34
1

If you are using standard jniLib structure (i.e. jniLibs in main as shown in your first screenshot), you don't need to specify it in sourceSets anymore. jniLibs.srcDirs = ['libs'] in sourceSets is conflicting with the standard structure (jniLibs).

See https://groups.google.com/forum/?fromgroups#!topicsearchin/pdfnet-sdk/android$20AND$20author$3Asgong@pdftron.com/pdfnet-sdk/0t_3-pN5jG4

Shirley G
  • 352
  • 2
  • 9