Getting Android Studio, Gradle and Android Annotations working together
Asked Answered
R

1

7

now that i've decided to use Android Annotations with Android Studio i wanted to implement it through Gradle. After some thoughtful research i've found out that there are older and newer ways of implementing Android Annotations through Gradle depending on which version android studio, gradle or android annotations have. i came to this useful tutorial -> http://www.jayway.com/2014/02/21/androidannotations-setup-in-android-studio/ , and tried to implement this , at first, with the new 'android-L' as target SDK like

targetSDKversion "android-L" + compileSdkVersion 20 + buildToolsVersion "20.0.0"

until i tried it with

targetSDKversion 20 + compileSdkVersion 20 + buildToolsVersion "20.0.0"

and also

targetSDKversion 19 + compileSdkVersion 19 + buildToolsVersion "19.1.0".

Everytime i was getting 2 warnings that my java classes dont seem to get precompiled. even though it seems that it pre-creates the build/generated/source/apt directory. but without my pre-processed class from my MainActivity -> MainActivity_

I always do get following Warnings:

Note: Resolve log file to D:\AndroidProjects\GradleTest\app\build\generated\source\apt\androidannotations.log Note: Initialize AndroidAnnotations 3.0.1 with options >{androidManifestFile=D:\AndroidProjects\GradleTest\app\build\intermediates\manifests\debug\AndroidManifest.xml, resourcePackageName=at.gradle.defuex.gradletest}

warning: Unclosed files for the types '[dummy1407928544078]'; these types will not undergo annotation processing

warning: The following options were not recognized by any processor: '[androidManifestFile, resourcePackageName]'

My build.gradle file looks like this:

buildscript{
repositories{
    mavenCentral()
}

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


repositories{
    mavenCentral()
}

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

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "at.gradle.defuex.gradletest"
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

    signingConfigs{
        releaseConfig{
            storeFile file("gradlekeystore.jks");
            storePassword ("*************");
            keyAlias "keyAlias";
            keyPassword "*************";
        }
    }


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

            signingConfig signingConfigs.releaseConfig
        }

        debug {
            debuggable true
            applicationIdSuffix ".debug"
        }
    }
}

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile
        resourcePackageName "at.gradle.defuex.gradletest"
    }
}

dependencies {
    apt "org.androidannotations:androidannotations:3.0+"
    compile "org.androidannotations:androidannotations-api:3.0+"
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
}

Im using following Versions:

  • Android Studio version 0.8.2
  • Gradle version 0.12.2
  • android-apt version 1.3
  • android annotations version 3.0.1 (as seen in the build.gradle file)
  • If there should be a solution to this problem please tell me, because im confused now.
  • If there should be a better annotations framework or a way of using cool annotations, please tell me that too.
  • And if it should not be a common way anymore to use annotations for android projects anyway, please pleeeeease tell me that too.

,but i would prefer a solution to my problem :)

Cheers!

Ribose answered 13/8, 2014 at 15:29 Comment(6)
I would drop AndroidAnnotations in favor to ButterKnifeBickerstaff
i shortly looked over ButterKnife and can see that it seems slightly more understandable. but i could not find any annotations e.g.: @ Background or @ UiThread like in Android Annotations that were always helpful too. Are there any other implementations for functionalities like this or is butterknife mainly for views?Ribose
@Bickerstaff Actually ButterKnife only offers a small subset of AA's functionality, but the setup of it requires quite the same effort in build.gradle. :)Chengteh
@Ribose So what is your question? You do not understand the warnings? Please read this issue. I do not know what is the problem with the apt arguments, maybe it's a problem with android-apt.Chengteh
the problem is that i can't build an .apk version due to the missing MainActivity_ class. furthermore, butterknife is much more easier to implement than AA...just my opinion. because it works like "butter".Ribose
Did you find any solution ? I'm having the same error + error: package javax.annotation.processing does not exist.Ens
V
-1

Try to run gradlew clean build from project root. Then try to make project (button with a green arrow with 0 and 1) before running on a device. Should be fine.

Violinist answered 18/8, 2014 at 13:9 Comment(1)
This doesn't change the situation at all.Oneness

© 2022 - 2024 — McMap. All rights reserved.