Java Question Help wrapper library

victormedranop

Well-Known Member
Licensed User
Longtime User
hi, I am making another printer library for Xpay 702 android 4.4.4. I already made 701 and its working but in this release the maker of the hardware do not include the lib. so, so I need to load in the library. but its not working. I am uploading the zip eclipse project. is some one have some time to take a look,
thanks.

this is the erro output unfiltered :->
Error loading printer library
Couldn't load libserial_port from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/b4a.example-1.apk"],nativeLibraryDirectories=[/data/app-lib/b4a.example-1, /vendor/lib, /system/lib]]]: findLibrary returned null

Victor
 

Attachments

  • XprinterLib.zip
    361.9 KB · Views: 365
Last edited:

DonManfred

Expert
Licensed User
Longtime User

victormedranop

Well-Known Member
Licensed User
Longtime User
Thanks, for your answer but I try that with same result.

java.lang.UnsatisfiedLinkError: Couldn't load libserial_port from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/net.nowyouseeme.newprinter-2.apk"],nativeLibraryDirectories=[/data/app-lib/net.nowyouseeme.newprinter-2, /vendor/lib, /system/lib]]]: findLibrary returned null

upload_2018-4-19_12-10-13.png



unfiltered logs

Trying to load lib libjavacore.so 0x0
Added shared lib libjavacore.so 0x0
Trying to load lib libnativehelper.so 0x0
Added shared lib libnativehelper.so 0x0
No JNI_OnLoad found in libnativehelper.so 0x0, skipping init
Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods
Calling main entry com.android.commands.pm.Pm
No content provider found for permission revoke: file:///data/local/tmp/PrinterTest.apk
No content provider found for permission revoke: file:///data/local/tmp/PrinterTest.apk
Copying native libraries to /data/app-lib/vmdl-1293422886
Force stopping net.nowyouseeme.newprinter appid=10086 user=-1: uninstall pkg
Killing 9008:net.nowyouseeme.newprinter/u0a86 (adj 9): stop net.nowyouseeme.newprinter
Scheduling restart of crashed service net.nowyouseeme.newprinter/.starter in 1000ms
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@424c3ce0 attribute=null, token = android.os.BinderProxy@4216b708
WIN DEATH: Window{420553d8 u0 net.nowyouseeme.newprinter/net.nowyouseeme.newprinter.main}
Package net.nowyouseeme.newprinter codePath changed from /data/app/net.nowyouseeme.newprinter-2.apk to /data/app/net.nowyouseeme.newprinter-1.apk; Retaining data and using new
Read Node State Ok
Read Node State Ok
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Update ...

Trying to load lib /data/app-lib/net.nowyouseeme.newprinter-1/libserial_port.so 0x41f5ae80
libserial_port.so has text relocations. This is wasting memory and is a security risk. Please fix.
Added shared lib /data/app-lib/net.nowyouseeme.newprinter-1/libserial_port.so 0x41f5ae80

with this structure works, must have additional and lib together.

upload_2018-4-19_14-1-57.png


Victor
 

victormedranop

Well-Known Member
Licensed User
Longtime User
At this time. I can load so file with no problems.
but for some reason I still can connect to the printer port.

no error generated.

I use simple compiler library, I will try with eclipse so made the jar and tested.

if any super java guru is available, please check my code.

thanks,

Victor
 

DonManfred

Expert
Licensed User
Longtime User
i´m using eclipse too. But just for syntax help. I do compile with SLC (using a custom tool configured in Eclipse).

The Attached compilation is made with SLC.

The Eclipse zip shows you how the files must be organized.
 

Attachments

  • XPrinterEclipse.zip
    316.8 KB · Views: 358
  • XPrinterV118.37.zip
    18 KB · Views: 342

victormedranop

Well-Known Member
Licensed User
Longtime User
Still not working. I made an example in kotlin and works.
I found why is not working but I don't know how to solve.

the problem is in this function.

the library need info from de activity. but I really don't know how to.

I will post the kotlin code . if any one can help will be appreciated.


B4X:
private fun initListener() {
    printer!!.setDataListener(DataListener { data ->
        Toast.makeText(this@MainActivity, data.toString(), Toast.LENGTH_SHORT).show()
        //textView.setText(new BigInteger(1,data).toString(16).trim());
        //textView.text = data.toString()
    })
}

this is in Java.

B4X:
package com.example.printtest;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.math.BigInteger;
   import android_serialport_api.Printer;
   import android_serialport_api.Printer.DataListener;

