如何为Android库项目指定多个源目录 [英] How to specify multiple source directory for Android library project

查看:30
本文介绍了如何为Android库项目指定多个源目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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

构建失败

C:\Program Files\Android\android-sdk\tools\ant\build.xml:681: 执行此行时出现以下错误:

C:\Program Files\Android\android-sdk\tools\ant\build.xml:749:

C:\workarea\Android\Packages\test\src;src2 不存在.

谁能告诉我如何在ant.properties中指定多个源目录来构建Android库项目?

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)并添加 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 项目,ant 使用目录 bin/classes 中编译的 .class 文件创建 jar 库> 在 ant.propertiesbuild.properties 文件中指定的 out.dir 目录;

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;

在创建 jar 时,antjar 中删除所有 .java 源文件,其中可能包含如果编码器在 out.dir 目录中保留任何 .java 源文件,则使用 jar,并在 source.dir<中指定该目录/strong>;

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 ;

现在删除那些 .javaant 使用以下命令转到 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}" 

使用这个命令ant实际上试图去目录

With this command ant actually trying to go the directory

cd   <your_project_root_dir>/first_source_dir ;second_source_dir ; third_source_dir

不存在...

解决方案:

第一步.首先确保你的源目录(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\android-sdk\tools\ant 打开 build.xml然后转到 jar 标签

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>

现在注释或删除 jar 标签中的最后一个 fileset 标签

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>

现在构建你的项目;

这篇关于如何为Android库项目指定多个源目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