7

I am using crosswalk as webview in my project, now I want to override a replace class for some purposes.

original class

org.xwalk.core.internal

imports....

class SslUtil {

    public static boolean shouldDenyRequest(int error) {
        switch(error) {
            case NetError.ERR_CERT_COMMON_NAME_INVALID:
            case NetError.ERR_CERT_DATE_INVALID:
            case NetError.ERR_CERT_AUTHORITY_INVALID:
            case NetError.ERR_CERT_WEAK_SIGNATURE_ALGORITHM:
            case NetError.ERR_CERT_WEAK_KEY:
            case NetError.ERR_CERT_NAME_CONSTRAINT_VIOLATION:
            case NetError.ERR_CERT_VALIDITY_TOO_LONG:
            case NetError.ERR_CERT_CONTAINS_ERRORS:
            case NetError.ERR_CERT_REVOKED:
            case NetError.ERR_CERT_INVALID:
            case NetError.ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
            case NetError.ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN:
            return true;
        default:
            break;
        }
        return false;
    }
}

Now what I want to do is to replace it by copying the package name and the classe nam.

org.xwalk.core.internal

imports....

class SslUtil {

    public static boolean shouldDenyRequest(int error) {
        //I'll do my custom handling of error
        return false;
    }
}

This is possible when I'm just running with Android Studio because the IDE asks me what SslUtil should I be using. However I won't be able to generate a signed APK because of the duplicate file

(org.xwalk.core.internal.SslUtil)

Now is there a way wherein I can exclude this certain file from my dependency and use the one I created? Or is it impossible?

Aaron
  • 2,591
  • 4
  • 27
  • 45
  • Short of ripping that class out of the compiled library, I don't think that you have many options here. BTW, please note that if your plan is to relax SSL validation (so that invalid connections become valid), your app may become ineligible for distribution on the Play Store and other app distribution channels. – CommonsWare Aug 15 '17 at 12:03
  • @CommonsWare Yes I am aware of that, I just wanted to try it out. Regarding the SSL Validation I already fixed it with API >= 24 (android:networkSecurityConfig) however it has issues with API <= 23 because android:networkSecurityConfig was introduced in API 24. Thanks! – Aaron Aug 15 '17 at 12:23
  • 1
    One option is to abuse `buildSrc` in a Gradle project. Its classloader takes precedence, so it is possible to completely replace a class from a library by putting it in the correct package there. – AutonomousApps Oct 26 '18 at 15:53

1 Answers1

-3

If you are overriding a class why do you want it to be in the same package as the class. since its your personal overriding, have it in your package.

your.own.package.here

imports....

class SslUtilNew extends SslUtil {

    public static boolean shouldDenyRequest(int error) {
        // Call Super if you want to otherwise use your own method
        //I'll do my custom handling of error
        return false;
    }
}

And then when you want to use it, import the one with your package. You can still continue to use other old class methods and only use the new one that you override.

Kapil G
  • 4,081
  • 2
  • 20
  • 32
  • I just edited it, *replace* not override. :), this method is being invoked by the library (dependency / another class in crosswalk) not me. – Aaron Aug 15 '17 at 11:56