【问题标题】:Missing annotation processing in Android StudioAndroid Studio 中缺少注释处理
【发布时间】:2016-12-11 03:31:13
【问题描述】:

我正在使用 Android Studio 2.2.3 和构建工具 24.0.2。

包括 Butterknife 在内的几个库在 build.gradle 中为我要编译的应用程序使用注释。在第一次我得到这个错误:

Gradle 同步失败:找不到参数 [com.jakewharton:butterknife-compiler:8.4.0] 的方法 annotationProcessor()

在 AS 启动窗口中,我编辑了首选项并勾选了注释处理。我清除了缓存并重新启动了 Android。仍然收到该错误。

应用级 build.gradle:

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.github.triplet.gradle:play-publisher:1.1.4'
        //noinspection GradleDynamicVersion
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '3.1'
    distributionUrl = distributionUrl.replace("bin", "all")
}

Mod 级别 build.gradle:

apply plugin: 'com.android.application'
apply from: '../config/quality/quality.gradle'
apply plugin: 'com.github.triplet.play'
//TODO uncomment line below after adding fabric api secret and key to fabric.properties
//apply plugin: 'io.fabric'

android {
    compileSdkVersion 24
    buildToolsVersion '24.0.2'
    defaultConfig {
        applicationId 'com.murphysw.rosie'
        minSdkVersion 16
        targetSdkVersion 24
        testInstrumentationRunner "${applicationId}.runner.RxAndroidJUnitRunner"
        versionCode 1000
        // Major -> Millions, Minor -> Thousands, Bugfix -> Hundreds. E.g 1.3.72 == 1,003,072
        versionName '0.1.0'
    }
    signingConfigs {
        // You must set up an environment var before release signing
        // Run: export APP_KEY={password}
        // TODO Add your release keystore in /keystore folder
        release {
            storeFile file('keystore/release.keystore')
            keyAlias 'alias'
            storePassword "$System.env.APP_KEY"
            keyPassword "$System.env.APP_KEY"
        }

        debug {
            storeFile file('keystore/debug.keystore')
            keyAlias 'androiddebugkey'
            storePassword 'android'
            keyPassword 'android'
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release

            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            ext.betaDistributionReleaseNotesFilePath =
                    file('../crashlytics_release_notes.txt').absolutePath
        }

        debug {
            versionNameSuffix " Debug"
            debuggable true
        }
    }
    sourceSets {
        def commonTestDir = 'src/commonTest/java'
        test {
            java.srcDir commonTestDir
        }
        androidTest {
            java.srcDir commonTestDir
        }
    }
    //Needed because of this https://github.com/square/okio/issues/58
    lintOptions {
        warning 'InvalidPackage'
    }
    productFlavors {
    }
}

play {
    serviceAccountEmail = 'your-service-account-email'
    pk12File = file('key.p12')
    // By default publishes to Alpha channel
    track = 'alpha'
}

dependencies {
    final PLAY_SERVICES_VERSION = '9.6.1'
//    final SUPPORT_LIBRARY_VERSION = '25.0.1'
    final SUPPORT_LIBRARY_VERSION = '24.0.2'
    final RETROFIT_VERSION = '2.1.0'
    final DAGGER_VERSION = '2.5'
    final DEXMAKER_VERSION = '1.4'
    final HAMCREST_VERSION = '1.3'
    final ESPRESSO_VERSION = '2.2.1'
    final RUNNER_VERSION = '0.4'
    final BUTTERKNIFE_VERSION = '8.4.0'
    final AUTO_VALUE_VERSION = '1.3'
    final AUTO_VALUE_GSON_VERSION = '0.4.2'
    def daggerCompiler = "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
    def jUnit = "junit:junit:4.12"
    def mockito = "org.mockito:mockito-core:1.10.19"
    // App Dependencies
    compile "com.google.android.gms:play-services-gcm:$PLAY_SERVICES_VERSION"
    compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
    compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
    compile "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
    compile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
    compile('com.squareup.sqlbrite:sqlbrite:0.8.0')
    {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    compile "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
    compile "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
    compile "com.squareup.retrofit2:adapter-rxjava:$RETROFIT_VERSION"
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.1.6'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
        transitive = true;
    }
    compile 'com.jakewharton.timber:timber:4.1.2'
    compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION" annotationProcessor "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
    // Replace provided dependency below with official AutoValue once this issue is fixed

    // https://github.com/google/auto/issues/268
    provided "com.jakewharton.auto.value:auto-value-annotations:$AUTO_VALUE_VERSION" provided "com.ryanharter.auto.value:auto-value-gson:$AUTO_VALUE_GSON_VERSION" annotationProcessor "com.google.auto.value:auto-value:$AUTO_VALUE_VERSION" annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.4-rc2'
    annotationProcessor "com.ryanharter.auto.value:auto-value-gson:$AUTO_VALUE_GSON_VERSION" annotationProcessor 'com.squareup:javapoet:1.7.0'
    // https://github.com/rharter/auto-value-parcel/issues/64
    compile "com.google.dagger:dagger:$DAGGER_VERSION" provided 'org.glassfish:javax.annotation:10.0-b28'
    //Required by Dagger2
    annotationProcessor daggerCompiler testAnnotationProcessor daggerCompiler androidTestAnnotationProcessor daggerCompiler
    // Instrumentation test dependencies
    androidTestCompile jUnit
    androidTestCompile mockito
    androidTestCompile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
    androidTestCompile("com.android.support.test.espresso:espresso-contrib:$ESPRESSO_VERSION")
    {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'recyclerview-v7'
    }
    androidTestCompile "com.android.support.test.espresso:espresso-core:$ESPRESSO_VERSION"
    androidTestCompile "com.android.support.test:runner:$RUNNER_VERSION"
    androidTestCompile "com.android.support.test:rules:$RUNNER_VERSION"
    androidTestCompile "com.crittercism.dexmaker:dexmaker:$DEXMAKER_VERSION"
    androidTestCompile "com.crittercism.dexmaker:dexmaker-dx:$DEXMAKER_VERSION"
    androidTestCompile "com.crittercism.dexmaker:dexmaker-mockito:$DEXMAKER_VERSION"
    // Unit tests dependencies
    testCompile jUnit testCompile mockito testCompile "org.hamcrest:hamcrest-core:$HAMCREST_VERSION" testCompile "org.hamcrest:hamcrest-library:$HAMCREST_VERSION" testCompile "org.hamcrest:hamcrest-integration:$HAMCREST_VERSION" testCompile 'org.robolectric:robolectric:3.1'
}

// Log out test results to console
tasks.matching {it instanceof Test}.all {
    testLogging.events = ["failed", "passed", "skipped"]
}

【问题讨论】:

  • build.gradle 中的 gradle 版本设置为什么?是 > 2.2 吗?

标签: java android


【解决方案1】:

butterknife 页面要求包含这一行:

annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

您是否将其包含在您的应用级 gradle 中?

【讨论】:

  • 我正在使用来自一家名为 Ribot 的公司的模板项目。它被广泛使用,所以我怀疑问题出在我的 Android Studio 设置上。那条线似乎包括在内。 AS 似乎没有定义注释处理器。看起来这个功能以前是由插件包含的,现在应该被加入。谢谢!
  • 原来 Ribot 模板缺少几行,并且 build.gradle 文件需要在任务之间添加一些额外的换行符。按照此处的 Butterknife 安装说明:github.com/JakeWharton/butterknife 为该库启用注释处理。
猜你喜欢
  • 1970-01-01
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 2017-03-21
  • 1970-01-01
  • 2013-09-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多