Using ANT with Flex, building dependent target fails - apache-flex

I have a flex project called framework and another one called commons. Commons depends on framework.
Build script for framework :
<project name="imanager-framework" basedir=".">
<property name="src" location="src"/>
<property name="dist" location="dist"/>
<property name="FLEX_HOME" value="C:/Program Files (x86)/Adobe/Adobe Flash Builder 4.5/sdks/4.6.0"/>
<taskdef resource="flexTasks.tasks" classpath="${basedir}/libs/flexTasksFlash4.jar"/>
<target name="clean">
<delete dir="${dist}"/>
</target>
<target name="dist">
<echo>src dir: ${src}</echo>
<mkdir dir="${dist}"/>
<compc output="${dist}/${ant.project.name}.swc">
<source-path path-element="src" />
<library-path dir="libs" includes="*.swc" append="true"/>
<include-sources dir="${src}" includes="*" />
</compc>
</target>
</project>
Build script for commons :
<?xml version="1.0" encoding="UTF-8"?>
<project name="imanager-commons" basedir=".">
<property name="src" location="src"/>
<property name="dist" location="dist"/>
<property name="FLEX_HOME" value="C:/Program Files (x86)/Adobe/Adobe Flash Builder 4.5/sdks/4.6.0"/>
<taskdef resource="flexTasks.tasks" classpath="${basedir}/libs/flexTasksFlash4.jar"/>
<target name="clean">
<delete dir="${dist}"/>
</target>
<target name="init">
<echo>Running Target: init</echo>
<echo>Running ant dist on framework</echo>
<!-- THIS PART FAILS --> <ant dir="../framework/" target="dist" inheritall="false"/>
<copy file="../framework/dist/imanager-framework.swc" todir="libs"/>
</target>
<target name="dist" depends="init">
<mkdir dir="${dist}"/>
<compc output="${dist}/${ant.project.name}.swc">
<source-path path-element="src" />
<library-path dir="libs" includes="*.swc" append="true"/>
<include-sources dir="${src}" includes="*" />
</compc>
</target>
</project>
Calling <ant> from the commons build file gives me spurious compile errors about bad imports and classes not being found. But running framework's build separately doesn't give any errors.
Here's some of the output I get
Buildfile: E:\flexspace\imanager\commons\build.xml
init:
[echo] Running Target: init
[echo] Running ant dist on framework
Trying to override old definition of task asdoc
Trying to override old definition of task compc
Trying to override old definition of task mxmlc
Trying to override old definition of task html-wrapper
dist:
[echo] src dir: E:\flexspace\imanager\framework\src
[compc] Loading configuration file C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.5\sdks\4.6.0\frameworks\flex-config.xml
...some warnings from my code here...
[compc] E:\flexspace\imanager\framework\src\com\iwobanas\controls\dataGridClasses\MDataGridColumn.as(72): col: 88 Error: Access of undefined property WildcardFilterEditor in package com.iwobanas.controls.dataGridClasses.filterEditors.
[compc] filterEditor = new ClassFactory(com.iwobanas.controls.dataGridClasses.filterEditors.WildcardFilterEditor);
[compc] ^
[compc] E:\flexspace\imanager\framework\src\com\iwobanas\controls\dataGridClasses\MDataGridColumn.as(24): col: 60 Error: Definition com.iwobanas.controls.dataGridClasses.filterEditors:WildcardFilterEditor could not be found.
[compc] import com.iwobanas.controls.dataGridClasses.filterEditors.WildcardFilterEditor;
[compc] ^
[compc] E:\flexspace\imanager\framework\src\org\syspire\erp\component\tooltip\components\ExtendedToolTip.as(3): col: 48 Error: Definition org.syspire.erp.component.tooltip.skins:ExtendedToolTipSkin could not be found.
[compc] import org.syspire.erp.component.tooltip.skins.ExtendedToolTipSkin;
[compc] ^
[compc] E:\flexspace\imanager\framework\src\org\astrika\shared\components\gridSearch\view\SearchDatePopup.mxml(14): Error: Type was not found or was not a compile-time constant: SearchDateView.
[compc] <gridSearch:SearchDateView id="searchDateView"/>
...similar errors...
BUILD FAILED
E:\flexspace\imanager\commons\build.xml:17: The following error occurred while executing this line:
E:\flexspace\imanager\framework\build.xml:17: compc task failed
Total time: 4 seconds
What's going wrong here?
Thanks
EDIT
As requested, here are the config dumps:
Framework build using Flash Builder: http://pastebin.com/kLai6j7X
Framework build using ANT: http://pastebin.com/FGHBAXZX
Framework build called from commons using ANT: (This is same as the previous dump)
UPDATE
I ended up just changing the structure of my build files to eliminate the <ant> call. I now how one build.xml for all the projects, will all targets in it. Not pretty, but it works for me.

