论坛首页 编程语言技术论坛

[原] FlashDevelop导出swc插件(exportswc)的问题及解决方法

浏览 3873 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-12-30   最后修改:2010-12-30

 

[说明: 本文为 http://www.smithfox.com/?e=42 原创, 转载请注明原文, 谢谢]

因为机器不能装Flash Builder,只能用FlashDevelop,所以必须要研究这个(真的很烦呀)。还是Flash Builder好呀(不过要钱)。

FlashDevelop不能建立Library工程, 有人做了一个插件可以导出swc文件, 在FD界可谓小有名气。

它就是 Export SWC。不过非常遗憾,这个插件不支持SWC manifest的配置(它菜单的tooptip显示的manifest指的是它自己生成的 编译配置文件 obj\xx.flex.compc.xml ).

还是自己动手改造吧.

研究发现这个插件的Build All动作先是生成编译配置文件 obj\xx.flex.compc.xml, 然后再调用 compc.exe -load-config+="xxx\obj\xxx.flex.compc.xml" . 所以我们只需要改造这个配置文件. 并且 以后每次都只能调用 Compile Targets, 以避免插件重新生成配置文件覆盖了修改(这个很不爽).

主要改造如下 (注意看注释):


<?xml version="1.0"?>
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
  <output>D:\workspace\flex_workspace\smf\.\bin\smf.swc</output>
  <use-network>true</use-network>
  <target-player>10.1</target-player>
  <warnings>true</warnings>
  <benchmark>false</benchmark>
  <compiler>
    <accessible>false</accessible>
    <allow-source-path-overlap>false</allow-source-path-overlap>
    <optimize>true</optimize>
    <strict>true</strict>
    <es>false</es>
    <show-actionscript-warnings>true</show-actionscript-warnings>
    <show-binding-warnings>true</show-binding-warnings>
    <show-unused-type-selector-warnings>true</show-unused-type-selector-warnings>
    <use-resource-bundle-metadata>true</use-resource-bundle-metadata>
    <verbose-stacktraces>false</verbose-stacktraces>
    <source-path>
      <path-element>d:\workspace\flex_workspace\smf\src</path-element>
    </source-path>
    
    <!-- namespaces 是我手动增加的, 还必须要将flex sdk的带上, 否则因为覆盖了SDK默认的flex-config.xml中的
    namespaces项, 就没有了默认的namespace声明,编译会报错。
    ${flexlib}变量, 编译器认识, 会自动定位到Flex SDK home的frameworks目录
     -->
    <namespaces>
         <namespace>
            <uri>http://ns.adobe.com/mxml/2009</uri>
            <manifest>${flexlib}/mxml-2009-manifest.xml</manifest>
         </namespace>
         <namespace>
            <uri>library://ns.adobe.com/flex/spark</uri>
            <manifest>${flexlib}/spark-manifest.xml</manifest>
         </namespace>
         <namespace>
            <uri>library://ns.adobe.com/flex/mx</uri>
            <manifest>${flexlib}/mx-manifest.xml</manifest>
         </namespace>
         <namespace>
            <uri>http://www.adobe.com/2006/mxml</uri>
            <manifest>${flexlib}/mxml-manifest.xml</manifest>
         </namespace>
         <!-- 这个是我自己的namespace -->
         <namespace>
            <uri>http://www.smithfox.com</uri>
            <manifest>D:\workspace\flex_workspace\smf\src\manifest.xml</manifest>
         </namespace>
    </namespaces>
  </compiler>
  
  <!-- 这个也是新增加的 -->
  <include-namespaces><uri>http://www.smithfox.com</uri></include-namespaces>
  
  <include-classes>
    <class>com.smithfox.components.C1</class>
    <class>com.smithfox.components.C2</class>
    <class>com.smithfox.components.C3</class>
  </include-classes>
</flex-config>
 

还有一种方法,就是干脆不用这个插件,写Ant脚本直接编译:

build.xml 直接放在项目根目录,注意看注释

<?xml version="1.0"?>
<!--
所用到的参考网址:
http://hi.baidu.com/liyunluck/blog/item/cc5692ccd9863d35b700c845.html
http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_22.html#250507
http://www.oreillynet.com/pub/a/oreilly/digitalmedia/helpcenter/flex3cookbook/chapter21.html
http://ant.apache.org/manual/Tasks/pathconvert.html
http://ant.apache.org/manual/Types/mapper.html
-->
<project name="smf.swc" basedir="." default="dist">
  <!-- 已经有了 ant 默认的 basedir, 就不要再创建什么 project.dir 之类的了 -->
  
  
  <property name="name" value="${ant.project.name}"/>
	
  <!-- 因类compc认死了这个名字,所以请不要改FLEX_HOME这个名字了 -->
  <property name="FLEX_HOME" value="D:\flash\flex_sdk_4.1.0.16076_mpl" />
  
  <!-- 为了不再创造新的名字,就沿用Flex SDK中的flex-config.xml中的flexlib变量名, 指的都是一个目录 -->
  <property name="flexlib" value="${FLEX_HOME}\frameworks" />
  
  <!-- 这个是flex做的ant插件,必须先加载 -->
  <taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}\ant\lib\flexTasks.jar" />

  <property name="output.file" value="${name}" />

  <target name="dist" depends="clean, compc" />

  <!-- 遵循FlashBuilder和FlashDevelop的目录结构, 就用bin目录作为output所在的目录 -->
  <target name="clean">
         <delete dir="${basedir}\bin" failonerror="true"/>  
         <mkdir  dir="${basedir}\bin"/>
  </target>

  <target name="compc">
  
    <!-- 包含所有文件, 而不仅仅是as文件, 还包含了mxml文件和图片文件 -->
    <fileset dir="${basedir}\src" id="sources">
      <include name="**\**"/>
    </fileset>
    
    <!-- 遍历src目录下的所有as和mxml文件, 以生成 include-classes列表, 
    最终是类似于 'com.smithfox.class1 com.smithfox.class2' 的以空格隔开的字符串  
    这个ant task比较难理解, 相比网上写的, 我加了mxml文件的类名转换, 否则mxml将不会编译
    -->
    <pathconvert
      property="included.classes"
      pathsep=" "
      dirsep="."
      refid="sources">
      <map from="\" to="/"/>
      <map from="src\" to=""/>
      <mapper>
        <chainedmapper><globmapper from="${basedir}\*.mxml" to="*"/></chainedmapper>    
        <chainedmapper><globmapper from="${basedir}\*.as" to="*"/></chainedmapper>    
      </mapper>
    </pathconvert>

    <!-- 打印到screen, 以使确认一下, 如果太多,可以删除这行 -->
    <echo message="${included.classes}" />
    
    <!--
    <compc output="${basedir}\bin\${output.file}"
      include-classes="${included.classes}"
      optimize="true"
      benchmark="true"
      strict = "true"
      debug="false"
      as3="true"
      actionscript-file-encoding = "utf-8"
      allow-source-path-overlap = "true"
      use-resource-bundle-metadata = "true"
      >
      -->
    <compc output="${basedir}\bin\${output.file}"
      include-classes="${included.classes}"
      >
        <!-- 源文件所在路径 -->
        <source-path path-element="${basedir}\src" />
        
        <!--如果类库做了国际化,那么需要引入国际化资源文件,
        也就是工程目录\locale\下面的所有资源文件(类型为.properties)-->
        <!--
        <source-path path-element="${basedir}\locale\en_US"/>
        <source-path path-element="${basedir}\locale\zh_CN"/>
        -->
        
        <!-- 
        需要指定引用图片的资源文件,否则在编译好的mx文件夹下的所有图片都是0字节,
        上面这句话, 是保留自原作者的, 但是我将其comment, 没有出现什么问题
        -->
        <!--
        <source-path path-element="${FLEX_HOME}\frameworks\projects\framework\src"/>
        -->
        
        <!-- List of SWC files or directories that contain SWC files. -->
        <!-- 这里可以指定类库文件的目录
        我没有用到3rd lib, 同时我也将FLEX_HOME也comment也,一切都正常
         -->
        <!--
        <compiler.include-libraries dir="${FLEX_HOME}" append="true">
          <include name="/frameworks/libs/*.swc"/>
        </compiler.include-libraries>
        <compiler.include-libraries dir="." append="true">
          <include name="/lib/*.swc" />
        </compiler.include-libraries> 
        -->

        <!-- 下面是声明SDK 的manifest和自己的manifest 
        SDK的manifest必须要加, 否则编译报错
        -->
        <namespace uri="http://ns.adobe.com/mxml/2009" manifest="${flexlib}/mxml-2009-manifest.xml" />
        <namespace uri="library://ns.adobe.com/flex/spark" manifest="${flexlib}/spark-manifest.xml" />
        <namespace uri="library://ns.adobe.com/flex/mx" manifest="${flexlib}/mx-manifest.xml" />
        <namespace uri="http://www.adobe.com/2006/mxml" manifest="${flexlib}/mxml-manifest.xml" />
        <namespace uri="http://www.smithfox.com" manifest="${basedir}\src\manifest.xml" />
        <include-namespaces uri="http://www.smithfox.com" />
    </compc>
</target>  
</project>

 

[说明: 本文为 http://www.smithfox.com/?e=42 原创, 转载请注明原文, 谢谢]

 

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics