Skip to content

Commit 7cbde08

Browse files
committed
Android 项目集成 AndroidAnnotations 的使用示例.
1 parent e4ebdd3 commit 7cbde08

26 files changed

+453
-4
lines changed

.classpath

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry kind="src" path=".apt_generated">
8+
<attributes>
9+
<attribute name="optional" value="true"/>
10+
</attributes>
11+
</classpathentry>
12+
<classpathentry kind="output" path="bin/classes"/>
13+
</classpath>

.factorypath

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<factorypath>
2+
<factorypathentry kind="WKSPJAR" id="/androidannotations-example/compile-libs/androidannotations-3.0.1.jar" enabled="true" runInBatchMode="false"/>
3+
<factorypathentry kind="PLUGIN" id="org.eclipse.jst.ws.annotations.core" enabled="false" runInBatchMode="false"/>
4+
</factorypath>

.project

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>androidannotations-example</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.apt.aptEnabled=true
3+
org.eclipse.jdt.apt.genSrcDir=.apt_generated
4+
org.eclipse.jdt.apt.reconcileEnabled=true

.settings/org.eclipse.jdt.core.prefs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.6
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.processAnnotations=enabled
12+
org.eclipse.jdt.core.compiler.source=1.6

AndroidManifest.xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.androidkickstarter.app"
3+
android:versionCode="1"
4+
android:versionName="0.1.0" >
5+
6+
<uses-sdk
7+
android:minSdkVersion="8"
8+
android:targetSdkVersion="16" />
9+
10+
11+
12+
<application
13+
android:icon="@drawable/ic_launcher"
14+
android:theme="@style/AppTheme"
15+
android:label="@string/app_name" >
16+
<activity
17+
android:name="MainActivity_"
18+
android:label="@string/app_name" >
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>

