简体   繁体   中英

Printer method calls for a POS app behave differently for release and debug environment

I've been stuck with the problem for almost a week now. The issue that I am facing is that when I set the application in debug mode, the printer functions work well; they return the correct responses and the sample texts are printed from the thermal printer the POS has.

However, when I switch the app to release mode, things start to behave a little differently. To give you a picture of what is happening, here is the correct method calls and responses. You can see that the request that goes to the OS is correct and the return values are correct too.

09-06 21:22:04.058 357-357/? D/LibPrinterService: PrinterService getStatus...
09-06 21:22:04.072 357-357/? D/LibPrinterService: PrinterService getStatus,status=0
09-06 21:22:04.072 6412-6432/com.company.newpos D/PAYSDK: [+] Print Status: 0
09-06 21:22:04.072 357-466/? D/LibPrinterService: PrinterService getMaxTemperature...
09-06 21:22:04.074 357-466/? D/LibPrinterService: PrinterService getMaxTemperature,max=70
09-06 21:22:04.074 6412-6432/com.company.newpos D/PAYSDK: [+] Print MaxTemp: 70
09-06 21:22:04.074 357-5733/? D/LibPrinterService: PrinterService getWidth...
09-06 21:22:04.076 6412-6432/com.company.newpos D/PAYSDK: [+] Print Width: 384
09-06 21:22:04.077 357-357/? D/LibPrinterService: PrinterService getTemperature...
09-06 21:22:04.082 6412-6432/com.company.newpos D/PAYSDK: [+] Print Temp: 32

That is the correct way it should work. Now when I switch to release mode. the methods behave way different. The getStatus() method makes the PrinterService return the current temperature ( getTemperature() ), getMaxTemperature() returns the status ( getStatus() ). As the result, the printer module is all messed up and the printer doesn't work.

At first, I thought it was a proguard mapping issue (It may still be) but, the same happens even when proguard and minify are disabled.

Can anyone help guide me or give me an idea of what might be happening here?

Thanks

Try to add some delay in the connection.

 new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            // put your function here.
        }
    }, 2000);

I later was able to solve this. Turn out the proguard configuration was not excluding some of the classes.

So next time your app behaves radically different between release and debug mode, check your proguard configuration first.

Thank you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM