question

tommyblock avatar image
tommyblock asked dazza5000 commented

Order SDK changes? App crashing with didn't find class "com.clover.sdk.v3.order.Order"

Have there been any recent changes to the orders SDK? We are having all sorts of issues using the OrderConnector, with code that was working before.

I thought maybe it was an issue with my build (e.g. libraries being updated), so I downloaded an old release from the sandbox, which was working and QAed before, but now that has the same error:

03-22 17:09:24.497 21399 21415 E Parcel  : Class not found when unmarshalling: com.clover.sdk.v3.order.Order
03-22 17:09:24.497 21399 21415 E Parcel  : java.lang.ClassNotFoundException: com.clover.sdk.v3.order.Order
03-22 17:09:24.497 21399 21415 E Parcel  :      at java.lang.Class.classForName(Native Method)
03-22 17:09:24.497 21399 21415 E Parcel  :      at java.lang.Class.forName(Class.java:400)
03-22 17:09:24.497 21399 21415 E Parcel  :      at android.os.Parcel.readParcelableCreator(Parcel.java:2508)
03-22 17:09:24.497 21399 21415 E Parcel  :      at android.os.Parcel.readParcelable(Parcel.java:2462)
03-22 17:09:24.497 21399 21415 E Parcel  :      at android.os.Parcel.readValue(Parcel.java:2365)
03-22 17:09:24.497 21399 21415 E Parcel  :      at d.b.b.m.g.k$a.a(:3)
03-22 17:09:24.497 21399 21415 E Parcel  :      at d.b.b.l.f.c(:6)
03-22 17:09:24.497 21399 21415 E Parcel  :      at d.b.b.m.g.k.i()
03-22 17:09:24.497 21399 21415 E Parcel  :      at e.a.a.a.doInBackground(:3)
03-22 17:09:24.497 21399 21415 E Parcel  :      at android.os.AsyncTask$2.call(AsyncTask.java:305)
03-22 17:09:24.497 21399 21415 E Parcel  :      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-22 17:09:24.497 21399 21415 E Parcel  :      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
03-22 17:09:24.497 21399 21415 E Parcel  :      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
03-22 17:09:24.497 21399 21415 E Parcel  :      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
03-22 17:09:24.497 21399 21415 E Parcel  :      at java.lang.Thread.run(Thread.java:761)
03-22 17:09:24.497 21399 21415 E Parcel  : Caused by: java.lang.ClassNotFoundException: Didn't find class "com.clover.sdk.v3.order.Order" on path: DexPathList[[zip file "/data/app/snip/base.apk"],nativeLibraryDirectories=[/data/app/<snip>/lib/x86, /data/app/snip/base.apk!/lib/x86, /system/lib, /vendor/lib]]
03-22 17:09:24.497 21399 21415 E Parcel  :      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-22 17:09:24.497 21399 21415 E Parcel  :      at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
03-22 17:09:24.497 21399 21415 E Parcel  :      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
03-22 17:09:24.497 21399 21415 E Parcel  :      ... 15 more

This only occurs in release builds, in debug builds the code works perfectly. I've created a concise example that reproduces the error - it works in debug builds, but in release builds it crashes when trying to create the order:

package mycomp.services;

import android.app.IntentService;
import android.content.Intent;
import android.os.RemoteException;
import android.util.Log;

import com.clover.sdk.util.CloverAccount;
import com.clover.sdk.v1.BindingException;
import com.clover.sdk.v1.ClientException;
import com.clover.sdk.v1.ServiceException;
import com.clover.sdk.v3.order.Order;
import com.clover.sdk.v3.order.OrderConnector;

public class OrderCreateTestService extends IntentService {
    final String TAG = "OrderCreateTestService";

    public OrderCreateTestService() {
        super(OrderCreateTestService.class.getName());
    }

    protected OrderConnector orderConnector;

    @Override
    public void onCreate() {
        super.onCreate();

        orderConnector = new OrderConnector(this, CloverAccount.getAccount(this), null);
        orderConnector.connect();
    }

    @Override
    public void onDestroy() {
        if (orderConnector != null) {
            orderConnector.disconnect();
            orderConnector = null;
        }

        super.onDestroy();
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        try {
            orderConnector.createOrder(
                    new Order()
                        .setTitle("Test Order #1234")
                        .setNote("This is a test order.")
            );
        } catch (RemoteException | ClientException | ServiceException | BindingException e) {
            Log.e(TAG, "Error creating order: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
Orders
1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dazza5000 avatar image dazza5000 commented ·

This is a proguard issue. The following rule will fix it:


# Clover SDK

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}
0 Likes 0 ·
tommyblock avatar image
tommyblock answered dazza5000 commented

Hi David,

Thanks that thread was helpful and led me down the right path, although it doesn't directly have an answer for my issue. I'm testing on the Android emulator, not a devkit.

It turns out the issue was code shrinking, which is enabled by default for release builds, but not debug builds. In my case R8 was removing a bunch of classes relating to orders, hence the ClassNotFoundException when I tried to use the OrderConnector.

I couldn't figure out a set of Proguard rules to make it keep these classes, so for now I simply disabled code shrinking by setting minifyEnabled false for all build types, which fixed the issue.

After I figured all this out, I came across another thread where someone had the same issue, and same solution:

https://community.clover.com/questions/26997/should-we-avoid-minifying-the-apk-unless-necessary.html

It looks like there is something configured incorrectly in the Clover SDK then, causing Proguard to remove these classes even though they are being used.

Regards,

TB

1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dazza5000 avatar image dazza5000 commented ·
                    
  1. # Clover SDK
  2. -keepnames class * implements android.os.Parcelable {
  3. public static final ** CREATOR;
  4. }
0 Likes 0 ·
David Marginian avatar image
David Marginian Deactivated answered

I know you said you downloaded an older working build, and it doesn't work as well, are you absolutely certain you installed it correctly (was this on a devkit?). This sounds like some type of packaging or dependency issue on your end, you may want to read through this thread - https://community.clover.com/questions/23761/app-crashes-on-station-orig-with-classnotfoundexce.html. Have you added any dependecies lately?

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community