Android Question PdfViewer Error if targetSdkVersion="26"

MarcoRome

Expert
Licensed User
Longtime User
Hi all. if i try this code with targetSdkVersion = 19 work without problem

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim pdf As PDFViewer
  Dim i,pc As Int=0
  Dim iv
  Dim rp As RuntimePermissions
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    
    
    If Not(rp.Check(rp.PERMISSION_WRITE_EXTERNAL_STORAGE))Then
        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Else
        'gmap.MyLocationEnabled = Result
        Log("Permssi accordati")
        Log("CopyFile()")
        If Not(File.Exists(File.DirRootExternal, "test.pdf")) Then
            Log("test.pdf does not exist at DirRootExternal")
        
            File.Copy(File.DirAssets, "test.pdf", File.DirRootExternal, "test.pdf")
            Log("test.pdf copied")
        End If
        pdf.init
        Activity.AddView(pdf,0,0,-1,-1)

        pdf.getpdf2(File.Combine(File.DirRootExternal,"test.pdf"),"")

    End If
    
    
End Sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = rp.PERMISSION_WRITE_EXTERNAL_STORAGE Then
        'gmap.MyLocationEnabled = Result
        Log("Permssi accordati")
        Log("CopyFile()")
        If Not(File.Exists(File.DirRootExternal, "test.pdf")) Then
            Log("test.pdf does not exist at DirRootExternal")
        
            File.Copy(File.DirAssets, "test.pdf", File.DirRootExternal, "test.pdf")
            Log("test.pdf copied")
        End If
        pdf.init
        Activity.AddView(pdf,0,0,-1,-1)

        pdf.getpdf2(File.Combine(File.DirRootExternal,"test.pdf"),"")

    End If
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

if i have targetSdkVersion="26" i have this error:

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Permssi accordati
CopyFile()
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/b4a.example.pdfviewer2-xL41jgevqM2C35EorzE7CQ==/lib/arm/libpdfview2.so" has text relocations
at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
at java.lang.System.loadLibrary(System.java:1657)
at de.donmanfred.pdfviewerwrapper.init(pdfviewerwrapper.java:104)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:778)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:358)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.pdfviewer2.main.afterFirstLayout(main.java:104)
at b4a.example.pdfviewer2.main.access$000(main.java:17)
at b4a.example.pdfviewer2.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
** Activity (main) Resume **
An error occurred:
(Line: 49) Activity.AddView(pdf,0,0,-1,-1)
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean

Any idea ?
HERE ( https://www.dropbox.com/s/9e2w4ukzsxk8uoz/libPDFViewer.zip?dl=0 ) example project
Thank you
Marco
 

DonManfred

Expert
Licensed User
Longtime User
seems like there is no .so file for the Architecture of your device (arm)

/lib/arm/libpdfview2.so
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
seems like there is no .so file for the Architecture of your device (arm)
Hi dear Don. The device is Samsung S7 Edge Android 8.
N.B If i use targetsdk = 19 into same device work without problem.
I think the error is related to targetsdk. But I can not understand what:
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/b4a.example.pdfviewer2-xL41jgevqM2C35EorzE7CQ==/lib/arm/libpdfview2.so" has text relocations
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Read this @MarcoRome, I'm presuming that you are creating a PDF file and then trying to preview using one of the apps on your device from within your app.

https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/#content

EDIT:
OR
save your PDF file into a 'SafeDirectoty' then try this code.
B4X:
'Code mostly from memory, not tested but should work for you, hopefully.
        Dim Intent1 As Intent
            Intent1.Initialize(Intent1.ACTION_VIEW, "file://" & File.Combine(Starter.SafeDirectoty, "test.pdf"))
            Intent1.SetType("application/pdf")
            Intent1.WrapAsIntentChooser("Open PDF document using:")
        StartActivity(Intent1)

Enjoy...
 
Last edited:
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Read this @MarcoRome, I'm presuming that you are creating a PDF file and then trying to preview using one of the apps on your device from within your app.

https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/#content

EDIT:
OR
save your PDF file into a 'SafeDirectoty' then try this code.
B4X:
'Code mostly from memory, not tested but should work for you, hopefully.
        Dim Intent1 As Intent
            Intent1.Initialize(Intent1.ACTION_VIEW, "file://" & File.Combine(Starter.SafeDirectoty, "test.pdf"))
            Intent1.SetType("application/pdf")
            Intent1.WrapAsIntentChooser("Open PDF document using:")
        StartActivity(Intent1)

Enjoy...

No, isnt my situation. I dont use an intent. I use the pdfView application to view the file.
Example with PdfRender by @DonManfred work without problem.
I think that the problem is here:
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/b4a.example.pdfviewer2-xL41jgevqM2C35EorzE7CQ==/lib/arm/libpdfview2.so" has text relocations
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
This will not work. You can only share an intent with FileProvider class.

You need to find a newer version of the native library.

Yes Agree. So the current PdfView library will not run from version 24 or >
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Erel we need your help
1. This is a community forum. Do not limit your questions to a single member!
2. You never should post a question/wish to an existing thread. Always create a new thread for any issue/question you have
3. Your wish should be posted in the wish forum or alternatively you can create a offer in the Jobforum.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/b4a.example.pdfviewer2-xL41jgevqM2C35EorzE7CQ==/lib/arm/libpdfview2.so" has text relocations

The native library needs to be recompiled.
 
Upvote 0
Top