Android Question Cannot get Wrapper Working - code provided

Krammig

Member
Licensed User
Longtime User
Hi,

I am trying to run an app with a third party library, specifically, Chilkat Email Library.

A couple of issues which I cannot seem to find the reason for and was hoping someone could spot what I cannot.

a)
I have built a Wrapper and created a Jar file from a Java file. Code listed below.

b)
I have created a B4A app, code listed below.

ISSUES ;

i)
if I do not have the third party library placed in the ?Files folder I get an error saying it is missing.
However if I place it in there, Chilkat libchilkat.so I see a message in the IDE saying that it is never used.
File libchilkat.co is not used. (Warning #15)

ii)
running the app, it seems to compile and displays input data on the phone. However immediately on pressing the Get button I see the following error.


B4X:
LogCat connected to: d3ae099
--------- beginning of system
--------- beginning of main
Copying updated assets files (2)
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/b4a.example-2/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]] couldn't find "libchilkat.so"
    at java.lang.Runtime.loadLibrary(Runtime.java:366)
    at java.lang.System.loadLibrary(System.java:988)
    at com.wrapper.email.popEmail.<init>(popEmail.java:22)
    at b4a.example.main._btnget_click(main.java:422)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:4785)
    at android.view.View$PerformClick.run(View.java:19888)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5273)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)

I have checkboxed the Library in the Library Manager.

I would greatly appreciate any assist / feedback / comments on this.

thanks



TEST APP CODE ....................

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

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

    'Dim email As popEmail
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.

   
    Private btnGet As Button
    Private address As EditText
    Private login As EditText
    Private password As EditText
    Private count As Int
   
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("llgetEmail")   
    address.Text = "banlogic@qq.com"
    login.Text = "3363507683"
    password.Text="1qaz2wsx"
   
    'Msgbox("Welcome to B4A!", "");
   
End Sub
Sub btnGet_click   
       
    Private email As PopEmail
    email.initialize
    email.login(address.Text, login.Text, password.Text)
    count=email.emailCount()
    If count=0 Then
        Msgbox("no emails found", "")
    Else
        Msgbox(count + "emails found", "")
    End If
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


WRAPPER CODE ..................

B4X:
package com.wrapper.email;

import com.chilkatsoft.CkEmailBundle;
import com.chilkatsoft.CkMailMan;

import anywheresoftware.b4a.BA.*;

/**
* Created by LGH on 2017/1/12.
*/
@Version(1.0f)
@Author("Nelson")
@ShortName("PopEmail")
@DontInheritEvents
public class popEmail {

    public String mailHost;
    public String userName;
    public String password;
   
    {
        System.loadLibrary("chilkat");
    }

    CkMailMan mailman;
    public popEmail(){
               
        mailman = new CkMailMan();
        boolean success = mailman.UnlockComponent("30-day trial");
        if (success != true) {
            System.out.println("Component unlock failed");
        }
    }
   
    public void initialize() {
        boolean success = mailman.UnlockComponent("30-day trial");
        if (success != true) {
            System.out.println("Component unlock failed");
            return;
        }
    };
  
    public boolean login(String host, String user, String pass){

        //  Any string argument automatically begins the 30-day trial.
       

        //  Set the POP3 server's hostname
        mailman.put_MailHost(host);

        //  Set the POP3 login/password.
        mailman.put_PopUsername(user);
        mailman.put_PopPassword(pass);
        return  true;
    }

    public int emailCount(){
        CkEmailBundle bundle;
        //  Copy the all email from the user's POP3 mailbox
        //  into a bundle object.  The email remains on the server.
        bundle = mailman.CopyMail();

        if (bundle == null ) {
            System.out.println(mailman.lastErrorText());
            return 0;
        }

        int count = bundle.get_MessageCount();
       
        return count;
//        if(bundle.get_MessageCount() > 0){
//            System.out.println(bundle.get_MessageCount() + " emails found");
//        }else{
//            System.out.println("no emails found");
//        }
//        int i;
//        CkEmail email;
//        for (i = 0; i <= bundle.get_MessageCount() - 1; i++) {
//            email = bundle.GetEmail(i);
//            System.out.println("From: " + email.ck_from());
//            System.out.println("Subject: " + email.subject());
//
//        }
    }

    public void close(){
        mailman.Pop3EndSession();
    }
}
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top