Jacob
Jacob

Reputation: 15297

Android annotations in Android studio - cannot access Activity_?

There are several solutions how to add Android Annotations with Android Studio. This time I've simply added it via AS interface. It show all annotations like @EActivity but it does not access generated classes ActivityName_ .

enter image description here

EDIT:

I've also changed Scope to Provided with no result. Option with gradle content:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.package">

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity android:name=".MainFragmentActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


    </application>

</manifest>

Internal build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        // replace with the current version of the Android plugin
        classpath 'com.android.tools.build:gradle:1.0.0'
        // replace with the current version of the android-apt plugin
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}
repositories {
    mavenCentral()
    mavenLocal()
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.1'
dependencies {
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}

//androidManifestFile variant.outputs[0].processResources.manifestFile
apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
//        androidManifestFile variant.outputs[1].processResources.manifestFile
        // if you have multiple outputs (when using splits), you may want to have other index than 0

        resourcePackageName 'com.package'

        // If you're using Android NBS flavors you should use the following line instead of hard-coded packageName
        // resourcePackageName android.defaultConfig.packageName

        // You can set optional annotation processing options here, like these commented options:
        // logLevel 'INFO'
        // logFile '/var/log/aa.log'
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.package"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.2'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'org.androidannotations:androidannotations:3.2'
    provided 'org.androidannotations:androidannotations-api:3.2'
    compile 'com.android.support:support-v4:21.0.2'
}

The global project build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0-rc4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Upvotes: 0

Views: 1695

Answers (2)

user8898827
user8898827

Reputation: 1

Here is a working sample for Android Plugin 2.3.0:

buildscript {
    repositories {
      mavenCentral()
    }
    dependencies {
        // replace with the current version of the Android plugin
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}

apply plugin: 'com.android.application'

def AAVersion = 'XXX'
dependencies {
    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 25

        // If you have different applicationIds for buildTypes or productFlavors uncomment this block.
        //javaCompileOptions {
        //    annotationProcessorOptions {
        //        arguments = ["resourcePackageName": android.defaultConfig.applicationId]
        //    }
        //}
    }
}

Upvotes: 0

Andr&#233; B&#228;uml
Andr&#233; B&#228;uml

Reputation: 205

Facing same problem. I solved this by using the default gradle wrapper.

In Android studio settungs -> Build, Execution, Deployment -> Build Tools -> Gradle

Hope this helps

Upvotes: 4

Related Questions