Cannot get android-apt working
Asked Answered
O

3

5

Twice already I've tried to get android-apt to work, because it's required by the 3rd-party libraries I wanted to use (AndroidAnnotations and PermissionsDispatcher), and both times I bashed my head against the wall until I got tired of hearing the squishing sound.

The problem? Android Studio simply fails to find or fetch the dependencies:

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

I'm probably making some sort of ridiculous mistake (I mean, those libraries would not see any use otherwise, right?), but I can't see what I'm doing wrong.

I'm running Android Studio 1.4, in case it's somehow relevant.

This is the gradle file for the project:

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'
}

This is the gradle file for the module I'm mostly working on:

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'
}
Odalisque answered 15/10, 2015 at 13:18 Comment(3)
Please add some showing errorsIndue
Looks alright at first sight. Did you copy the dependency, 'apt' and 'apply' lines by any chance? Try to manually type those, as it has happened that copy paste introduces invisible spaces, breaking the configuration.Aixlachapelle
I just tried commenting everything out and manually typing it all again. Nothing changed... I added the classpath line first, tried to sync, got the error again, then added the rest, and tried syncing again - to end up with another error. Is there a way to manually import those dependencies into the m2repository? Say, I download everything manually and paste it somewhere for Gradle to find it?Odalisque
W
7

I had the same problem. This helped me to figure it out.

On the app module itself, add these lines (order is important):

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'
}
Wojak answered 19/11, 2015 at 15:12 Comment(2)
It turned out that I was placing these lines on the Gradle file for the whole project instead. Looking between this and the android-apt-example project helped sort things out. Many thanks... you just found the fix for a headache that has tormented me for months. Now I can test whether AndroidAnnotations is better than RoboGuice or not. :POdalisque
In repositories I had maven { url 'https://maven.fabric.io/public' } earlier. When I added mavenCentral() after the line, it worked fine.Watchful
C
3

As of the Android Gradle plugin version 2.2, all functionality that was previously provided by android-apt is now available in the Android plugin. This means that android-apt is officially obsolete ;)

Thus,

  1. Make sure you've updated your Gradle plugin to be >= 2.2
  2. Instead of apt use annotationProcessor

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

Collation answered 6/11, 2016 at 17:42 Comment(2)
I don't think this really answers the question. The 3rd party libraries the OP uses require android-apt, so removing it is probably not an option.Jellaba
What can be the solution then. I am using the the library and in the update of Android I cannot use apt. I am forced to update Android Studio to add the notification feature that is suitable with Android 8 and aboveRevocation
W
1

I figured this way on Android Studio 2.2.1:

This lets me use Butterknife on the main project and also on the library at the same time.

Please note that, on the library, use R2.id.blah instead of R.id.blah when using Butterknife annotations.

Hope works for all.

Also check this link

1) project gradle file:

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) app graddle file

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) library graddle file

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'
    ...
}
Whisenhunt answered 19/1, 2017 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.