It's a bit off-topic but I found Ant does bad at managing the build of Flex projects, especially when you have dependencies.
Have you considered using Maven with FlexMojos ? Adobe released a series of articles about this great tool. Much recommended !

One thing you can definitely try is to move the taskdef into target, at least that'll get rid of "Trying to override old definition of task" warning.

Related

Flex Ant: Compile multiple module

I am trying to compile my project by using Ant.
I did. But I have some problem. I don't know how to resolve.
<!-- Compile Modules (S) -->
<target name="compileModules" depends="compileBLP">
<record name="${LOG_DIR}/LOG_${CURR_TIME_SUBFIX}${LOG_FILE_TYPE}" append="false" action="start" />
<cpmdl file="com/dou/pi/views/dm/Module1" />
<cpmdl file="com/dou/pi/views/pim/Module2" />
<record name="${LOG_DIR}/LOG_${CURR_TIME_SUBFIX}${LOG_FILE_TYPE}" action="stop" />
</target>
<!-- Compile Modules (E) -->
<macrodef name="cpmdl">
<attribute name="file" />
<sequential>
<echo>#{file}</echo>
<mxmlc file="${SRC_DIR}/#{file}.mxml" output='${DEPLOY_DIR}/#{file}.swf' optimize="true" debug="false" incremental="false" fork="true">
<compiler.source-path path-element="${SRC_DIR}" />
<source-path path-element="${FLEX_HOME}/frameworks" />
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs" />
</compiler.library-path>
<compiler.library-path dir="${basedir}" append="true">
<include name="libs" />
<include name="src/assets/swc" />
</compiler.library-path>
<source-path path-element="${SRC_DIR}" />
</mxmlc>
</sequential>
</macrodef>
You can see. If I compile 2 modules, I have to load file config 2 times.
[mxmlc] Loading configuration file C:\Program Files\Adobe\Adobe Flash Builder 4 Plug-in\sdks\4.1.0\frameworks\flex-config.xml
[mxmlc] D:\Projects\BLP\BUILD\DEPLOY\com\dou\pi\views\dm\Module1.swf (1233413 bytes)
[mxmlc] Loading configuration file C:\Program Files\Adobe\Adobe Flash Builder 4 Plug-in\sdks\4.1.0\frameworks\flex-config.xml
[mxmlc] D:\Projects\BLP\BUILD\DEPLOY\com\dou\pi\views\pim\Module2.swf (963045 bytes)
Maybe, that is not good.
I though, can we load it just 1 time?
Hope you can give me any suggestion.
Thanks.
There's really nothing to be done here. The loading of the config file is done internally by mxmlc, not ant. Remember, each time you call mxmlc in your ant script, it's launching a new instance of it, so each instance has to load the configuration for itself.
It's similar to how, if you launch your web browser, close it, and reopen it, you'll end up loading your homepage twice. There's nothing in the environment that can save the page to memory to pass it in to the second invocation of the program.

