zoukankan      html  css  js  c++  java
  • android ant打包问题总结

     用Ant打包的好处就在于可以打多个渠道 常用的就是修改友盟的渠道号,而不需要每改一次输入一次keystore密码的繁琐过程。

    android 不知道在什么版本之后tools目录下就没有在apkbuilder.bat这个文件了,如果从别人那边 copy 过来也无法使用,提示“ apkbuilder 不稳定。。”。

    所以在现在的版本上,进过查找各种资料 我在 ADT 22 版本下找到 Ant 新的解决方法,如有不对,不行请大家指出

    1.Ant  和 android 环境变量配置,不多说了。

    2.在 Android 工程目录下 执行 android update project -p F:workspaceAntTest   (-p 后加入工程目录)

    如果成功就会出现 

    在工程目录下就会出现 两个个文件,build.xml ; local.properties ; 

    阅读build.xml 就会发现 里面有一句很重要的代码:<import file="${sdk.dir}/tools/ant/build.xml" />

    个人觉得这个是 Android 新版里添加的,为了减少开放者的时间,写好了 “父” 版本,然后我们去继承好了,浏览下“父” build.xml 发现的确没有apkbuilder.bat这个文件在使用,替换的是

     <!-- find location of build tools -->
            <getbuildtools name="android.build.tools.dir" />
            <property name="aidl" location="${android.build.tools.dir}/aidl${exe}" />
            <property name="aapt" location="${android.build.tools.dir}/aapt${exe}" />
            <property name="dx" location="${android.build.tools.dir}/dx${bat}" />
            <property name="renderscript" location="${android.build.tools.dir}/llvm-rs-cc${exe}"/>

    这几个工具就llvm-rs-cs.exe 不同以前的了。

    粗略了解之后就是自己的配置好 local.properties 这个文件,

    sdk.dir=D:\android-sdk-windows   
    key.store=F:/workspace/AntTest/android.keystore
    key.store.password=1234
    key.alias=android.keystore
    key.alias.password=1234
    #android.library.reference.1=..\SouTaoProject\TopAndroid

    配置好 SDK 目录 签名工具,最后一句后面再解释。

    Ok,这样在工程目录下运行命令 ant release 就会在bin目录下生成一个 默认的MainActivity-release.apk

    在不修改用 android update project 生成的 build.xml 功能能做的很少 比如 你的工程引入其他工程 Library 这些操作就无法满足

    所以 要支持 Library 需做一下操作:

    1.在 引入的工程下执行 android update project -p  也生成一个 build.xml  不用去修改它,看看在project.properties文件中是否有这句话  android.library=true 没有就添加。

    2.在自己的工程目录下 project.properties 是否有 android.library.reference.1=../Library/TopAndroid   目录一定要写对 不然会报  Fail find Library path。

    最后就是执行 ant release 命令 这样应该就可以通过。

    最后就是多渠道问题了 这个我是直接引用其他博客上的

    <target name="setup-channel">
            <property name="matchChannel.start" value='UMENG_CHANNEL" android:value="' />
            <property name="matchChannel.end" value='"' />            
            <replaceregexp file="AndroidManifest.xml" match='${matchChannel.start}[^"]*${matchChannel.end}' replace="${matchChannel.start}${meta.channel}${matchChannel.end}" />
    
        </target>
        <target name="build-channel" >
            <echo>channel: building ${meta.channel}</echo>
            <antcall target="setup-channel" />
            <antcall target="release" />
    <move file="bin/${ant.project.name}-release.apk" tofile="bin/${ant.project.name}-${meta.channel}.apk"/>
        </target>
        <target name="channel_91" >
            <antcall target="build-channel">
                <param name="meta.channel" value="91"/>
            </antcall>
        </target>
        <target name="channel_hiapk" >
            <antcall target="build-channel">
                <param name="meta.channel" value="apk"/>
            </antcall>
        </target>
    
    <target name="all" depends="channel_91,channel_hiapk">
        </target>

    将以上代码添加到 你的 build.xml 然后执行 ant all 就会在 bin目录下生成对应的渠道apk。

    可能以上只是针对比较简单的工程打包 如果还有引用 JNI , so(以上方法试过好像可以通过)等还有带考究。

    以上是结合网络多篇文章自己摸索出来的,可能有纰漏,请大侠支出。

    看过的文章: http://www.cnblogs.com/qianxudetianxia/archive/2012/07/04/2573687.html  (这是旧sdk打包和ant最基础的教程)

                    http://my.eoe.cn/luoxiangyu001/archive/3430.html

          http://zgame.blog.51cto.com/6144241/1075003  (这个是旧的sdk打包方式)

          http://www.oschina.net/code/snippet_16_6782 (加入了混淆的)

                    http://blog.csdn.net/smallbutstrong/article/details/8457064

                    http://code.google.com/p/android/issues/detail?id=21720 (这个bbs讨论了Library的问题  2楼里给了解决方式)

    补充:

      1.每添加一个Library 就要在 local.properties这个文件里添加目录,并在该Library里加入ant.properties;local.properties;build.xml这三个”初始“文件。

      2.如果遇到

    error: No resource identifier found for attribute 'xxx' in package 'com.xxx.xxx' main.xml

    我的修改方式是把 xmlns:app="http://schemas.android.com/apk/res/com.xxx.xxx"------>改成 xmlns:app="http://schemas.android.com/apk/lib/com.xxx.xxx"

    参考地址:http://stackoverflow.com/questions/5819369/error-no-resource-identifier-found-for-attribute-adsize-in-package-com-googl 

    3.非法字符 ufeff...

      将该文件保存为UTF-8 NOT BOM

    4.获取Apk的版本

      

    <xmlproperty file="AndroidManifest.xml" 
                         prefix="themanifest" 
                         collapseAttributes="true"/>
    调用-->${themanifest.manifest.android:versionName}
  • 相关阅读:
    Orleans is a framework
    修改emlog后台登录路径的方法(转)
    form表单中的 action=./?> 是什么意思
    10 个迅速提升你 Git 水平的提示(转)
    为什么国外程序员爱用苹果Mac电脑?(转)
    Socket 专题
    Android 时间戳简单转化
    Android 常用时间格式转换代码
    Android AlarmManager(全局定时器/闹钟)指定时长或以周期形式执行某项操作
    Android AlarmManager类的应用(实现闹钟功能)
  • 原文地址:https://www.cnblogs.com/gfqFighting/p/3435698.html
Copyright © 2011-2022 走看看