public class MainActivity extends Activity implements OnClickListener{

   private Button openPrinter;
   private Button closePrinter;
   private Button queState;
   private Button setAlignType;
   private Button setLeftMargin;
   private Button setRigthMargin;
   private Button setLineSpecingByDotPitch;
   private Button setPrintOrientation;
   private Button setBold;
   private Button printLF;
   private Button feedPaper;
   private Button printString;
   private Button printEAN13;
   private Button printQR;
   private Button printPicture;
   private Button resetPrint;
   private TextView textView;
   private Printer printer;
   private Bitmap bitmap;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      printer =  new Printer(this);
      Log.i("Printer", "Printer init");
      Toast.makeText(this,"Printer init",Toast.LENGTH_LONG).show();
      initView();
      initListener();
   }

   private void initListener() {
      printer.setDataListener(new DataListener() {
         @Override
         public void onDataReceived(byte[] data) {
            Toast.makeText(MainActivity.this, data.toString(), Toast.LENGTH_SHORT).show();
            //textView.setText(new BigInteger(1,data).toString(16).trim());
            textView.setText(data.toString());
         }
      });
   }

   private void initView() {

         bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo3);
         textView = (TextView) findViewById(R.id.textView);
         openPrinter = (Button) findViewById(R.id.openPrinter);
         closePrinter = (Button) findViewById(R.id.closePrinter);
         queState = (Button) findViewById(R.id.queState);
         setAlignType = (Button) findViewById(R.id.setAlignType);
         setLeftMargin = (Button) findViewById(R.id.setLeftMargin);
         setRigthMargin = (Button) findViewById(R.id.setRigthMargin);
         setLineSpecingByDotPitch = (Button) findViewById(R.id.setLineSpecingByDotPitch);
         setPrintOrientation = (Button) findViewById(R.id.setPrintOrientation);
         setBold = (Button) findViewById(R.id.setBold);
         printLF = (Button) findViewById(R.id.printLF);
         feedPaper = (Button) findViewById(R.id.feedPaper);
         printString = (Button) findViewById(R.id.printString);
         printEAN13 = (Button) findViewById(R.id.printEAN13);
         printQR = (Button) findViewById(R.id.printQR);
         printPicture = (Button) findViewById(R.id.printPicture);
         resetPrint = (Button) findViewById(R.id.resetPrint);
        
         openPrinter.setOnClickListener(this);
         closePrinter.setOnClickListener(this);
         queState.setOnClickListener(this);
         setAlignType.setOnClickListener(this);
         setLeftMargin.setOnClickListener(this);
         setRigthMargin.setOnClickListener(this);
         setLineSpecingByDotPitch.setOnClickListener(this);
         setPrintOrientation.setOnClickListener(this);
         setBold.setOnClickListener(this);
         printLF.setOnClickListener(this);
         feedPaper.setOnClickListener(this);
         printString.setOnClickListener(this);
         printLF.setOnClickListener(this);
         printEAN13.setOnClickListener(this);
         printQR.setOnClickListener(this);
         printPicture.setOnClickListener(this);
         resetPrint.setOnClickListener(this);

   }

   @Override
   public void onClick(View v) {
      switch(v.getId()){
     
      //OK
      case R.id.openPrinter:
         printer.openPrinter();
         break;
      //OK
      case R.id.closePrinter:
         printer.closePrinter();
         break;
      //OK
      case R.id.queState:
         printer.queState();
         break;
      //OK
      case R.id.setAlignType:
         printer.setAlignType(1);
         break;
      case R.id.setLeftMargin:
         printer.setLeftMargin(20);
         break;
      case R.id.setRigthMargin:
         printer.setRigthMargin(20);
         break;
      case R.id.setLineSpecingByDotPitch:
         printer.setLineSpacingByDotPitch(50);
         break;
      case R.id.setPrintOrientation:
         printer.setStringZoomIn(2);
         //printer.setPrintOrientation();
         break;
      //OK
      case R.id.setBold:
         printer.setBold(1);
         //printer.cancelBold();
         break;
      //OK
      case R.id.feedPaper:
         printer.feedPaper();
         break;
      //OK
      case R.id.printLF:
         printer.printLF(100);
         break;
      case R.id.printEAN13:
         printer.printEAN13("111111111111");
         break;
      //OK
      case R.id.printQR:
         printer.printQR("www.google.com",8);
         break;
      //OK
      case R.id.printString:
         printer.printString("Hello World");
         break;
      //OK
      case R.id.printPicture:
         printer.PrintPicture(bitmap);
         break;
      //OK
      case R.id.resetPrint:
         printer.resetPrint();
         break;
      }
   }

}
 

