First
- Create Android Gradle Empty Project
Second
- Set build.gradle ( Top-level build File )
buildscript {
repositories {
mavenCentral()
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:1.2.3'
// the latest version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
mavenCentral()
mavenLocal()
}
- Set build.gradle ( Application build file )
buildscript {
repositories {
mavenCentral()
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:1.2.3'
// the latest 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: 'com.neenbedankt.android-apt'
def AAVersion = '3.3.2' // change this to your desired version, for example the latest stable: 3.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 "com.juranoaa.sample01"
// You can set optional annotation processing options here, like these commented options:
logLevel 'INFO'
logFile '/var/log/aa.log'
}
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.juranoaa.sample01"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
}
Third
- Set Annotatioin processors
[ File -> Other Settings -> Default Settings... -> Build, Execution, Deployment -> Compiler -> Annotation Processor ]
Checked
Enable annotation processing
Fourth
- Make java class and modify xml file.
package com.juranoaa.sample01;
import android.app.Activity;
import android.widget.EditText;
import android.widget.TextView;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
@EActivity(R.layout.activity_main)
public class AAMainActivity extends Activity {
@ViewById(R.id.myInput)
EditText myInput;
@ViewById(R.id.myTextView)
TextView textView;
@Click(R.id.myButton)
void myButton() {
String name = myInput.getText().toString();
textView.setText("Hello " + name);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/myInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click me!"
/>
<TextView
android:id="@+id/myTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Problem?
P: Not find my class ( ...MyActivity_ )
No comments:
Post a Comment