Android Annotations + Android Studio / Gradle构建正常,但在运行时抛出ClassNotFoundException

时间:2015-10-26 11:17:54

标签: android android-studio gradle annotations android-annotations

我正在努力将项目从Eclipse迁移到Android Studio并让Android Annotations正常运行。

我在各种项目中都使用AA而没有太多问题,但这让我很难过。我在gradle文件中有通常的设置:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

apply plugin: 'android'
apply plugin: 'com.neenbedankt.android-apt'
def AAVersion = '3.3.2'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':libprojects:ActiveAndroid')

    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"

    compile 'joda-time:joda-time:2.8.2'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'

    compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
    compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.4.1.3'
}

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            // java.srcDirs = ['.apt_generated','src'] // We had big build issues with this left in, but it builds OK with it commented out
            resources.srcDirs = ['.apt_generated','src']
            aidl.srcDirs = ['.apt_generated','src']
            renderscript.srcDirs = ['.apt_generated','src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')
    }

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

apt {
    arguments {
        // Mark - This looks like it's not actually needed, as it builds fine without and throws up a warning when it's included.
         androidManifestFile variant.outputs[0].processResources.manifestFile
        // if you have multiple outputs (when using splits), you may want to have other index than 0
    }
}

该应用程序似乎构建正常,但我在运行时立即得到ClassNotFoundException。我检查了构建目录,似乎没有生成ClassName_类。我的androidannotations.log文件也只有以下行:

20:11:45.159 [Daemon worker Thread 30] INFO  o.a.AndroidAnnotationProcessor:83 - Initialize AndroidAnnotations 3.3.2 with options {androidManifestFile=/Users/marky/myapp/android/build/intermediates/manifests/full/debug/AndroidManifest.xml}

而我构建的另一个应用程序的日志要长得多:

20:11:58.93 [Daemon worker] INFO  o.a.AndroidAnnotationProcessor:83 - Initialize AndroidAnnotations 3.3.2 with options {androidManifestFile=/Users/marky/anotherapp/app/build/intermediates/manifests/full/debug/AndroidManifest.xml}
20:11:58.164 [Daemon worker] INFO  o.a.AndroidAnnotationProcessor:107 - Start processing for 18 annotations on 26 elements
20:11:58.215 [Daemon worker] DEBUG o.a.h.AndroidManifestFinder:98 - AndroidManifest.xml file found with specified path: /Users/marky/anotherapp/app/build/intermediates/manifests/full/debug/AndroidManifest.xml 
...loads more lines 

所以看起来AA没有完全运行,但我不确定为什么。我在SO和其他地方整日搜索了一个解决方案,但我看不到。

0 个答案:

没有答案