Attachments

  • KotlinPrinter.zip
    178.1 KB · Views: 355

victormedranop

Well-Known Member
Licensed User
Longtime User
no matter what I do, still getting "java.lang.NoClassDefFoundError: android_serialport_api.Printer"
uffffff
 

victormedranop

Well-Known Member
Licensed User
Longtime User
yes, using this. I posted las changes on libs. Printer.jar is the file that provide access to .so

B4X:
@Version(118.65f)
@ShortName("Xprinter")
@Author("Victor Medrano")
@ActivityObject
@DontInheritEvents
@DependsOn(values={"Printer"})

thanks.

Victor
 

Attachments

  • xprinter.zip
    318.5 KB · Views: 334

victormedranop

Well-Known Member
Licensed User
Longtime User
I am Still working on this. my problem is that I made a custom apps for an specific device XPAY 701, the have been an upgrade to XPAY 702 diferentes driver on printer.
my libs it's some kind working. I have an error with the original java example, same with my lib. I will continue working.

thanks all comments.

victor

B4X:
package net.nowyouseeme;
import android.content.Context;
import android.graphics.Bitmap;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;
import android_serialport_api.*;
import android_serialport_api.Printer.DataListener;
@Version(0.40f)
@ShortName("xpfprinter")
@Author("Victor Medrano")
//@ActivityObject
@DependsOn(values={"Printer"})
public class xprinter {
 private static Printer printer;
 private Bitmap bitmap;
 private BA ba;
 public static final String LOG_TAG = xprinter.class.getName();
 private static String _IS_LIB_LOADED = "false";
    
// public static void main(String[] args) {
 static {
  printer =  new Printer(BA.applicationContext.getBaseContext());
  BA.Log("Printer init");
  try { 
   System.loadLibrary("serial_port");
      _IS_LIB_LOADED = "true";
      BA.Log(LOG_TAG + " Printer library loaded");
      initListener();
  }catch (UnsatisfiedLinkError | Exception e) {
        e.printStackTrace();
           BA.Log(LOG_TAG + " Error loading printer library");
           BA.Log(LOG_TAG + " "  + e.getMessage());
           _IS_LIB_LOADED = "false";
     }
  BA.Log(LOG_TAG + " " +  _IS_LIB_LOADED);
  }
 
 
 private static void initListener() {
  printer.setDataListener(new DataListener() {
   @Override
   public void onDataReceived(byte[] data) {
    BA.Log(LOG_TAG + " data listener " +  data.toString());
   }
  });
 } 
 
 public void onClick(Context context) {
  BA.Log(LOG_TAG+" Context "+context.toString());
 }
 
 public int openPrinter(){
  onClick(BA.applicationContext.getBaseContext());
  int result = printer.openPrinter();
  return result;
 }
 
 public int closePrinter(){
  onClick(BA.applicationContext.getBaseContext());
  int result = printer.closePrinter();
  return result;
 }
 
 public int startPrinting(String data){
  onClick(BA.applicationContext.getBaseContext());
  int result = printer.printString(data);
  return result;
 }
 
 public int lineFeed(int size){
  onClick(BA.applicationContext.getBaseContext());
  int result = printer.printLF(size);
  return result;
 }
 public int Feed(int size){
  onClick(BA.applicationContext.getBaseContext());
  int result = printer.feedPaper();
  return result;
 }
 
 public void resetPrinter(){
  onClick(BA.applicationContext.getBaseContext());
  printer.resetPrint();
 }
 
 public void printEAN13(String data){
  onClick(BA.applicationContext.getBaseContext());
  printer.printEAN13(data);
 }
 public void printQR(String data,int size){
  onClick(BA.applicationContext.getBaseContext());
  printer.printQR(data, size);
 }
/*
 
 int queState();
 int setAlignType(int type);
 int setLeftMargin(int dis);
 int setRigthMargin(int dis);
 int setLineSpecingByDotPitch(int s);
 int setPrintOrientation();
 int setBold();
 int printEAN13(String txt);
 int printQR(String txt);
 int PrintPicture(Bitmap bit);
 
*/
 
}
 
Top