SVJ
SVJ

Reputation: 63

Android : Getting NoClassDefFoundError for AndroidUtils

I am using Android Studio to develop an app that is GCM enabled, needs google Sign in and uses google maps. I have incorporated endpoints for google app engine also. Now I am getting noclassfound error when i trying to call the endpoints.

Below given is my gradle file for app

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {


    dexOptions {
        javaMaxHeapSize "4g"
    }
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
    applicationId "my.application.com"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
dexOptions {
    incremental true
}
}

dependencies {
compile 'com.android.support:multidex:1.0.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.facebook.android:facebook-android-sdk:4.6.0'

compile project(path: ':backend', configuration: 'android-endpoints')

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:percent:23.1.1'
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile 'com.google.android.gms:play-services:8.3.0'
}

NOW i when i am trying to access the endpoints in a ASyntask i am getting noclassdeffound error:

 Registration.Builder builder = new Registration.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                // options for running against local devappserver
                // - 10.0.2.2 is localhost's IP address in Android emulator
                // - turn off compression when running against local devappserver
                .setRootUrl("http://192.168.1.4:8080/_ah/api")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });

EXACT error stack is as follows:

java.lang.RuntimeException: An error occured while executingdoInBackground()
                                                                        at android.os.AsyncTask$3.done(AsyncTask.java:299)
                                                                        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
                                                                        at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:239)
                                                                        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
                                                                        at java.lang.Thread.run(Thread.java:856)
                                                                     Caused by: **java.lang.NoClassDefFoundError: com.google.api.client.extensions.android.AndroidUtils**
                                                                        at com.google.api.client.extensions.android.http.AndroidHttp.newCompatibleTransport(AndroidHttp.java:54)

I have tried most of the suggestion given on web. - Rebuild - Deleted all gradle cache - Restarted Studio

Since i am new to android and Java world any detailed help would be much appreciated.

Upvotes: 1

Views: 193

Answers (2)

Jorgesys
Jorgesys

Reputation: 126563

You are missing a reference that contains :

com.google.api.client.http.apache.ApacheHttpTransport

please add:

compile 'com.google.api-client:google-api-client'

check the info: https://github.com/google/google-api-java-client

and very important: Sync project with gradle files!.

Upvotes: 1

SVJ
SVJ

Reputation: 63

I am still not clear of the root cause of the issue. But issue was solved via using following steps:

  1. Removed all dex related stuff.
  2. Removed 'com.google.android.gms:play-services:8.3.0' from gradle.
  3. Added individual dependencies like 'com.google.android.gms:play-services-plus:8.3.0' 'com.google.android.gms:play-services-maps:8.3.0' 'com.google.android.gms:play-services-location:8.3.0'

  4. Also added dependency as suggested by @Elenasys. But this did not alone solved the issue.

  5. Rebuild the entire application.

Upvotes: 0

Related Questions