Integrating the Bixolon SDK into a Flutter project

If you are reading this I am going to assume that you are currently dealing with the many annoyances that come when trying to work with Bixolons in a developer environment, which I to have encountered. Poor documentation, strange apk behavior, and misleading information online may all sound familiar. I am going to break down the issues I have faced and how I was able to resolve them.
The Basics
Bixolon provides a native SDK for ios, android, and web respectively. They also make different types of printers such as Point of Sale (POS), Mobile, and label printers. These each also have different SDKs for them. The best way to find the SDK you need would be the following:
- On your printer, locate the device name on the bottom or side. It may look something like “SRP-350plusIII”
- Navigate to the Bixolon website and find the downloads page. Once here enter the name of the device that you are going to be writing code for.
- Scroll down and find the SDK section of the downloads. Select what platform you plan on using, and download the zip file. For my project I needed to use the android SDK. It’s important to note that with flutter, you will have to download and support each separate SDK if you plan on running your application on multiple device types.
- Unzip the file.
How to use the SDK
There will be a pdf inside the unzipped folder with instructions on how to get the SDK set up, and this seems to work if you use Eclipse like they do in the guide. I initially followed these same steps recreated in Flutter and was not able to find success, so here is how I got the SDK to work.
Flutter Method Channels
Flutter is built on top of the Dart language. The Bixolon SDK is not written in Dart, but Flutter has a neat feature called Method Channels that allow us to integrate native code. This link does a great job explaining how they work and the basics for getting started: Writing custom platform-specific code
You will be able to follow the steps in that article to set up your basic communication between the dart code and native code. I will be looking at incorporating the android SDK that uses java.
Adding an SDK to android section
Inside of the Bixolon folder that was downloaded earlier, there will be a libs folder that contains everything you need to start using the Bixolon. In your android app section of your project, there may be a libs folder. If not, create one. In this folder you are going to add the bixolon_printer_V???.jar file, jniLibs folder, and the libcommon_V???.jar folder that was included in the Bixolon download. After pasting these in, right click the jar files and select “add as library”. You should be able to keep the default path that is given. You do not need to do this step for the jniLibs folder.
Navigate to app/src/main and paste the jniLibs folder inside of this directory as well. Next, we will look into modifying the project attributes to finish allowing access to the SDK
AndroidManifest.xml
If you plan on connecting to your Bixolon printer via bluetooth, you will have to add the following lines before the application section:
<uses-permission android:name=”android.permission.BLUETOOTH”android:maxSdkVersion=”30" /><uses-permission android:name=”android.permission.BLUETOOTH_ADMIN”android:maxSdkVersion=”30" /><uses-permission android:name=”android.permission.BLUETOOTH_SCAN” /><uses-permission android:name=”android.permission.BLUETOOTH_ADVERTISE” /><uses-permission android:name=”android.permission.BLUETOOTH_CONNECT” /><uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION”/>
build.gradle (app/build.gradle)
I needed to run my code on a modern android tablet, which required me to add an abiFilter in the defaultConfig section.
ndk { abiFilters 'armeabi-v7a'}
If you run into apk problems after this, try rebuilding the apk’s. This can be done through the command line or by pressing Build->Flutter->Build APK in the top menu bar.
You will also have to include the dependencies that we added earlier. At the bottom of your file, add the following lines if not already present:
dependencies {implementation fileTree(dir: ‘libs’, include: [‘*.jar’, ‘*.so’])implementation files(‘libs/bixolon_printer_V2.1.6.jar’)implementation files(‘libs/libcommon_V1.1.6.jar’)}
Ensure the previous changes were done in the app level build.gradle. The android level should not need to be modified.
Testing and Running
Navigate back to the Bixolon SDK manual that was included in the zip file downloaded earlier. Find a basic activity, such as a print text. You may find it towards the bottom of the pdf, but if not search for it. We can use this code to set up the Bixolon.