Android Studio: Use AndroidAnnotations

后端 未结 6 747
梦毁少年i
梦毁少年i 2020-12-28 18:12

So I wanted to try the new Android Studio and imported my eclipse projects (I generated a gradle build file). Worked pretty good.

The only library which does not see

相关标签:
6条回答
  • 2020-12-28 18:27

    I had the same issues, followed the instructions for configuring aa with intelliJ, now it works like a charm does.

    AA intelliJ config page will point you to this post...

    http://www.ashokgelal.com/2012/12/setting-up-intellij-idea-12-with-maven-actionbarsherlock-roboelectric-androidannotations/

    ...the above post walks you through setting up various libs in intelliJ, scroll towards the bottom for AA.

    The main thing I had to do that I did not have to do in eclipse was go to Preferences > Compiler > Annotation Processors and set my Processor Path to something like...

    [PATH TO AA JARS]/androidannotations-2.7.jar:[PATH TO AA JARS]/androidannotations-api-2.7.jar:[PATH TO AA JARS]/codemodel-2.4.1.jar

    0 讨论(0)
  • 2020-12-28 18:31

    As Android Studio is based on IntelliJ did you try to follow the configuration guideline on AndroidAnnotation's wiki ?

    If you're using gradle you should check this page which explains how to configure the AndroidAnnotation's plugin :

    buildscript {
        repositories {
            mavenCentral()
        }
    
        def gradleAndroidAnnotationsPluginVersion = '0.3.0'
    
        dependencies {
            classpath "net.ealden.gradle.plugins:gradle-androidannotations-plugin:$gradleAndroidAnnotationsPluginVersion"
        }
    }
    
    apply plugin: 'androidannotations'
    apply plugin: 'idea'
    
    androidAnnotationsVersion = '2.2'
    

    I didn't try this new IDE yet. I'll check that soon.

    0 讨论(0)
  • 2020-12-28 18:31

    If you try to use Android Studio with a project running Android Annotations, you may run into a cryptic compiler issue:

    incorrectly typed data found for annotation element public abstract int com.googlecode.androidannotations.annotations.EActivity.value() (Found data of type int)

    Problem is the R class is not found. Android Studio doesn't place the R.java into the gen directory by default like eclipse. The solution is to go into Project Settings -> Facets -> Select the Android facet for your project -> Compiler tab, and change the "R.java and Manifest.java files" from "Run process-resources Maven task before Make" to "Generated by IDE".

    0 讨论(0)
  • 2020-12-28 18:39

    It seems there is a way of making Android Studio work with AndroidAnnotations

    http://code.google.com/p/android/issues/detail?id=55764

    0 讨论(0)
  • 2020-12-28 18:44

    This is what works for me:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.5.+'
        }
    }
    
    apply plugin: 'android'
    
    configurations {
        apt
    }
    
    repositories {
        mavenRepo url: 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
    
    ext.androidAnnotationsVersion = '3.0-SNAPSHOT';
    
    dependencies {
        compile 'com.android.support:support-v4:18.0.+'
    
        apt "org.androidannotations:androidannotations:$ext.androidAnnotationsVersion"
        compile "org.androidannotations:androidannotations-api:$ext.androidAnnotationsVersion"
    }
    
    android {
        compileSdkVersion 18
        buildToolsVersion "17.0.0"
    
        defaultConfig {
            minSdkVersion 7
            targetSdkVersion 18
        }
    }
    
    android.applicationVariants.all { variant ->
        ext.aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")
        ext.aptOutput.mkdirs()
    
        variant.javaCompile.options.compilerArgs += [
                '-processorpath', configurations.apt.asPath,
                '-AandroidManifestFile=' + variant.processResources.manifestFile,
                '-s', ext.aptOutput
        ]
    }
    

    After that I need to mark build/sources/apt-generated/debug as source in Android Studio by right clicking it and selecting Mark Directory as > Source Root

    0 讨论(0)
  • 2020-12-28 18:50

    If you don't have problems compiling and just after seeing the generated classes in the IDE, then you need to check if target/generated-sources/annotations is checked as Source Folder.

    That would be File > Project Structure > Modules > Sources Tab, then look for the folder and tag it as Sources. The folder will turn blue and will be listed on the Source Folder list.

    0 讨论(0)
提交回复
热议问题