如何指定为Android库项目多个源目录多个、目录、项目、Android

2023-09-06 00:45:44 作者:妳的愛我不懂

我使用Ant工具来构建Android库项目, 我需要指定多个源目录。

I am using ant tool to build android library project, I need to specify multiple source directory .

我曾尝试通过ant.properties交替增加这些线路文件来指定多个源目录

I have tried to specify multiple source directory by adding these lines alternatively in ant.properties file

source.dir=src:src2    
source.dir=src;src2

但不能建立在两种情况下, 在这两种情况下的的.class 生成,但在创建jar文件,我得到这个错误

but unable to build in both case, in both the cases .class were generated , but while creating jar file i was getting this error

BUILD失败。

C:\ Program Files文件\机器人\ Android的SDK \工具\蚂蚁\ build.xml文件:681​​:执行此行出现以下错误:

C:\ Program Files文件\机器人\ Android的SDK \工具\蚂蚁\ build.xml文件:749:

C:\工作区\机器人\包\测试\ SRC; SRC2不存在

任何一个可以告诉我如何指定多个源目录在 ant.properties 建立的Andr​​oid库项目

can any one tell me How to specify multiple source directory in ant.properties to build Android library projects ?

推荐答案

我已经解决了这个问题,在一个取巧的办法;这是

I have Solved This issue in a tricky way; Here it is

要建库项目在Android中有一个以上的源代码目录,第一次去的 ant.properties 文件(对于Linux是 build.properties ),并添加< STRONG> source.dir

To building library-project in android with more than one source directory, first go to ant.properties file (for linux it is build.properties) and add source.dir

    source.dir=first_source_dir ;second_source_dir ; third_source_dir

有关LIB项目,蚂蚁创建罐库编译的.class 从目录中的文件的斌/班的 out.dir 目录 ant.properties 或 build.properties 文件;

for lib project , ant creates the jar library with compiled .class files from the directory bin/classes of out.dir directory specified in ant.properties or build.properties file;

在创建罐 蚂蚁删除所有的的.java 源文件形成的罐,可加入与罐如果codeR保留任何的.java 源代码中的 out.dir 目录下的文件,并指定源目录.DIR

While creating jar , ant removes all .java source file form the jar, which may be included with the jar if coder keeps any .java source file in out.dir directory, and specify that directory in source.dir ;

现在,以消除那些的.java 源蚂蚁转到 source.dir 使用以下命令目录

Now to removing those .java source ant goes to the source.dir directory with the following command

        <property name="source.absolute.dir" location="${source.dir}" />
        dir="${source.absolute.dir}" 

通过这个命令的蚂蚁实际上是试图走在目录

With this command ant actually trying to go the directory

cd   <your_project_root_dir>/first_source_dir ;second_source_dir ; third_source_dir

这是不是present ...

which is not present ...

解决方法:

步骤1.首先请确保您的源代码目录(source.dir)和建目录(out.dir)是不同的;

step 1. At first make sure that your source directory (source.dir) and build directory ( out.dir ) are different;

步骤2进入C:\ Program Files文件\机器人\ Android的SDK \工具\蚂蚁打开的build.xml 然后转到罐标记

step 2. go to C:\Program Files\Android\android-sdk\tools\ant open build.xml then go to jar tag

    <jar destfile="${out.library.jar.file}">                        
       <fileset dir="${out.classes.absolute.dir}"
         includes="**/*.class"
         excludes="${project.app.package.path}/R.class ${project.app.package.path}/R$*.class ${project.app.package.path}/Manifest.class ${project.app.package.path}/Manifest$*.class ${project.app.package.path}/BuildConfig.class"/>
       <fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" />
   </jar>

现在评论或删除最后的文件集标签中的罐标记

Now comment or remove the last fileset tag in jar tag

    <jar destfile="${out.library.jar.file}">                        
       <fileset dir="${out.classes.absolute.dir}"
            includes="**/*.class"
            excludes="${project.app.package.path}/R.class ${project.app.package.path}/R$*.class ${project.app.package.path}/Manifest.class ${project.app.package.path}/Manifest$*.class ${project.app.package.path}/BuildConfig.class"/>
       <!--fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" /-->
    </jar>

现在生成项目;