Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Android Studio + Gradle issues #899

Closed
ArthurSav opened this issue Jan 23, 2014 · 9 comments
Closed

Android Studio + Gradle issues #899

ArthurSav opened this issue Jan 23, 2014 · 9 comments

Comments

@ArthurSav
Copy link

I've followed every guide out there for installing android annotations in intellij(Android Studio 0.4.2) with gradle.

I did all the basic steps and i can call annotations in my activities but androidManifest.xml can't find MainActivity_

*I can't mark the production source directory as 'Source' , like most guides state since android studio has removed that capability

Any workaround?

@DayS
Copy link
Contributor

DayS commented Jan 23, 2014

On Android Studio, it seems you have to do it with gradle. Change your config for something like this :

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 18
    }

    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java', 'YOUR_OTHER_PRODUCTION_SOURCE_FOLDER']
            resources.srcDirs = ['src/main/res']
            res.srcDirs = ['src/main/res']
        }
    }
}

@ArthurSav
Copy link
Author

Finally, it recognized the MainActivity_. Thanks a lot!

@DayS
Copy link
Contributor

DayS commented Jan 23, 2014

You're welcome. I should update the wiki to explain how to configure AA on Android Studio..

@DayS DayS closed this as completed Jan 23, 2014
@ArthurSav
Copy link
Author

Yeah, that would help a lot since most guides are outdated

@aat-antoine
Copy link

I have the same problem with android-studio 0.4.3. My MainActivity_ is not recognized. I've followed this link https://github.com/excilys/androidannotations/wiki/Building-Project-Gradle but i don't understand where is the problem.

@C0nnector Is there something to configure in android-studio ?

@ArthurSav
Copy link
Author

Ok, this is how i did it:

  • Go to android studio settings and uncheck ''enable annotation proccessing"(if not already). No need to use any settings there
  • go to your build.gradle file, the one that is outside you project. Mine looks like this:
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
        // the latest version of the android-apt plugin
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

Here you add the android-apt plugin, it will do all the work for you and help you install annotations

  • Then, go to your build.gradle file that is INSIDE your project. Mine looks like this:
apply plugin: 'android'

//Make sure you add this to your code. Calls the apt-plugin
apply plugin: 'android-apt'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        packageName "com.annotations.app" //ADD YOUR PACKAGE HERE
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}


//Add this to your code
apt {
    arguments {
        resourcePackageName android.defaultConfig.packageName
        androidManifestFile variant.processResources.manifestFile
    }
}

dependencies {
    compile 'com.android.support:gridlayout-v7:19.0.1'
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:19.0.1'

    //android annotations
    compile 'org.androidannotations:androidannotations-api:3.0.1'
    apt 'org.androidannotations:androidannotations:3.0.1'
}
  • Clean your project and rebuild it. It should work. No need to include locally stuff or mess with any android studio settings. Just add the code to your grade files and happy coding

@aat-antoine
Copy link

Thx a lot ! Now it works by unchecking ''enable annotation proccessing

@snu-smumrik
Copy link

Hi there.
How i can get access to generated files?
For example i can not see PersonItemView_.build(context); from https://github.com/excilys/androidannotations/wiki/Adapters-and-lists
I tryed add
sourceSets { main.java.srcDirs += 'build/source/apt/' }
to build.gradle file that is inside in my project. But it not working for me.

@c0nscience
Copy link

nevermind

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants