Patreon / patreon-java

Interact with the Patreon API via OAuth
Apache License 2.0
53 stars 26 forks source link

NoSuchMethodError #29

Open kaldhu opened 5 years ago

kaldhu commented 5 years ago

This has been reported before but it was closed, I did post on that one put it seems to have not been noticed so i am opening a new issue

java.lang.NoSuchMethodError: No static method encPath(Ljava/lang/String;Ljava/nio/charset/Charset;)Ljava/lang/String; in class Lorg/apache/http/client/utils/URLEncodedUtils; or its super classes (declaration of 'org.apache.http.client.utils.URLEncodedUtils' appears in /system/framework/org.apache.http.legacy.boot.jar)
        at org.apache.http.client.utils.URIBuilder.encodePath(URIBuilder.java:172)
        at org.apache.http.client.utils.URIBuilder.buildString(URIBuilder.java:135)
        at org.apache.http.client.utils.URIBuilder.toString(URIBuilder.java:343)
        at com.patreon.PatreonAPI.fetchUser(PatreonAPI.java:95)
        at com.patreon.PatreonAPI.fetchUser(PatreonAPI.java:74)
        at com.******.Actvities.PatreonActivity$1.run(PatreonActivity.java:43)
        at java.lang.Thread.run(Thread.java:764)

This is the calling code, which apart from the threading around it, is the same code that is within the wiki


        Thread thread = new Thread(new Runnable(){
            public void run() {
                try {
                    PatreonOAuth oauthClient = new PatreonOAuth(clientId, clientSecret, redirectUri);
                    PatreonOAuth.TokensResponse tokens = oauthClient.getTokens(code);
                    String accessToken = tokens.getAccessToken();

                    PatreonAPI apiClient = new PatreonAPI(accessToken);
                    JSONAPIDocument<User> userResponse = apiClient.fetchUser();
                    User user = userResponse.get();
                    List<Pledge> pledges = user.getPledges();
                    if (pledges != null && pledges.size() > 0) {
                        Pledge pledge = pledges.get(0);
                    }
                } catch (Exception ex){
                }
            }
        });

Looking into the code the issue seems to be at the following function within .gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpclient\4.2.3\3328e73c4c97cc62e1077ff754308c98ab1564a\httpclient-4.2.3-sources.jar!\org\apache\http\client\utils\URIBuilder.java:

  private String encodePath(final String path) {
        return URLEncodedUtils.encPath(path, Consts.UTF_8);
    }

I have managed to fix the issue myself by creating a version of the PatreonAPI class and replacing the use of URIBuilder with Uri.Builder.

If you have any suggestions which allow me to use the PatreonAPI class from this package instead please let me know as rewriting entire classes is not my aim.

But I am having issues creating my APK due to conflicts with Apache that is used within this plugin

nperickson commented 5 years ago

Thank you @kaldhu for reporting this. We have added this to our backlog and hope to have a fix in place as soon as we can.