Getting ant build error "Unable to locate specified base class 'mx.core.Application' for component

I am trying to build using ant a Flex 3.5 app, and I keep on getting the error:
Unable to locate specified base class 'mx.core.Application' for component class 'main'.
my build.xml file looks something like:
<project name="ASC App" default="compile flex project">
<!-- 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="${basedir}/libs/flexTasks.jar"/>
<!-- delete and create the DEPLOY dir again -->
<target name="init">
<delete dir="${DEPLOY_DIR}" />
<mkdir dir="${DEPLOY_DIR}" />
</target>
<!-- Build and output the Main.swf-->
<target name="compile flex project" depends="init">
<mxmlc file="src/main.mxml" output="${DEPLOY_DIR}/main.swf">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="${APP_COMMON}"/>
<source-path path-element="${FLEX_COMMON}"/>
<library-path dir="${LIBS_DIR}/AlivePDF/" append="true"/>
<library-path dir="${LIBS_DIR}" append="true"/>
<compiler.debug>false</compiler.debug>
</mxmlc>
</target>
and my build.properties:
# Application name
APP_NAME=AS App
# SWF file
APP=main
# Common library
APP_COMMON=../ASC_common
FLEX_COMMON=../common
ALIVE_PDF=../libraries/AlivePDF/SWC/AlivePDF
# change this to your Flex SDK directory path
FLEX_HOME=/SDKs/flex_sdk_3_4
# this points to your project's src directory
SRC_DIR =${basedir}/src
# points to the project's libs directory
LIBS_DIR =${basedir}/libs
# this is the folder we want to publish the swf to
DEPLOY_DIR = ${basedir}/DEPLOY
Your help would be very much appreciated!
I am trying to build using ant a Flex 3.5 app
Yet you have
FLEX_HOME=/SDKs/flex_sdk_3_4

Could not load definitions from resource flexTasks.tasks. It could not be found

I'm attempting to compile a Flex application from an ANT script, inside of Eclipse (CFBuilder, based on Eclipse), and I've run into this error:
Could not load definitions from resource flexTasks.tasks. It could not be found.
I haven't been able to find anything that gives directions on where this file (flexTasks.tasks) should be copied to, if it's needed at all. Some places indicate that it should be part of the flexTasks.jar file. I've tried two different things:
Copy the jar file into the ant/plugins/lib folder (and restart my CF Builder instance)
Specify the path to the jar in the classpath attribute, as suggested by the comment on this page
Neither helps me get past this error.
Here's my build script, for reference:
<project name="Tagging" default="compile-tagging" basedir=".">
<!-- setup flex compilation capability -->
<taskdef resource="flexTasks.tasks" />
<property name="flex.src" value="./src" />
<property name="flex.bin" value="./bin"/>
<target name="compile-tagging">
<mxmlc
file="${flex.src}/main.mxml"
output="${flex.bin}/main.swf"
keep-generated-actionscript="true">
<source-path path-element="${FLEX_HOME}/frameworks" />
</mxmlc>
</target>
</project>
Adam, I believe you need to tell taskdef where to look for the file. try keeping flextasks.jar in the same directory as your ant file (for now... you can move it later after you get it working).
then, you can do something like this:
<taskdef name="mxmlc" classname="WhateverTheTaskIsNamed" classpath="flexTAsks.jar" />
While not ideal, this code is working for me at the moment:
<project name="IOLTagging" default="go" basedir=".">
<!-- setup flex compilation capability -->
<property name="FLEX_HOME" value="C:/program files (x86)/Adobe/Adobe Flash Builder Beta 2/sdks/3.4.1/" />
<taskdef name="mxmlc" classname="flex.ant.MxmlcTask" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<taskdef name="html-wrapper" classname="flex.ant.HtmlWrapperTask" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<property name="flex.src" value="./src" />
<property name="flex.bin" value="./bin"/>
<property name="swf.name" value="main" />
<target name="go" depends="compile-flex" />
<target name="compile-flex">
<mxmlc
file="${flex.src}/main.mxml"
output="${flex.bin}/${swf.name}.swf"
debug="false"
keep-generated-actionscript="false">
<source-path path-element="${FLEX_HOME}/frameworks" />
<compiler.library-path dir="${basedir}/libs" append="true">
<include name="*.swc" />
</compiler.library-path>
</mxmlc>
</target>
</project>
I had the same problem, and the reason was in lack of permissions to acces $FLEX_HOME/ant.
You can also put the flexTasks.jar in ~/.ant/lib directory
If you run ant -diagnostics you should see the jar in USER_HOME/.ant/lib jar listing
I think you should have solved this problem. just trying flexmonkey today and also got the same problem.
"Could not load definitions from resource flexTasks.tasks. It could not be found."
solution is to make sure the flexTasks.jar is included in the dir lib of your project workplace.
when I copied flexTasks.jar from flashbuild folder \ant\lib and built it again. the problem is fixed.

