Nets-mobile-acceptance / Netaxept-Android-SDK

PiA Netaxept Android SDK is a library that provides the native In-App interaction to perform Netaxept payments directly from an app on Android devices while minimizing PCI DSS requirements for you.
31 stars 15 forks source link

SDK crashes when opening 3DS activity when R8 is in full mode #81

Closed cf256 closed 1 year ago

cf256 commented 1 year ago

How to reproduce:

Manually setting android.enableR8.fullMode=false the crash doesn't happen.

Android Studio Flamingo is shipping with this R8.fullMode enabled by default now so I'm guessing this will happen to more and more apps.

I can also resolve this by adding:

-keep,allowobfuscation,allowshrinking class eu.nets.pia.** { *; }
-keep,allowobfuscation,allowshrinking interface eu.nets.pia.** { *; }

to the proguard file. But I'm not sure if this is "keeping" too much.

Stacktrace

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{---/eu.nets.pia.ui.webview.ThreeDSecureActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Class.isInterface()' on a null object reference
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4169)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8757)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
BuildManager-Nets commented 1 year ago

Hi,

We will look into it and get back to you.

Thanks

Miss-PiA commented 1 year ago

Hi @cf256

You can keep using the proguard rules which is working for you for now. We will update our proguard rules on our side in the next release. Hope that helps you.

Miss-PiA commented 1 year ago

Hi @cf256

I was trying but I'm not able to reproduce the issue.

cf256 commented 1 year ago

Hi! I've made a sample repo here (https://github.com/cf256/NetsSDKProguardBug) that reproduces it.

Weirdly I'm only able to reproduce it on Android 13.

Miss-PiA commented 1 year ago

I was also checking on Android 13 but the issue was not reproducible. Anyways, I'll have a look at that project that you have shared and I'll update you.

Miss-PiA commented 1 year ago

I get it now why it was working for me and crashing for you @cf256 because you have optimization step enabled in minifcation process but I didn't.

I have this in sample app proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' and you have this proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

I have noted down the proguard rule changes we need to do. One last thing can you please check if writing these rules work for you. Remove rules which you have previously written for Pia SDK. I'll ship these rules in consumer-rules.pro in next release

-keep public class eu.nets.pia.PiaSDK { public *;}
-keep public class eu.nets.pia.PiaInterfaceConfiguration { public *;}
-keep public interface eu.nets.pia.RegisterPaymentHandler {*;}
-keep public class eu.nets.pia.data.exception.* {*;}
-keep public class eu.nets.pia.data.model.* {*;}
-keep public class eu.nets.pia.network.model.* {*;}
-keep public class eu.nets.pia.utils.FileLogger {*;}
-keep public class eu.nets.pia.utils.LogUtils {*;}
-keep public class eu.nets.pia.utils.StringUtils {*;}
-keep public class eu.nets.pia.wallets.* {*;}
-keep public class eu.nets.pia.ui.themes.* {*;}

-keep public class eu.nets.pia.ExtensionsKt { *;}
-keep public class eu.nets.pia.card.* {*;}

-keep class **.*$HTMLInterceptor{*;}

-keepclassmembers class eu.nets.pia.ui.main.PiaActivity {
    public final static java.lang.String BUNDLE_MERCHANT_INFO;
    public final static java.lang.String BUNDLE_TOKEN_CARD_INFO;
    public final static java.lang.String BUNDLE_ORDER_INFO;
    public final static java.lang.String BUNDLE_COMPLETE_RESULT;
    public final static java.lang.String BUNDLE_TRANSACTION_INFO;
}

#Rules required by Card.Io library
-keep class eu.nets.pia.cardio.** { *; }
-dontwarn eu.nets.pia.cardio.**

-keepattributes JavascriptInterface

##---------------Begin: proguard configuration for Retrofit  ----------
# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}

# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>

# Keep inherited services.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface * extends <1>

# R8 full mode strips generic signatures from return types if̄ not kept.
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>

# With R8 full mode generic signatures are stripped for classes that are not kept.
-keep,allowobfuscation,allowshrinking class retrofit2.Response

##---------------End: proguard configuration for Retrofit  ----------
cf256 commented 1 year ago

Hi. I've tested those rules in my sample app and it works with those enabled. Thanks!

Miss-PiA commented 1 year ago

Great. We will make a release soon. Either this or the next week.

Miss-PiA commented 1 year ago

Hi @cf256

We have just published a new version of our SDK. Could you please check and confirm whether the issue has been resolved for you?

cf256 commented 1 year ago

Hi. I've tested this now and it works. Thanks