androidannotations 在android studio中的使用

apply plugin: ‘com.android.application‘

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.change360.helpdoctor"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘
        }
    }
}

dependencies {
    compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
    compile ‘com.android.support:appcompat-v7:22.1.1‘
    compile ‘com.github.rey5137:material:1.1.0‘
    compile ‘de.greenrobot:eventbus:2.4.0‘
    compile ‘net.steamcrafted:load-toast:1.0.6‘
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        // replace with the current version of the Android plugin
        classpath ‘com.android.tools.build:gradle:1.2.2‘
        // the latest version of the android-apt plugin
        classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.4‘
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}
apply plugin: ‘android-apt‘
def AAVersion = ‘3.3.1‘ // change this to your desired version, for example the latest stable: 3.2

dependencies {
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}

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

        // If you‘re using 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‘
    }
}

上面是在android studio里面的build.gradle文件

下面是Activity中的使用,是不是比以前更清爽了。

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.annotations.ViewById;

@OptionsMenu(R.menu.menu_main)
@EActivity(R.layout.activity_main)
public class MainActivity extends ActionBarActivity {

    @ViewById
    TextView textView;
    @AfterViews
    public  void init(){
        textView.setText("hello world");
    }
    @OptionsItem(R.id.action_settings)
    void myMethod() {
        // You can specify the ID in the annotation, or use the naming convention
    }
}

注意:最后在配置Activity的时候一定要在原有的基础上加上_(配置中是MainActivity_而不是MainActivity)

下面是配置文件

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

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
时间: 2024-08-02 17:31:21

androidannotations 在android studio中的使用的相关文章

AndroidAnnotations在Android Studio中的配置

AndroidAnnotations是一款功能很强大的注解框架,具体使用我就不介绍了,大家可以自行百度了解.在eclipse的配置也比较简单,但是在android studio中的配置好像有点麻烦,看网上介绍的都不行,自己去google查了半天才找到配置方法,这里分享给大家,我的android studio版本是V1.2.2,其他android studio版本没测试过. 打开我们的项目,切换到Project模式,然后选择app目录下面的build.gradle文件,打开它,然后在上面添加 ap

在Android studio中如何把项目放到远程git或从远程git得到项目:

主要记录了在Android studio 中如何把项目放到远程git或从远程得到项目: 因为它已经为我们提供了git插件,所有我们部署一下就可以直接使用了.方法如下: 1.准备:先下载window上的git(在不同的系统下载不同的git),然后安装. 2.在Android studio 里点击:File->Settings(如图1),然后进入Version Control->Git;(如图二)然后点击Test(出现图三表示成功). 图1 图二 图三 3.初始化git项目(git init),操

Android Studio 中 FAILURE: Build failed with an exception. * What went wrong: Execution failed for task &#39;:compileDebugAidl&#39;.的问题解答

Android Studio 中 FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileDebugAidl'.的问题解答 完整的问题提示 Gradle: FAILURE:Build failed with an exception.*What went wrong:Execution failed for task ':compileDebugAidl'.>No

关于Android Studio中启动模拟器时,报VT-x is disabled in BIOS错误的解决办法

有时候在Android Studio中启动一个模拟器去运行程序的时候,会出现下面的错误提示:"Intel HAXM is required to run this AVD,VT-x is disabled in BIOS". 接下来我来说说解决的办法: 1. 首先在SDK Manager中检查是否安装Download Intel x86 Emulator Accelerator (HAXM installer),如果没有安装,则在SDK Manager中下载安装Download Int

在Android Studio 中正确使用adil ”绝对经典“

今天调用远程服务中遇到了一个问题,哎,调了2个小时,后来终于解决,总结来看还是对新的Android Studio 不够熟悉.那么....就可以睡觉啦!!! 在Android Studio中使用进程通信机制adil时一定要注意: 1  Android Studio提供了ADIL的创建规则,我们尽量去遵循这个规则吧,别总对Eclipse念念不忘啦: 2  在按照新建ADIL文件的步骤创建完成文件之后,***一定要在adil目录下级的包名目录中右键run一下,这样工具才会编译并在build中的gene

在Android Studio中创建项目和模拟器

北京电子科技学院 实      验      报      告 课程:移动平台应用开发实践  班级:201592  姓名:杨凤  学号:20159213 成绩:___________  指导老师:娄嘉鹏   实验日期 :2015.11.1 实验名称:           在Android Studio中创建项目和模拟器 实验内容:       1.在Android Studio中创建项目 2.创建并启动Android模拟器 一.实验简介 熟悉Android的开发环境.一些基本的操作技巧以及调试技

android studio中安装git

在android studio中方便的版本控制软件是git,当然还有其他的比如svn,但是和github一起常用算起来git方便很多怎么安装呢?请看下文: 第一步:下载安装git 先在你的电脑上安装git,去git官网上下载,http://www.git-scm.com/download/下载你的电脑对应的版本,安装的时候记住安装的路径比如D:\Git_Install\Git\bin 第二步:android studio 配置git 打开android studio的-----File ----

Android Studio中解决Gradle DSL method not found: &#39;android()&#39;

最近导入as的项目出了这样的问题 这个问题困扰了我很长时间,好吧,搜了半天全都是runProguard的,最后在stackoverflow上搜到解决办法了: http://stackoverflow.com/questions/27735646/android-studio-gradle-dsl-method-not-found-android-error17-0 解决方法: 删掉最外层的build.gradle中的 android { compileSdkVersion 19 buildToo

Android Studio中手动导入Eclipse Project

RT,这应该是很多朋友刚从Eclipse转到Android Studio后遇到最大的一个问题,首先我们需要重新认识AS里面的目录结构,在我前一篇帖子里面也有提到(Android Studio中的Project相当于Eclipse中的Workspace,Module则相当于Eclipse中的Project). 所以我们手动导入Project,其实就是导入AS里面的Module.主要有以下几个步骤: 1.复制build.gradle到需要导入的项目中 2.复制你需要导入的项目至AS Project根