Android : Getting NoClassDefFoundError for AndroidUtils

时间:2015-12-14 18:08:36

标签: android google-app-engine android-studio google-cloud-messaging google-play-services

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.

2 个答案:

答案 0 :(得分:1)

您缺少包含以下内容的参考:

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

请添加:

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

查看信息:https://github.com/google/google-api-java-client

非常重要:使用gradle文件同步项目!

答案 1 :(得分:0)

我仍然不清楚问题的根本原因。但问题通过以下步骤解决:

  1. 删除了所有与dex相关的内容。
  2. 从gradle中删除'com.google.android.gms:play-services:8.3.0'
  3. 添加了个别依赖项 “com.google.android.gms:播放服务加:8.3.0” “com.google.android.gms:播放服务,地图:8.3.0” 'com.google.android.gms:播放服务-位置:8.3.0'

  4. 还添加了@Elenasys建议的依赖关系。但这并没有解决这个问题。

  5. 重建整个应用程序。