README.md

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
androidannotations-example
2-
==========================
3-
4-
AndroidAnnotations Example
1+
# AndroidAnnotations Example
2+
Android 项目集成 [AndroidAnnotations](https://github.com/excilys/androidannotations) 的使用示例.
3+
4+
对于为什么要使用AndroidAnnotations, 它的价值用一句话可以概括: **让你的代码更简洁易懂, 省时省力.**
5+
6+
不明白怎么个简洁易懂法? 觉得有点虚?
7+
8+
那么就请速速围观 [AndroidAnnotations](http://androidannotations.org/), Before -> After 代码量直接减少一半够你大吃一惊了吧!
9+
10+
## 本示例包含功能
11+
1. 基础代码通过 [AndroidKickstartR](http://androidkickstartr.com/) 生成而来
12+
2. AndroidKickstartR目前(2014-05-05)只提供 androidannotations-2.7.1, 手工升级为 androidannotations-3.0.1
13+
3. 能够通过ANT来构建项目, 无需依赖IDE(基于Android的build.xml), 包含集成androidannotations时ProGuard所需的正确配置
14+
4. 当然也可以作为Eclipse项目来运作, 无需关心ANT构建
15+
5. 仅使用了最简单的androidannotations注解功能, 更多实用功能请参考: [AndroidAnnotations Documentation](https://github.com/excilys/androidannotations/wiki)[HelloWorldEclipse](https://github.com/excilys/androidannotations/tree/develop/examples/HelloWorldEclipse)
16+
17+
## 既然有官方示例了, 还要这个项目做什么
18+
主要增强(区别)的地方:
19+
20+
1. 集成了ANT构建项目, 参考[Building Project Ant](https://github.com/excilys/androidannotations/wiki/Building-Project-Ant)
21+
2. 修正官方示例中的 ProGuard 配置, 以及未在[How to configure Proguard for AndroidAnnotations](https://github.com/excilys/androidannotations/wiki/Proguard)中提及的配置项

ant.properties

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is used to override default values used by the Ant build system.
2+
#
3+
# This file must be checked into Version Control Systems, as it is
4+
# integral to the build system of your project.
5+
6+
# This file is only used by the Ant script.
7+
8+
# You can use this to override default values such as
9+
# 'source.dir' for the location of your java source folder and
10+
# 'out.dir' for the location of your output folder.
11+
12+
# You can also use it define how the release builds are signed by declaring
13+
# the following properties:
14+
# 'key.store' for the location of your keystore and
15+
# 'key.alias' for the name of the key to use.
16+
# The password will be asked during the build when you use the 'release' target.
17+
18+
key.store=app.keystore
19+
key.alias=androidannotations-example
20+
21+
key.store.password=123456
22+
key.alias.password=123456

app.keystore

1.22 KB
Binary file not shown.

build.xml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project name="androidannotations-example" default="help">
3+
4+
<!-- The local.properties file is created and updated by the 'android' tool.
5+
It contains the path to the SDK. It should *NOT* be checked into
6+
Version Control Systems. -->
7+
<property file="local.properties" />
8+
9+
<!-- The ant.properties file can be created by you. It is only edited by the
10+
'android' tool to add properties to it.
11+
This is the place to change some Ant specific build properties.
12+
Here are some properties you may want to change/update:
13+
14+
source.dir
15+
The name of the source directory. Default is 'src'.
16+
out.dir
17+
The name of the output directory. Default is 'bin'.
18+
19+
For other overridable properties, look at the beginning of the rules
20+
files in the SDK, at tools/ant/build.xml
21+
22+
Properties related to the SDK location or the project target should
23+
be updated using the 'android' tool with the 'update' action.
24+
25+
This file is an integral part of the build system for your
26+
application and should be checked into Version Control Systems.
27+
28+
-->
29+
<property file="ant.properties" />
30+
31+
<!-- if sdk.dir was not set from one of the property file, then
32+
get it from the ANDROID_HOME env var.
33+
This must be done before we load project.properties since
34+
the proguard config can use sdk.dir -->
35+
<property environment="env" />
36+
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
37+
<isset property="env.ANDROID_HOME" />
38+
</condition>
39+
40+
<!-- The project.properties file is created and updated by the 'android'
41+
tool, as well as ADT.
42+
43+
This contains project specific properties such as project target, and library
44+
dependencies. Lower level build properties are stored in ant.properties
45+
(or in .classpath for Eclipse projects).
46+
47+
This file is an integral part of the build system for your
48+
application and should be checked into Version Control Systems. -->
49+
<loadproperties srcFile="project.properties" />
50+
51+
<!-- quick check on sdk.dir -->
52+
<fail
53+
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
54+
unless="sdk.dir"
55+
/>
56+
57+
<!--
58+
Import per project custom build rules if present at the root of the project.
59+
This is the place to put custom intermediary targets such as:
60+
-pre-build
61+
-pre-compile
62+
-post-compile (This is typically used for code obfuscation.
63+
Compiled code location: ${out.classes.absolute.dir}
64+
If this is not done in place, override ${out.dex.input.absolute.dir})
65+
-post-package
66+
-post-build
67+
-pre-clean
68+
-->
69+
<import file="custom_rules.xml" optional="true" />
70+
71+
<!-- Import the actual build file.
72+
73+
To customize existing targets, there are two options:
74+
- Customize only one target:
75+
- copy/paste the target into this file, *before* the
76+
<import> task.
77+
- customize it to your needs.
78+
- Customize the whole content of build.xml
79+
- copy/paste the content of the rules files (minus the top node)
80+
into this file, replacing the <import> task.
81+
- customize to your needs.
82+
83+
***********************
84+
****** IMPORTANT ******
85+
***********************
86+
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
87+
in order to avoid having your file be overridden by tools such as "android update project"
88+
-->
89+
<!-- version-tag: 1 -->
90+
<import file="${sdk.dir}/tools/ant/build.xml" />
91+
92+
</project>
603 KB
Binary file not shown.

custom_rules.xml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project name="custom_rules">
3+
<!-- 通过 androidannotations APT 来生成代码 -->
4+
<!-- https://github.com/excilys/androidannotations/wiki/Building-Project-Ant -->
5+
<property name="generated.dir" value=".apt_generated" />
6+
<property name="generated.absolute.dir" location="${generated.dir}" />
7+
<property name="java.compilerargs" value="-s &apos;${generated.absolute.dir}&apos;" />
8+
9+
<target name="-pre-compile">
10+
<echo level="info">Creating APT output dir: ${generated.absolute.dir}</echo>
11+
<mkdir dir="${generated.absolute.dir}" />
12+
</target>
13+
14+
<!-- Compiles this project's .java files into .class files. -->
15+
<target name="-compile" depends="-pre-build, -build-setup, -code-gen, -pre-compile">
16+
<do-only-if-manifest-hasCode elseText="hasCode = false. Skipping...">
17+
<!-- merge the project's own classpath and the tested project's classpath -->
18+
<path id="project.javac.classpath">
19+
<path refid="project.all.jars.path" />
20+
<path refid="tested.project.classpath" />
21+
<fileset dir="compile-libs" includes="*.jar"/>
22+
</path>
23+
<javac encoding="${java.encoding}"
24+
source="${java.source}" target="${java.target}"
25+
debug="true" extdirs="" includeantruntime="false"
26+
destdir="${out.classes.absolute.dir}"
27+
bootclasspathref="project.target.class.path"
28+
verbose="${verbose}"
29+
classpathref="project.javac.classpath"
30+
fork="${need.javac.fork}">
31+
<src path="${source.absolute.dir}" />
32+
<src path="${gen.absolute.dir}" />
33+
<compilerarg line="${java.compilerargs}" />
34+
</javac>
35+
36+
<!-- if the project is instrumented, intrument the classes -->
37+
<if condition="${build.is.instrumented}">
38+
<then>
39+
<echo level="info">Instrumenting classes from ${out.absolute.dir}/classes...</echo>
40+
41+
<!-- build the filter to remove R, Manifest, BuildConfig -->
42+
<getemmafilter
43+
appPackage="${project.app.package}"
44+
libraryPackagesRefId="project.library.packages"
45+
filterOut="emma.default.filter"/>
46+
47+
<!-- define where the .em file is going. This may have been
48+
setup already if this is a library -->
49+
<property name="emma.coverage.absolute.file" location="${out.absolute.dir}/coverage.em" />
50+
51+
<!-- It only instruments class files, not any external libs -->
52+
<emma enabled="true">
53+
<instr verbosity="${verbosity}"
54+
mode="overwrite"
55+
instrpath="${out.absolute.dir}/classes"
56+
outdir="${out.absolute.dir}/classes"
57+
metadatafile="${emma.coverage.absolute.file}">
58+
<filter excludes="${emma.default.filter}" />
59+
<filter value="${emma.filter}" />
60+
</instr>
61+
</emma>
62+
</then>
63+
</if>
64+
65+
<!-- if the project is a library then we generate a jar file -->
66+
<if condition="${project.is.library}">
67+
<then>
68+
<echo level="info">Creating library output jar file...</echo>
69+
<property name="out.library.jar.file" location="${out.absolute.dir}/classes.jar" />
70+
<if>
71+
<condition>
72+
<length string="${android.package.excludes}" trim="true" when="greater" length="0" />
73+
</condition>
74+
<then>
75+
<echo level="info">Custom jar packaging exclusion: ${android.package.excludes}</echo>
76+
</then>
77+
</if>
78+
79+
<propertybyreplace name="project.app.package.path" input="${project.app.package}" replace="." with="/" />
80+
81+
<jar destfile="${out.library.jar.file}">
82+
<fileset dir="${out.classes.absolute.dir}"
83+
includes="**/*.class"
84+
excludes="${project.app.package.path}/R.class ${project.app.package.path}/R$*.class ${project.app.package.path}/BuildConfig.class"/>
85+
<fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" />
86+
</jar>
87+
</then>
88+
</if>
89+
90+
</do-only-if-manifest-hasCode>
91+
</target>
92+
</project>

libs/androidannotations-api-3.0.1.jar

85.3 KB
Binary file not shown.

local.properties

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must *NOT* be checked into Version Control Systems,
5+
# as it contains information specific to your local configuration.
6+
7+
# location of the SDK. This is only used by Ant
8+
# For customization when using a Version Control System, please read the
9+
# header note.
10+
sdk.dir=D:\\Program Files\\android-sdk-windows

proguard-project.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}
21+
22+
# ignore androidannotations depend 3rd jars warnings
23+
-dontwarn org.androidannotations.**

project.properties

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-17

res/drawable-hdpi/ic_launcher.png

3.73 KB
Loading

res/drawable-ldpi/ic_launcher.png

1.64 KB
Loading

res/drawable-mdpi/ic_launcher.png

2.28 KB
Loading

res/drawable-xhdpi/ic_launcher.png

4.44 KB
Loading

0 commit comments

Comments
 (0)