How can I automate the building of a Flex component library?

I would like to build a flex library project automatically instead of the current process, which involves one of our developers compiling it on his machine and then us checking in the resulting .swc file. It's gross.
I am coming at this from the perspective of a java developer, so I'm having a hard time getting the hang of the compilation tools provided in the Flex Builder 3 application, but here's what I already have:
I have created an ant file that loads the ant task library correctly, and can therefore execute <mxmlc/> and <compc/> tasks.
I have located the source code that I need to build, and know what sort of .swc I want to end up with.
What I want is an ant script that will do the equivalent of these steps:
We build all sources (actionscript and MXML) and assets in the project into an swc file.
The library.swf file is extracted and optimized
So far I have this:
<target name="compile-component" depends="init">
<compc output="${DEPLOY_DIR}/${SWC_NAME}.swc">
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="${SRC_DIR}"/>
</compc>
</target>
However, it's not including any content:
[compc] Loading configuration file /Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/flex-config.xml
[compc] Adobe Compc (Flex Component Compiler)
[compc] Version 3.2.0 build 3958
[compc] Copyright (c) 2004-2007 Adobe Systems, Inc. All rights reserved.
[compc]
[compc] Error: nothing was specified to be included in the library
[compc]
[compc] Use 'compc -help' for information about using the command line.
It looks like I need to enumerate every class that I want to include in the library, which is... ludicrous. There must be a better way. How do I do this?
You can do the following... it takes all the files from the source path and converts it to a format that the compc task can then use.
<fileset id="project.test.dir.fileset" dir="${project.test.dir}">
<include name="**/*.as" />
<include name="**/*.mxml" />
</fileset>
<property name="project.test.dir.fileset" refid="project.test.dir.fileset" />
<!-- Convert the test files into a compiler friendly format. -->
<pathconvert property="project.test.dir.path" pathsep=" " refid="project.test.dir.fileset">
<compositemapper>
<chainedmapper>
<globmapper from="${project.test.dir}/*" to="*" handledirsep="true" />
<mapper type="package" from="*.as" to="*" />
</chainedmapper>
<chainedmapper>
<globmapper from="${project.test.dir}/*" to="*" handledirsep="true" />
<mapper type="package" from="*.mxml" to="*" />
</chainedmapper>
</compositemapper>
</pathconvert>
<compc headless-server="true" default-frame-rate="${flex.default-frame-rate}" debug="${flex.compiler.debug.mode}" output="${build.swc.dir}/${test.component.name}.swc" include-classes="${project.test.dir.path}" directory="false">
<source-path path-element="${project.test.dir}" />
&dependencies;
</compc>
We use it to produce swcs for testing purposes.
Lucky for you I JUST solved this problem and was looking for the answer to another problem!
<compc output="${basedir}/mySwc.swc" locale="en_US">
<source-path path-element="${basedir}/src/main/flex"/>
<include-sources dir="${basedir}/src/main/flex" includes="*" />
<load-config filename="${basedir}/fb3config.xml" />
</compc>
The source-path is necessary to tell it what to look at when trying to resolve various references. The include-sources tells it which sources to include (obviously in this case all of them). The load-config is just the -dump-config output from Flex Builder.
Hope this helps!!
You can use Maven. It's a configuration management tool rather than just a build tool. It does rely on your project having a manifest file.

