Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you interpret "java.lang.NoSuchMethodError: No direct method"?

Tags:

java

android

We decided, perhaps naively, that we should update many of our libraries from two-year-old 1.12.0-betas to nice new versions 1.20.0. For example: we updated google-http-client-1.12.0-beta.jar to google-http-client-android-1.20.0.jar.

When we execute this code:

  List<String> scopes = Lists.newArrayList(SendToGoogleUtils.FUSION_TABLES_SCOPE);
  GoogleAccountCredential credential = SendToGoogleUtils.getGoogleAccountCredential(
      context, account.name, scopes );
  if (credential == null) {
    return false;
  }
  Fusiontables fusiontables = new Fusiontables.Builder(
      AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();

we get this amazing error report:

FATAL EXCEPTION Caused by: java.lang.NoSuchMethodError: No direct method <init>(Lcom/google/api/client/http/HttpTransport;Lcom/google/api/client/http/HttpRequestInitializer;Ljava/lang/String;Ljava/lang/String;Lcom/google/api/client/json/JsonObjectParser;Lcom/google/api/client/googleapis/services/GoogleClientRequestInitializer;Ljava/lang/String;Z)V in class Lcom/google/api/client/googleapis/services/json/AbstractGoogleJsonClient; or its super classes (declaration of 'com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient' appears in /data/app/dkr.ajijic.apps.tm-1/base.apk)

Does anybody know how to interpret it? We sure don't!

like image 288
BinCodinLong Avatar asked Aug 17 '15 00:08

BinCodinLong


3 Answers

Had this on Android when the source code target version was higher than the OS version used on the device. Therefore had access to methods that didn't exist in the library bundled with the OS, hence NoSuchMethodError.

like image 150
klenki Avatar answered Sep 18 '22 12:09

klenki


It just means that a constructor for AbstractGoogleJsonClient with a particular argument list wasn't available.

Check your super() calls for your subclass(es) of AbstractGoogleJsonClient and make sure you don't need to update the argument list to match your updated libraries.

If that's not in your source code, then there may be a library version dependency issue with Google API client library.

like image 27
kris larson Avatar answered Sep 19 '22 12:09

kris larson


This issue is happened because of Proguard is applied via Proguard this class name and methods name changes that why NoSuchMethod exception is occurring.

To resolve this error please add below line into you Proguard rules.

-keep class com.google.** { *; }

Hopefully this will resolve your issue.

like image 38
Muhammad Noman Avatar answered Sep 20 '22 12:09

Muhammad Noman