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.
Related
I'm trying to compile a AIR library project to SWC using compc and it's not including any of my libraries files. Here is my ANT task:
<!-- Compile the FCLibrary swc -->
<target name="compileFCLibrary" >
<compc output="${FC_DEPLOY_DIR}" directory="true" locale="en_US" >
<!-- FCLibrary has Air classes and requires air-config to be loaded -->
<load-config filename="${FLEX_HOME}/frameworks/air-config.xml" />
<source-path path-element="${FCLIB_SRC}"/>
<include-sources dir="${BASE_DIR}/FClibrary/src" includes="*" />
</compc>
</target>
It looks like it includes some files. The directory it creates is as such:
/catalog.xml
/library.swf
/local
/en_US
/... (*.properties)
/spark
/components
/... (*.png)
Actually, I don't know if the classes are not including my files. The catalog.xml mentions them.
The error I'm getting on the project that is compiling based on this is:
Type was not found or was not a compile-time constant:
Error: Type was not found or was not a compile-time constant: LoadFile.
Solved. The problem was two fold.
The name of the library referenced in ANT was miscased. It was referenced FClibrary.swc when the actual file was FCLibrary.swc
mxmlc was not including the library and was failing silently (should have thrown an error).
Didn't work:
<include-libraries file="FClibrary.swc" />
Worked:
<include-libraries file="FCLibrary.swc" />
Ok, I need some help on this one. I upgraded from Flash Builder 4 to Flash Builder 4.5 and have switched my project to the 4.5.1 sdk. I use an ant script to build my project, so I modified it to use the appropriate flexTasks.jar, mxmlc, etc...
Now, if I start out with a blank bin-debug folder, then build and run the app everything works fine. However, if I then make a code change and build (without deleting the bin-debug) then run the app I get a runtime error:
ReferenceError: Error #1065: Variable ... is not defined.
at flash.display::MovieClip/nextFrame()
at mx.managers::SystemManager/deferredNextFrame()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\SystemManager.as:284]
at mx.managers::SystemManager/preloader_preloaderDocFrameReadyHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\SystemManager.as:2633]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/timerHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:515]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
Again, if I delete the bin-debug folder and compile again it runs with no problems.
The variable it complains about is always a Class variable that points to an image file used as an icon. The code I use to create the var:
[Embed(source="/assets/icons/close-32x32.png")]
public var closeIcon:Class;
The file exists, and I verified that when it gives that error the file is in the bin-debug/assets/icons folder and the src/assets/icons/ folder.
After the error is thrown, if I hit the continue button in Flash Builder it then throws the same error again on the next Class variable pointing to an image file.
Any ideas? The delete/recompile takes several minutes, so obviously this is driving me mad.
Edit: Ant task that compiles in debug mode:
<target name="compile-debug">
<echo>Compile MXML</echo>
<mxmlc
file="${SRC_DIR}/${MAIN_SOURCE_FILE}"
debug="true"
optimize="false"
output="${DEBUG_DIR}/${APP_ROOT_FILE}"
append="true"
actionscript-file-encoding="UTF-8"
keep-generated-actionscript="false"
link-report="MyReport.xml"
maxmemory="2048m"
incremental="true">
<!-- Get default compiler options. -->
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<load-config filename="${FLEX_HOME}/frameworks/air-config.xml"/>
<!-- List of path elements that form the roots of ActionScript class hierarchies. -->
<source-path path-element="${FLEX_HOME}/frameworks"/>
<!-- Include Themes -->
<!-- NOTE: Spark theme required -->
<theme dir="${FLEX_HOME}/frameworks/themes/Spark/">
<include name="spark.css" />
</theme>
<theme dir="${FLEX_HOME}/samples/themes/spark_graphite/">
<include name="spark_graphite.css" />
</theme>
<!-- 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>
<!-- uncomment if you have external libs (swc files) -->
<library-path dir="${LIB_DIR}/riaspace/" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${LIB_DIR}/AlivePDF/" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${LIB_DIR}/coltware/" append="true">
<include name="*.swc" />
</library-path>
</mxmlc>
</target>
Where FLEX_HOME = < path to flash builder >/sdks/4.5.1
The answer is buried in the middle of Maxim's post that he referenced in a comment above:
--> Try turning off incremental compilation.
I had the same issue here with a simple mimeType='application/octet-stream' embed, and when reading Maxim's text this jumped out because I'd recently changed my custom build tools to use inremental compilation: "Embed sometimes fails during incremental compilation"
The result of this failure is that the .swf contains something like this:
<DefineBinaryData id='1' length='1024' />
which looks like it's empty, instead of this (from the working file):
<DefineBitsLossless2 id='1' encoding='base64'>
(.. in my case, 1024 bytes of base64-encoded data)
</DefineBitsLossless2>
(This solved it for me, so a big thank-you to Maxim. I hope it solves it for you too.)
I had the same problem, so I "Clean"ed the project and then re ran. It worked.
I have Flash Builder 4.7 and am using sdk 4.5.1A.
I was using Flash Player debugger version 15 before Christmas of 2014 and everything was working. I had Firefox set up as the default browser. However, in 2015, Adobe has a new player so I upgraded to version 16 and that's when I got the same problem. After much struggle, I found that the problem had to do with the new version of Firefox Flash player debugger. I had to switch the default browser to Internet Explorer and installed the Internet Explorer Flash player debugger. Prior to debugging, I had to clean and update first. Then everything worked again!
According to the Adobe asdocs, Flex framework files are supposed to be able to be loaded at runtime. These localized framework files, the ones that exist at (on windows) C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.5\sdks\4.5.0\frameworks\locale, are responsible for items such as button text on Alert Dialogs, and a host of other controls. My expectation is that once these framework files are loaded I would see these resources available in my Flex app.
I've set up my project as follows:
MyProject
-src
-Flex4.5
-Referenced Libraries
-bin-debug
-bin-release
-libs
-locale (I've copied all of the directories(da_DK,en_US,es_ES,etc) of framework files for the locales I want to support inside of this dir)
Now the asdocs state that in order to do this, you have to set the compiler settings to read
-locale=en_US,da_DK,de_DE,es_ES,fi_FI,fr_FR,it_IT,ja_JP,ko_KR,nb_NO,nl_NL,pt_BR,ru_RU,sv_SE,zh_CN,zh_TW -allow-source-path-overlap=true -source-path=locale/{locale}
which I have done.
My Build Path Libraries for Flex 4.5 - C:Program Files (x86)\Adobe\Adobe Flash Builder 4.5\sdks\4.5.0 are set to be Runtime Shared library (of note, the {locale} subfolder says "Merged into code")
But when I change the language in the browser, I'm not seeing any of the framework resources.
Also, when I build my project, I don't see any indication of the locale-oriented resource files in the bin-release. Since we only deploy the contents of the bin-release folder (and not the entire project), how is this supposed to work?
I am also seeing .swz files in my bin-release (and I know these arent the localized framework resources).
Does anyone have any experience with Runtime Framework Localization?? What am I doing wrong? My expectation is that once I build my project (with the framework resources externalized) that the app would be able to load those resources, but this isn't happening and I am not interested in compiling a different version of my app for all of the locales I support.
Thanks in advance
I use the following ANT task which works for me:
<mxmlc file="${build.dir.src}/${mxml.file}" keep-generated-actionscript="false" output="${build.dir.stage}/${project.app.name}.swf"
actionscript-file-encoding="UTF-8" incremental="false" context-root="${project.app.name}" optimize="${app.optimize}"
debug="${app.debug}" configname="air" locale="en_US,ja_JP,fr_FR">
<jvmarg value="-Xmx1024m" />
<jvmarg value="-Xms512m" />
<compiler.theme append="true" file="${FLEX_HOME}/frameworks/projects/spark/MXFTEText.css" />
<source-path path-element="${FLEX_HOME}/frameworks" />
<source-path path-element="${build.dir.locale.src}/{locale}" />
<library-path dir="${FLEX_HOME}/frameworks/libs" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${FLEX_HOME}/frameworks/libs/air" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${FLEX_HOME}/frameworks/locale" append="true">
<include name="{locale}" />
</library-path>
<library-path dir="${build.dir.lib}" append="true">
<include name="*.swc" />
</library-path>
Add the following tag to the classes that use resources and read the strings in the way:
[ResourceBundle('application')]
// set up the locale chain
ResourceManager.getInstance().localeChain = [ 'en_US', 'ja_JP', 'fr_FR' ];
// load resources
ResourceManager.getInstance().getString('application', 'some.string.code');
An observation: One does not need to copy the framework files into one's project folder. They will be picked up the compiler when compiling.
Let me know if it works, else we can debug more!
I can compile the main application but am having an issue with compiling a nested module.
I have the following application structure:
src
MyApp.mxml
view
MyView.mxml
module
MyModule.mxml
view
AnotherView.mxml
When using the following command
<mxmlc file="${SRC_DIR}/${MODULE_DIR}/MyModule.mxml"
debug="false"
output="${OUTPUT_DIR}/${MODULE_DIR}/MyModule.swf"
locale=""
actionscript-file-encoding="UTF-8"
keep-generated-actionscript="false"
optimize="true"
fork="true"
load-externs="LinkReport.xml"
incremental="false">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.library-path dir="libs" append="true">
<include name="*.swc"/>
</compiler.library-path>
</mxmlc>
I get the following error:
Error: Could not resolve "view:AnotherView" to a component implementation.
I think the compiler might be having an issue with determining which "view" directory has the right mxml file ..
Any Thoughts? A detailed explaination with an example would be most appreciated.
You need to add your src directory as part of the source-path as well. You basically haven't told the compiler where to find your code.
I have a flex project and if I build a release version of the application using flash builder with RSLs on my swf is 115k. If however I build the same application using ant the swf is 342k. Without RSLs the swf is 520k.
How do I get the swf to be as small as the one built by FlashBuilder?
Here is my ant file I have another task that copies the rsls.
<project name="EUI Client Application" default="compileClientApp">
<target name="compileClientApp" depends="compileClientBundles">
<mxmlc
file="${CLIENT_PROJECT.dir}/src/${CLIENT_PROJECT.app}.mxml"
output="${DEPLOY.dir}/${CLIENT_PROJECT.app}.swf"
keep-generated-actionscript="false"
actionscript-file-encoding="UTF-8"
incremental="false"
>
<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/framework.swc">
<url rsl-url="flex4_4.0.0.7791.swf"/>
<url rsl-url="framework_4.0.0.7791.swf"/>
<url rsl-url="framework_textLayout_4.0.0.7791.swf"/>
<url rsl-url="rpc_4.0.0.7791.swf"/>
<url rsl-url="textLayout_451.swf"/>
</runtime-shared-library-path>
<source-path path-element="${CLIENT_PROJECT.dir}/src" />
<compiler.library-path dir="${LIBS.dir}" append="true">
<include name="*.swc" />
</compiler.library-path>
<compiler.library-path dir="${DEPLOY_BIN.dir}" append="true">
<include name="*.swc" />
</compiler.library-path>
</mxmlc>
</target>
<target name="generateWrapper">
<html-wrapper
title="${CLIENT_APP_TITLE}"
file="${CLIENT_PROJECT.app}.html"
height="100%" width="100%"
bgcolor="white" application="app"
swf="${CLIENT_PROJECT.app}"
version-major="10" version-minor="0" version-revision="0"
history="true" output="${DEPLOY.dir}" />
</target>
<target name="compileClientBundles">
<compileBundle bundleName="Modules" source="${CORE_PROJECT.dir}/locale" />
</target>
Thanks for the replies guys but it wasn't either of those.
turns out all I needed to do was to remove the runtime-shared-library-path stuff as this is already in the flex-config.xml file. I also had to change the static-link-runtime-shared-libraries to false (so it's dynamic).
I've copied the flex-config.xml file into my build directory and use that so I can safely make changes.
This is with Flex 4 BTW - nto sure if I made that very clear.
my ant file now looks like this:
<project name="EUI Client Application" default="compileClientApp">
<target name="compileClientApp" depends="compileClientBundles">
<mxmlc
file="${CLIENT_PROJECT.dir}/src/${CLIENT_PROJECT.app}.mxml"
output="${DEPLOY.dir}/${CLIENT_PROJECT.app}.swf"
keep-generated-actionscript="false"
actionscript-file-encoding="UTF-8"
optimize="true" incremental="false"
link-report="${DEPLOY_BIN.dir}/app_link_report.xml"
>
<load-config filename="${basedir}/flex-config.xml" />
<define name="CONFIG::stub" value="false" />
<define name="CONFIG::release" value="true" />
<source-path path-element="${CLIENT_PROJECT.dir}/src" />
<compiler.library-path dir="${LIBS.dir}" append="true">
<include name="*.swc" />
</compiler.library-path>
<compiler.library-path dir="${DEPLOY_BIN.dir}" append="true">
<include name="*.swc" />
</compiler.library-path>
</mxmlc>
</target>
<target name="generateWrapper">
<html-wrapper
title="${CLIENT_APP_TITLE}"
file="${CLIENT_PROJECT.app}.html"
height="100%" width="100%"
bgcolor="white" application="app"
swf="${CLIENT_PROJECT.app}"
version-major="10" version-minor="0" version-revision="0"
history="true" output="${DEPLOY.dir}" />
</target>
<target name="compileClientBundles">
<compileBundle bundleName="Modules" source="${CORE_PROJECT.dir}/locale" />
</target>
You'll probably need to specify the paths to the external libs using the -external-library-path option.
See the docs for more info.
To use RSLs when compiling your application, you use the following application compiler options:
* runtime-shared-libraries Provides the run-time location of the shared library.
* external-library-path|externs|load-externs Provides the compile-time location of the libraries. The compiler requires this for dynamic linking.
Use the runtime-shared-libraries option to specify the location of the SWF file that the application loads as an RSL at run time. You specify the location of the SWF file relative to the deployment location of the application. For example, if you store the library.swf file in the web_root/libraries directory on the web server, and the application in the web root, you specify libraries/library.swf.
You can specify one or more libraries with this option. If you specify more than one library, separate each library with a comma.
Use the external-library-path option to specify the location of the library's SWC file or open directory that the application references at compile time. The compiler provides compile-time link checking by using the library specified by this option. You can also use the externs or load-externs options to specify individual classes or an XML file that defines the contents of the library.
The following command-line example compiles the MyApp application that uses two libraries:
mxmlc -runtime-shared-libraries=
../libraries/CustomCellRenderer/library.swf,
../libraries/CustomDataGrid/library.swf
-external-library-path=../libraries/CustomCellRenderer,
../libraries/CustomDataGrid MyApp.mxml
The order of the libraries is significant because the base classes must be loaded before the classes that use them.
You can also use a configuration file, as the following example shows:
../libraries/CustomCellRenderer
../libraries/CustomDataGrid
../libs/playerglobal.swc
../libraries/CustomCellRenderer/library.swf
../libraries/CustomDataGrid/library.swf
The runtime-shared-libraries option is the relative location of the library.swf files when the application has been deployed. The external-library-path option is the location of the SWC file or open directory at compile time. Because of this, you must know the deployment locations of the libraries relative to the application when you compile it. You do not have to know the deployment structure when you create the library, because you use the compc command-line compiler to create a SWC file.
Try separating your RSLs into their own arguments. Here's what how I have it on my build:
<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/framework.swc">
<url rsl-url="${rsl.url}/framework_3.2.0.3958.swz" />
<url rsl-url="${rsl.url}/framework_3.2.0.3958.swf" />
</runtime-shared-library-path>
<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/datavisualization.swc">
<url rsl-url="${rsl.url}/datavisualization_3.2.0.3958.swz" />
<url rsl-url="${rsl.url}/datavisualization_3.2.0.3958.swf" />
</runtime-shared-library-path>
Using RSL, remember to set use-network parameter to true, otherwise the compiled swf will complain security error (can't load RSL) when run in different location.