问题
I have an android application project A which depends on an Android Library project B. when i import both the projects in Eclipse,I've notice the Eclipse Builder (probably due to the ADT plugin), that the library project gets compiled and built as b.jar
and stored inside the bin\
folder of project B. It is referenced as b.jar in the classpath of A.
But, while building it with ant,the command ant debug
,the library project B is compiled as classes.jar
.
Is there a way to rename this file as .jar? I tried renaming it in the SDK build.xml,but then project A does not seem to resolve the classes defined in B. Also,the test project for B fails, since the Android dex compiler tries to search for the file classes.jar inside the bin\
folder of the library project.
Thanks,
回答1:
Create a custom_rules.xml file in your project director.
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<target name="-post-compile">
<echo level="info">Renaming jar filename</echo>
<move file="${out.library.jar.file}"tofile="${out.absolute.dir}/${ant.project.name}.jar"/>
</target>
</project>
回答2:
One way to rename the jar
file is to add a custom_rules.xml
file to the project, and override the right property:
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<property name="out.library.jar.file" location="bin/b.jar" />
</project>
If you look for this property name in the SDK's build.xml
, you'll see why this works.
Note: I did not check from which API level the custom_rules.xml
is supported by Android.
回答3:
I added an extra builder to the library project : /bin/cp bin/classes.jar bin/${project_name}.jar
回答4:
The simplest way is added a line to ant.properties:
out.library.jar.file=bin/b.jar
But if project B is referenced by project A in project-A/ant.properties like:
android.library.reference.1=/path/to/project-B
then compiler may complain that it cannot find symbols defined in project B.
来源:https://stackoverflow.com/questions/13002326/renaming-classes-jar-to-project-name-jar-while-building-a-library-project-in-a