1 Reply Latest reply on Aug 13, 2010 12:34 AM by Sankar Kethineni

    Problem in optimizing Flex application using ANT script

    Sankar Kethineni

      Dear folks,

       

            I have a Flex (SDK  version: 3.3.0.4852) project created with 3 modules and also using the framework RSL's to reduce the size of the main application swf size, as you all know that to reduce the initial load time of the application. In my project, the modules are kind of mini applications, optimized for the application and they are medium in size.

       

        By using the Flex Builder options, i have adopted these optimization techniques for my project. And after implementing these techniques the size of the main Application SWF size is 1.4MB and the modules swf size are 51KB, 51KB and 50.9KB respectively. The framework RSL file sizes are 550KB, 553KB respectively.

       

        Now am trying to make the GUI build process as automation by writing the ANT Script. When am compiling the flex project with the help of ant script, the main application swf size become 2.0MB and modules swf sizes become 1.7MB, 1.7MB, 1.7 MB.

       

        I don't have any clue on why the application and as well as the modules swf sizes got increased. Please, find the attchment of build.xml of my flex project. Please correct me, if any thing went wrong in build.xml in optimizing the modules for application and in using the framework RSLs.

       

      Any kind of help would be appreciated. Thanks in advance.

       


      Here is the build.xml....

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <project name="Flex Application using Ant script"
               default="compile">

       

          <!-- load previously defined configuration properties file -->
          <property file="build.properties"/>

       

          <!-- points to our flexTasks.jar we copied to the libs folder to distribute with the project -->
          <taskdef resource="flexTasks.tasks"
                   classpath="${LIBS_DIR}/flexTasks.jar"/>

       

          <!-- This is what you have to include to be able to use the "foreach" ant task -->
          <taskdef resource="net/sf/antcontrib/antlib.xml">
              <classpath>
                  <pathelement location="${LIBS_DIR}/ant-contrib-1.0b3.jar"/>
              </classpath>
          </taskdef>

       

          <!-- Build and output the Main swf-->
          <target name="compile"
                  depends="init,compileApplication,compileModules,copyImages,copyRSLs">
          </target>

       

          <!-- delete and create the DEPLOY directory again -->
          <target name="init">
              <delete dir="${DEPLOY_DIR}"/>
              <mkdir dir="${DEPLOY_DIR}"/>       
          </target>

       

          <!-- Compile Application file -->
          <target name="compileApplication">
              <mxmlc file="${SRC_DIR}/${APPLICATION_FILE}.mxml"
                     output="${DEPLOY_DIR}/${APPLICATION_FILE}.swf"
                     actionscript-file-encoding="UTF-8"
                     keep-generated-actionscript="false"
                     debug="false">

       

                  <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
                  <source-path path-element="${FLEX_HOME}/frameworks"/>
                  <compiler.include-libraries dir="${LIBS_DIR}"
                                              append="true">
                      <include name="*.swc"/>               
                  </compiler.include-libraries>

       

                  <!-- Using Runtime Shared Libraries -->
                  <runtime-shared-library-path path-element="${FLEX_FRAMEWORK}/framework.swc">
                      <url rsl-url="${FRAMEWORK_VERSION}.swz"/>
                      <url rsl-url="${FRAMEWORK_VERSION}.swf"/>
                  </runtime-shared-library-path>
              </mxmlc>
          </target>

       

          <!-- Compile Modules -->
          <target name="compileModules">
              <pathconvert property="flex.modules"
                           pathsep=",">
                  <fileset dir="${MODULE_DIR}">
                      <include name="**/*.mxml"/>
                  </fileset>

       

                  <!-- Strips the module name out of the full path to the module -->
                  <compositemapper>
                      <mapper type="regexp"
                              from="^(.*)[\\|/](.*)(\.mxml)$$"
                              to="\2"/>
                  </compositemapper>
              </pathconvert>

       

              <echo>Modules that are found in current project are: ${flex.modules}</echo>

       

              <!-- Calls the "compileModule" target and gives it the parameter "moduleName" -->
              <foreach list="${flex.modules}"
                       delimiter=","
                       parallel="false"
                       param="moduleName"
                       trim="true"
                       target="compileModule"/>

       

          </target>

       

          <target name="compileModule">
              <echo>Compiling ${moduleName} ...</echo>

       

              <!-- Get the package path to the module from the full path -->
              <pathconvert property="module.path"
                           pathsep=",">

       

                  <fileset dir="${MODULE_DIR}">
                      <include name="**/*.mxml"/>
                  </fileset>

       

                  <compositemapper>
                      <mapper type="regexp"
                              from="^(.*)[\\|/](src)[\\|/](.*)[\\|/](${moduleName}\.mxml)$$"
                              to="\3"/>
                  </compositemapper>
              </pathconvert>

       

              <mxmlc file="${MODULE_DIR}/${moduleName}.mxml"
                     output="${DEPLOY_DIR}/${module.path}/${moduleName}.swf"
                     actionscript-file-encoding="UTF-8"
                     keep-generated-actionscript="false"
                     optimize="true"
                     debug="false"
                     incremental="false">
                  <!-- Get default compiler options. -->
                  <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>

       

                  <!-- List of path elements that form the roots of ActionScript class hierarchies. -->
                  <source-path path-element="${FLEX_HOME}/frameworks"/>
                  <compiler.source-path path-element="src"/>

       

                  <!-- List of SWC files or directories that contain SWC files. -->
                  <!--<compiler.library-path dir="${FLEX_HOME}/frameworks"
                                         append="true">
                      <include name="libs"/>
                      <include name="../bundles/{locale}"/>
                  </compiler.library-path> -->

       

                  <library-path dir="${LIBS_DIR}"
                                append="true">
                      <include name="*.swc"/>
                  </library-path>
              </mxmlc>
          </target>

       

          <!-- Copy RSLs -->
          <target name="copyRSLs">
              <copy todir="${DEPLOY_DIR}"
                    file="${FLEX_HOME}/frameworks/rsls/${FRAMEWORK_VERSION}.swf"/>
              <copy todir="${DEPLOY_DIR}"
                    file="${FLEX_HOME}/frameworks/rsls/${FRAMEWORK_VERSION}.swz"/>
          </target>

       

          <!-- Copy Images -->
          <target name="copyImages">       
              <copy todir="${DEPLOY_DIR}/${IMAGE_PATH}">
                  <fileset dir="${SRC_DIR}/${IMAGE_PATH}"
                           includes="images/,swf/"/>
              </copy>
          </target>

       

      </project>

        • 1. Re: Problem in optimizing Flex application using ANT script
          Sankar Kethineni Level 1

          Hi Friends,

           

            Myself found the solution for this problem. I have done 2 changes here, which helped me in optimizing the modules for the application and as well as application SWF size.

           

          Here are the changes...

           

          1) use link-report option for the application mxmlc compiler - which will make a note of  CLASSES that are used in Application & it's components

           

                  and use load-externs option for the module mxmlc compiler - which will exclude the common classes from module files as they are already available in application.

           

          2) use <library-path .../> instead of  <compiler.include-libraries ..../> - which will help you in optimizing the Application SWF size.

           

          Here is the revised build.xml............

           

              ...............

           

              <!-- Compile Application file -->
              <target name="compileApplication">
                  <mxmlc file="${SRC_DIR}/${APPLICATION_FILE}.mxml"
                         output="${DEPLOY_DIR}/${APPLICATION_FILE}.swf"
                         actionscript-file-encoding="UTF-8"
                         keep-generated-actionscript="false"
                         debug="false"

                        link-report="c:/link-report.xml">

           

                      <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
                      <source-path path-element="${FLEX_HOME}/frameworks"/>

                      <!-- Referring to third party SWC libraries -->

           

                      Please Do Not Use this  - This tag will include all the libraries as part of  Application SWF.

                      <!-- <compiler.include-libraries dir="${LIBS_DIR}"
                                                  append="true">
                          <include name="*.swc"/>               
                      </compiler.include-libraries> -->

           

                      Please Use this  - This tag will just make reference to libraries while compiling the project & will not include in the Application SWF

                      <library-path dir="${LIBS_DIR}"
                                    append="true">
                          <include name="*.swc"/>
                      </library-path>

           

                   ................

                    
                  </mxmlc>
              </target>

           

              .........

           

              <!-- Compile Module -->

              <target name="compileModule">
                  <echo>Compiling ${moduleName} module ...</echo>       
                  .......
                  <mxmlc file="${MODULE_DIR}/${moduleName}.mxml"
                         output="${DEPLOY_DIR}/${module.path}/${moduleName}.swf"
                         keep-generated-actionscript="false"
                         optimize="true"
                         debug="false"
                         load-externs="c:/link-report.xml">
                  ..............           
                  </mxmlc>
              </target>