Compiling mxml files with ant and flex sdk

I am just getting started with flex and am using the SDK (not Flex Builder). I was wondering what's the best way to compile a mxml file from an ant build script.
The Flex SDK ships with a set of ant tasks. More info at:
http://livedocs.adobe.com/flex/3/html/help.html?content=anttasks_1.html
Here is an example of compiling Flex SWCs with ant:
http://www.mikechambers.com/blog/2006/05/19/example-using-ant-with-compc-to-compile-swcs/
mike chambers
I would definitely go with the ant tasks that are included with Flex, they make your build script so much cleaner. Here is a sample build script that will compile and then run your flex project
<?xml version="1.0"?>
<project name="flexapptest" default="buildAndRun" basedir=".">
<!--
make sure this jar file is in the ant lib directory
classpath="${ANT_HOME}/lib/flexTasks.jar"
-->
<taskdef resource="flexTasks.tasks" />
<property name="appname" value="flexapptest"/>
<property name="appname_main" value="Flexapptest"/>
<property name="FLEX_HOME" value="/Applications/flex_sdk_3"/>
<property name="APP_ROOT" value="."/>
<property name="swfOut" value="dist/${appname}.swf" />
<!-- point this to your local copy of the flash player -->
<property name="flash.player" location="/Applications/Adobe Flash CS3/Players/Flash Player.app" />
<target name="compile">
<mxmlc file="${APP_ROOT}/src/${appname_main}.mxml"
output="${APP_ROOT}/${swfOut}"
keep-generated-actionscript="true">
<default-size width="800" height="600" />
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.library-path dir="${APP_ROOT}/libs" append="true">
<include name="*.swc" />
</compiler.library-path>
</mxmlc>
</target>
<target name="buildAndRun" depends="compile">
<exec executable="open">
<arg line="-a '${flash.player}'"/>
<arg line="${APP_ROOT}/${swfOut}" />
</exec>
</target>
<target name="clean">
<delete dir="${APP_ROOT}/src/generated"/>
<delete file="${APP_ROOT}/${swfOut}"/>
</target>
</project>
There is another option - it's called Project Sprouts.
This is a system built with Ruby, RubyGems and Rake that provides many of the features found in Maven and ANT, but with a much cleaner syntax and simpler build scripts.
For example, the ANT script shown above would look like this in Sprouts:
require 'rubygems'
require 'sprout'
desc 'Compile and run the SWF'
flashplayer :run => 'bin/SomeProject.swf'
mxmlc 'bin/SomeProject.swf' do |t|
t.input = 'src/SomeProject.as'
t.default_size = '800 600'
t.default_background_color = '#ffffff'
t.keep_generated_actionscript = true
t.library_path << 'libs'
end
task :default => :run
After installing Ruby and RubyGems, you would simply call this script with:
rake
To remove generated files, run:
rake clean
To see available tasks:
rake -T
Another great benefit of Sprouts, once installed, is that it provides project, class and test generators that will get any development box ready to run with a couple simple command line actions.
# Generate a project and cd into it:
sprout -n mxml SomeProject
cd SomeProject
# Compile and run the main debug SWF:
rake
# Generate a new class, test case and test suite:
script/generate class utils.MathUtil
# Compile and run the test harness:
rake test
If you're open to Maven, try the flex-compiler-mojo plugin:
http://code.google.com/p/flex-mojos/
Christiaan

Resources