java - 带有 AndroidAnnotations NoClassDefFoundError 的 Android Studio

标签 java android android-studio android-gradle-plugin android-annotations

我有一个带有 Android 注释的应用程序,当我尝试运行它时,它给我一个 NoClassDefFoundError。

java.lang.NoClassDefFoundError: br.socialcondo.app.rest.services.UserService_

在注释日志中我可以看到生成了这个类:

Note: Generating class: br.socialcondo.app.rest.services.UserService_

我做错了什么?

编辑

分享build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        maven { url "http://dl.bintray.com/populov/maven" }
        mavenCentral()
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url "http://dl.bintray.com/populov/maven" }
    maven { url "https://repo.commonsware.com.s3.amazonaws.com" }
    mavenCentral()
}

configurations {
    apt
}


android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'

    dexOptions {
        javaMaxHeapSize "4g"
    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 30

        versionName "2.0.0"
        multiDexEnabled true
    }

    signingConfigs {
        release {
            storeFile file("xxx")
            storePassword "xxx"
            keyAlias "xxx"
            keyPassword "xxx"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

    buildTypes {
        release {
            ext.betaDistributionGroupAliases = "devs"
            minifyEnabled false
            signingConfig signingConfigs.release
        }
    }

    productFlavors {
        production {
            applicationId "br.socialcondo.app"
        }

        development {
            applicationId "br.socialcondo.app"
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/notice.txt'
    }
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName 'br.socialcondo.app'
    }
}

dependencies {
    compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
    compile group: 'com.google.guava', name: 'guava', version: '11.0.2'
    // You must install or update the Google Repository through the SDK manager to use this dependency.
    // The Google Repository (separate from the corresponding library) can be found in the Extras category.
    // compile 'com.google.android.gms:play-services:4.2.42'
    // You must install or update the Google Repository through the SDK manager to use this dependency.
    // The Google Repository (separate from the corresponding library) can be found in the Extras category.
    //
    apt 'org.androidannotations:androidannotations:3.2'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':libraries:facebook')
    compile project(':libraries:caldroid')
    compile 'org.codehaus.jackson:jackson-jaxrs:1.9.13'
    compile 'org.androidannotations:androidannotations-api:3.2'
    compile 'com.google.android.gms:play-services:6.1.+'
    compile 'com.android.support:support-v4:22.1.1'
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.android.support:recyclerview-v7:22.1.1'
    compile 'com.android.support:gridlayout-v7:22.1.1'
    compile 'de.greenrobot:greendao:1.3.7'
    compile 'com.koushikdutta.urlimageviewhelper:urlimageviewhelper:1.0.4'
    compile('com.crashlytics.sdk.android:crashlytics:2.2.4@aar') {
        transitive = true
    }
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.makeramen:roundedimageview:1.5.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.kbeanie:image-chooser-library:1.4.02@aar'
    compile 'com.github.chrisbanes.photoview:library:1.2.3'
    compile 'com.commonsware.cwac:endless:1.2.3'
    compile 'com.malinskiy:superrecyclerview:1.1.0'
}

编辑 2

根build.gradle

buildscript {

    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

最佳答案

问题出在

multiDexEnabled true

它仅在 Android 5 上受原生支持。所以我需要一个图书馆 在旧版本中运行。我找到了解决方法。

关于java - 带有 AndroidAnnotations NoClassDefFoundError 的 Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30491300/

相关文章:

java android studio - 检查权限

java - Android检查多个字符串是否不为空

android-studio - 如何在 Android Studio 中生成新的图片资源

java - 为什么当我打印出刚刚读取的文本文件时,会得到 "null"和 "0"

Android:如何将捕获的图像保存到特定文件夹

java - 如何从触摸屏获取输入并保存为位图格式?

机器人 : parsing XML and insert to sqlite database

java - 带参数的 Struts 2 重定向

java - ArrayList 如何提供随机访问行为?

java - 错误 : java. util.NoSuchElementException - 扫描仪未按预期运行