5

我已经两次尝试让 android-apt 工作,因为它是我想使用的第 3 方库(AndroidAnnotations 和 PermissionsDispatcher)所必需的,而且两次我都把头撞在墙上,直到我厌倦了听到挤压声。

问题?Android Studio 根本无法找到或获取依赖项:

Error:Could not find com.neenbedankt.gradle:plugins:android-apt.
Searched in the following locations:
    file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt.pom
    file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt-1.8.jar
    https://jcenter.bintray.com/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt.pom
    https://jcenter.bintray.com/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt-1.8.jar
    https://repo1.maven.org/maven2/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt.pom
    https://repo1.maven.org/maven2/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt-1.8.jar
Required by:
    :MaterialQuoter:unspecified

我可能犯了某种荒谬的错误(我的意思是,那些库不会有任何用处,对吧?),但我不出我做错了什么。

我正在运行 Android Studio 1.4,以防它在某种程度上相关。

这是项目的 gradle 文件:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.neenbedankt.gradle:plugins:android-apt:1.8'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
    }
}

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

dependencies {
    compile 'com.github.hotchemi:permissionsdispatcher:1.2.1'
    apt 'com.github.hotchemi:permissionsdispatcher-processor:1.2.1'
}

这是我主要工作的模块的 gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.callisto.materialquoter"
        multiDexEnabled true
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/ASL2.0'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.google.code.findbugs:jsr305:1.3.9'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.github.hotchemi:permissionsdispatcher:1.2.1'
    compile 'org.roboguice:roboguice:3.+'
    provided 'org.roboguice:roboblender:3.+'
    compile 'org.codepond:wizardroid:1.3.0'
    compile ('com.octo.android.robospice:robospice:1.4.14') {
        exclude group: 'org.apache.commons', module: 'commons-io'
    }
    compile ('com.octo.android.robospice:robospice-cache:1.4.14') {
        exclude group: 'org.apache.commons', module: 'commons-io'
    }
    compile ('com.octo.android.robospice:robospice-spring-android:1.4.14') {
        exclude group: 'org.apache.commons', module: 'commons-io'
    }
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
    compile 'de.greenrobot:greendao:2.0.0'
}
4

3 回答 3

7

我有同样的问题。这帮助我弄清楚了。

在应用程序模块本身上,添加这些行(顺序很重要):

buildscript {
    repositories {
        mavenCentral()
    }

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

apply plugin: 'com.android.application'
apply plugin: 'android-apt'


dependencies {
    compile 'com.github.hotchemi:permissionsdispatcher:1.2.1@aar'
    apt 'com.github.hotchemi:permissionsdispatcher-processor:1.2.1'
}
于 2015-11-19T15:12:57.930 回答
3

从 Android Gradle 插件版本 2.2 开始,之前由 android-apt 提供的所有功能现在都可以在 Android 插件中使用。这意味着 android-apt 已正式过时;)

因此,

  1. 确保您已将 Gradle 插件更新为 >= 2.2
  2. 而不是apt使用annotationProcessor

参考:https ://bitbucket.org/hvisser/android-apt/wiki/Migration

于 2016-11-06T17:42:51.597 回答
1

我在 Android Studio 2.2.1 上是这样想的:

这让我可以在主项目和库中同时使用 Butterknife。

请注意,在库中,使用 Butterknife 注释时使用R2 .id.blah 而不是 R.id.blah。

希望对所有人都有效。

还要检查这个链接

1)项目gradle文件:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.1'
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2)应用程序梯度文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    ...


}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    ...

    //Butterknife https://github.com/JakeWharton/butterknife#library-projects
    compile 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

    ...
}

3) 库 gradle 文件

apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.0"

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    //Butterknife
    compile 'com.jakewharton:butterknife-annotations:8.4.0'
    compile 'com.jakewharton:butterknife:8.4.0'
    ...
}
于 2017-01-19T08:06:21.080 回答