0

I have an android library project which is build using ant. Everything works fine, but I have some test java files there that I do not want to be included in the generated jar file, anybody know how to make that?

Thanks!

Joan P.S
  • 1,553
  • 1
  • 16
  • 42

2 Answers2

1

Android Studio/Gradle allows you to specify classes to exclude from the build; in Android Studio you can exclude classes by editing the build.gradle file and adding a custom SourceSet. Something like this:

android
{
    compileSdkVersion 20
    buildToolsVersion "20.0.4"

    defaultConfig
    {
        minSdkVersion 19
        targetSdkVersion 19
        packageName "org.google.home"
        testPackageName "org.google.home.test"
    }
    sourceSets
    {
        main
        {
            java
            {
                exclude '**/ClassToExclude.java'
            }
        }
        androidTest
        {
            java
            {
                exclude '**/TestforClassToExclude.java'
            }
        }
    }
}

As you can see above, you can exclude both test files (located in you project test directory) and standard source files.

EDIT

For ant you can use something similiar, known as a fileset so specify files that should be exluded from the build. The user manual has an excellent section that describes how to accomplish this: https://ant.apache.org/manual/Types/fileset.html.

ant also provides an <exclude> tag that you can use to specify files to exclude:

<exclude name="**/dir_name_to_exclude/**" />

There is also a stackoverflow post that discusses a similar issue: How to exclude a directory from ant fileset, based on directories contents

Community
  • 1
  • 1
Willis
  • 5,308
  • 3
  • 32
  • 61
0

I finally fi it adding the following lines in the build.xml of my android project:

<target name="-post-compile">
    <jar destfile="bin/myLibrary.jar">
        <zipfileset src="bin/classes.jar" excludes="com/my/package** com/something/unittest/**"/>
    </jar>
</target>

This will remove the unwanted files and update the jar file

Joan P.S
  • 1,553
  • 1
  • 16
  • 42