Search code examples
androidandroid-annotations

How to Get Android Annotations Working in Studio 0.8.2


I've been trying to get Android Annotations running my installation of Android Studio 0.8.2 and cannot get it working correctly.

Here's what I've done to get it set up...

In File > Settings > Compiler > Annotation Processors Selected "Enable annotation processing" Processor path set to "C:\software\android\androidannotations-3.0.1.jar;C:\software\android\androidannotations-api-3.0.1.jar"

Store Generated sources set to "Module content root" Directories are set to "gen/aa" and "gen/aa-test"

Placed the androidannotations-3.0.1.jar file in the project's libs directory.

I can add the annotations to the files correctly, autocomplete finds all the annotations.

However, when I change the AndroidManifest.xml file to use the _ at the end of the android:name, it shows as red, and doesn't launch the app.

Then, after changing the Activity in the Launch Configurations to use the underscore, it also fails with an error.

Next steps?

    <activity
        android:name=".FlagActivity_"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>



@EActivity
public class FlagActivity extends Activity implements
      GooglePlayServicesClient.ConnectionCallbacks,
      GooglePlayServicesClient.OnConnectionFailedListener {

enter image description here


Solution

  • I've got Android Annotations running on Android Studio 0.8.2.

    First off, you shouldn't have to specify a specific Activity, just choose "Launch default activity". Your manifest looks fine.

    What I've found is that you need to sync gradle from time to time so the BlahActivity_ can be generated.

    Here is my gradle config for my app module (only the Android annotations specific configs):

            buildscript {
                repositories {
                    mavenCentral()
                }
                dependencies {
                    classpath 'com.android.tools.build:gradle:0.12.+'
                    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
                }
            }
    
            apply plugin: 'android'
            apply plugin: 'android-apt'
    
            repositories {
                mavenCentral()
            }
    
            apply plugin: 'com.android.application'
    
            android {
    
                compileSdkVersion 20
                buildToolsVersion "20.0.0"
    
                defaultConfig {
                    applicationId "com.foo.androidapp"
                    minSdkVersion 16
                    targetSdkVersion 20
                    versionCode 1
                    versionName "1.0"
                }
    
                buildTypes {
                    release {
                        runProguard false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }
    
                // AA: if you are going to use the spring rest template with AA
                packagingOptions {
                    exclude 'META-INF/ASL2.0'
                    exclude 'META-INF/LICENSE'
                    exclude 'META-INF/license.txt'
                    exclude 'META-INF/NOTICE'
                    exclude 'META-INF/notice.txt'
                }
    
                productFlavors {
    
                    production {
                        packageName = 'com.foo.androidapp'
                    }
    
                    development {
                        packageName = 'com.foo.androidapp.dev'
                    }
    
                }
            }
    
            dependencies {
                // AA imports (also enables REST support w AA)!!
                compile fileTree(dir: 'libs', include: ['*.jar'])
                compile 'org.androidannotations:androidannotations-api:3.0+'
                compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
                compile 'com.fasterxml.jackson.core:jackson-databind:2.4.1.3'
                compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
                apt 'org.androidannotations:androidannotations:3.0+'
    
            }
    
            apt {
                arguments {
                    androidManifestFile variant.processResources.manifestFile
    
                    resourcePackageName "com.foo.androidapp"
    
                    // You can set optional annotation processing options here, like these commented options:
                    // logLevel 'INFO'
                    // logFile '/var/log/aa.log'
                }
            }