ant编译android程序,遇到butterknife的特殊处理
来源:互联网 发布:上海华讯网络2018校招 编辑:程序博客网 时间:2024/05/16 01:28
原文链接
Building Project Ant
What you should know before starting
AndroidAnnotations works by generating code at compile time.
AndroidAnnotations provides two jars:
- androidannotations-X.Y.jar is needed to generate the code at compile time. There is no reason to keep this jar at runtime because:
- Its code will never be executed at runtime.
- It makes your APK size bigger than needed.
- androidannotations-X.Y-api.jar only contains the code you need at runtime.
Prerequisites
This tutorial is based on the SDK v19. If you use another version, you may need to adapt this tutorial.
if you don't already have a
build.xml
file, you can easily generate one:
android update project --path "$PROJECT_ROOT$"
How to
Create a new folder at the root of your project (
compile-libs
would be a good candidate) and putandroidannotations-X.Y.jar
in this folder.Put
androidannotations-X.Y-api.jar
in the$PROJECT_ROOT$/libs
Create a
custom_rules.xml
Ant file next to yourbuild.xml
Ant script. Thebuild.xml
script generated by the Android tools automatically importscustom_rules.xml
if it exists. This enables you to customize the build, without having to modifybuild.xml
, which can therefore be easily updated.Add properties for the generated source folder in
custom_rules.xml
<property name="generated.dir" value=".apt_generated" /> <property name="generated.absolute.dir" location="${generated.dir}" /> <property name="java.compilerargs" value="-s '${generated.absolute.dir}'" />
Note: In some case you may have to replace .apt_generated
by gen
to make the whole thing works.
- Override the
-pre-compile
target incustom_rules.xml
<target name="-pre-compile"> <mkdir dir="${generated.absolute.dir}" /> </target>
Override the
-compile
target incustom_rules.xml
Open
$ANDROID_SDK_ROOT$/tools/ant/build.xml
Locate the
-compile
target in this file:
<target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile"> ...</target>
Copy the target and its content into
custom_rules.xml
Modify the classpath when
javac
is invoked by adding a<fileset>
node, and configure javac to generates the sources in a dedicated folder:
<target name="-compile" ...>... <path id="project.javac.classpath"> ...+ <fileset dir="compile-libs" includes="*.jar"/> </path>...</target>
- You should now be able to build you project using ant:
ant clean release
Next steps
- Configure Eclipse or IntelliJ
- Start using AndroidAnnotations
Potential issues
- If you put the two AndroidAnnotations jars in the $PROJECT_ROOT$/libsyou will encounter the following error:
java.lang.IllegalArgumentException: already added: Lcom/googlecode/androidannotations/annotations/AfterViews;
androidannotations-X.Y-api.jar is a subset of androidannotations-X.Y.jar. So each class in androidannotations-X.Y-api.jar is present in androidannotations-X.Y.jar.
This error is thrown when the dx command is invoked and two classes with the same name and package name are detected. To prevent this error you have to move androidannotations-X.Y.jar file away from the $PROJECT_ROOT$/libsfolder.
Anything else? Contact us on the mailing list, or create an issue, and we'll try to help you.
After upgrading the Android SDK, the content of$ANDROID_SDK_ROOT$/tools/ant/build.xml may have changed. Therefore, your ant build may be broken. The solution is to replace the content of the
-compile
target incustom_rules.xml
with the new-compile
target content defined in$ANDROID_SDK_ROOT$/tools/ant/build.xml
<fileset dir="compile-libs" includes="*.jar"/>
这句是删掉的
- ant编译android程序,遇到butterknife的特殊处理
- Ant编译android程序
- Ant编译android程序
- Ant编译android程序
- ant编译android程序
- 使用ant编译android工程遇到的问题
- 用ant编译Android程序
- 使用ant打包android程序遇到OutOfMemoryError
- 证书签发工具程序编译遇到的问题及处理
- butterknife遇到的坑
- ButterKnife遇到的坑
- eclipse编译android程序时遇到的问题总结
- butterknife 使用遇到的问题
- Java程序异常处理的特殊情况
- Java程序异常处理的特殊情况
- 编译android源码遇到错误处理
- 编译ant compile-native遇到的一些问题
- Android ButterKnife 的安装使用和控件为Null处理
- 小米手机价格终超3000元
- 安卓调试时出现两个一模一样的设备
- MATLAB导入xls文件以及cell的使用方法
- linux各个文件夹代表的意义
- mysql 链接远程数据库
- ant编译android程序,遇到butterknife的特殊处理
- redis 数据类型(一)string的使用
- C# GridView自定义表头
- javascript 原生实现 jquery live/delegate
- 使用Ajax向服务器端发送请求
- POJ 1260 Pearls(DP)
- AlarmManager机制和系统唤醒锁的总结
- 游戏服务器到底是什么?
- windows下用eclipse+goclipse插件+gdb搭建go语言开发调试环境