Mac下android工程编译,批量打包的一些总结

来源:互联网 发布:白金数据小说叫什么 编辑:程序博客网 时间:2024/06/05 14:07

原创,转载请注明出处!

    这几天有点时间研究了下android工程在mac打包的流程,之前项目的android工程都是在windows下完成的,现在转到mac下,总体感觉更方便了一些。

    首先是编译工程

    对应的命令就是 ant build_native 做的工作:

1. 把Resources目录下的复杂结构,展开复制到android工程下/assets/根目录下

2.. 把mm文件拷贝一份同名的cpp,方便统一编译

3. 编译所有文件,需要注意的是jni/android.mk文件 内容如下

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := game_sharedLOCAL_MODULE_FILENAME := libgame# 定义 all-cpp-files 返回当前路径和 Classes 路径想的所有 cpp 文件,注意:这里只考虑 cpp 而没有 c,如果需要自行添加define all-cpp-files$(patsubst jni/%,%, $(shell find $(LOCAL_PATH)/../../Classes/ $(LOCAL_PATH)/hellocpp -name "*.cpp"))  endef# 这里使用新的方式替换换来的方式,以自动添加源文件LOCAL_SRC_FILES := $(call all-cpp-files)                   LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes#静态库不会产生.so, 它们将和动态库一起,打成一个.so库,放到apk包里LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_staticLOCAL_WHOLE_STATIC_LIBRARIES := cocosdenshion_staticLOCAL_WHOLE_STATIC_LIBRARIES := cocos_extension_staticLOCAL_WHOLE_STATIC_LIBRARIES := cocos_lua_staticinclude $(BUILD_SHARED_LIBRARY)$(call import-module,CocosDenshion/android)$(call import-module,cocos2dx)$(call import-module,extensions)$(call import-module,scripting/lua/proj.android)


下面就是真正执行的编译动作

<target name="build_native" depends="mkdir_assets, copy_Resource" description="build all cpp files to .so file">        <echo message="--target Build Native--" />        <!--把mm文件 复制一份成cpp文件-->                <copy tofile="${basedir}/../Classes/Global/DeviceClass.cpp" file="${basedir}/../Classes/Global/DeviceClass.mm" />        <exec executable="sh">            <arg line="${basedir}/build_native.sh" />        </exec>    </target>    <!-- ************************* mkdir_assets **************** -->    <target name="mkdir_assets" description="mkdir_assets">        <delete dir="${basedir}/assets" />        <mkdir dir="${basedir}/assets" />    </target>    <!-- ************************* Copy Resource **************** -->    <target name="copy_Resource" description="copyResource">        <!--去掉svn 信息, 把所有文件递归拷贝到assets根目录下,不包括空目录-->        <copy todir="${basedir}/assets"  flatten="true" includeemptydirs="false">            <fileset dir="${basedir}/../Resources">                <include name="**/*" />                <exclude name="**/.svn/*" />            </fileset>        </copy>    </target>

执行ant build_native, 编译完成

下面是批量打包,根据多个渠道号,批量打包apk

这一步首先看ant.properties

签名文件的密码,可以在这里指定,不然每打一个渠道包,都要手动输入一下,麻烦。

# The password will be asked during the build when you use the 'release' target.sdk.dir=/Library/Android_Tools/SDK/adt-bundle-mac-x86_64-20130522/sdk# 证书签名 use keystore to sign apkkey.store=/Users/raochongtao/Documents/Android_KeyStore/******key.alias=********# 证书密码 input the password manually, uncomment thiskey.store.password=********key.alias.password=********#多个渠道号,market_channels=channel_000,channel_001,channel_002,channel_003#版本号app_version=1_0_0#导出路径apk_location_name=antApk_apk


再就是关键的 打包动作,这一步参照了,网上多位作者的思路及代码,这里一并表示感谢

<!-- ************************* Make Channels **************** -->    <target name="make_channels" description="make channels">        <echo>--make_channel--</echo>        <foreach target="make_one_channel" list="${market_channels}" delimiter="," param="channel">        </foreach>    </target>    <!-- ************************* Make One Channel **************** -->    <target name="make_one_channel" depends="savemanifest,modify_update_file,release,copyto_antapkdir,replacemanifest,clean" description="make one channel">        <echo>--make one channel--</echo>            </target>    <!-- ************************Save Manifest******************* -->    <target name="savemanifest">        <echo>--savemanifest--</echo>        <copy file="${basedir}/AndroidManifest.xml" tofile="${basedir}/AndroidManifest_bak.xml" />    </target>    <!-- ************************Copyto_antapkdir******************* -->    <target name="copyto_antapkdir">        <echo>--copyto_antapkdir--</echo>        <copy file="${out.final.file}" tofile="${out.final.file.withchannel}" />    </target>    <!-- ************************Replace Manifest******************* -->    <target name="replacemanifest">        <echo>--replacemanifest--</echo>        <copy file="${basedir}/AndroidManifest_bak.xml" tofile="${basedir}/AndroidManifest.xml" overwrite="true" />    </target>    <!-- ************************modify update manifest******************* -->    <target name="modify_update_file">        <echo>--modify_update_file--</echo>        <replaceregexp file="${basedir}/AndroidManifest.xml" match="channel_someid" replace="${channel}" byline="false" encoding="utf-8" />        <property name="out.final.file.withchannel" value="${basedir}/${apk_location_name}/${ant.project.name}_${app_version}_${channel}.apk" />    </target>    <taskdef name="foreach" classname="net.sf.antcontrib.logic.ForEach" classpath="${sdk.dir}/tools/lib/ant-contrib-1.0b3.jar" />


执行 ant make_channels

完成四个渠道包

0 0