如何利用Eclipse工具打包签名AndroidApkdat文件解包打包工具

Eclipse(20)
Android(38)
参考博文:http://blog.csdn.net/zhouxinhong/article/details/7599950
& & & & & & & & & &&/tianguook/archive//2705724.html
将两篇博文结合了一下,只采用自己熟悉的方法,介绍如下:
1、为何使用Eclipse打包
android 运行后可以自动打包成apk,并放在默认路径下%\bin\****.apk。android工程的bin目录下的demo.apk默认是已经使用debug用户签名的,所以不能使用上述步骤对此文件再次签名。
使用Eclipse打包成apk的目的:
(1)唯一标识apk,在许许多多apk中可能会有相同的Package Name,导致其他程序无法安装;另外,方便程序更新;
(2)这样打包速度更快,省时省力。
2、使用方法
(1)keytool.exe
& & & & & & & & 在Java的jdk安装路径下的bin目录下含有keytool.exe文件,我的路径是F:\Java\Java_Develop_Kit\Jdk1.8\bin
(2)由于安装Java时已经进行了环境变量配置,所以可直接在dos窗口下操作,输入以下命令
keytool -genkey -alias android.keystore -keyalg RSA -validity 100000 -keystore android.keystore
-genkey 产生密钥;-alias ******.keystore 别名,其中******可自定义名称
-keyalg RSA 使用RSA算法对签名加密
-validity 100000 有效期限100000天
-keystore ******.keystore密钥库位置
android.keystore存储到了C:\Users\banbeichase文件夹路径下。
(3)导出apk
Eclipse中选中要导出的工程,右击——”export&——Android文件夹,选择小机器人图标Export Android Application——N选择“Use existing keystore&,找到keystore的路径,并输入密码;
注:如果下次发布版本,还要使用该签名
输入alias(别名)密码
选择输出目标文件夹
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:167235次
积分:2474
积分:2474
排名:第15227名
原创:81篇
转载:20篇
评论:16条
(1)(7)(5)(1)(1)(1)(15)(1)(1)(4)(2)(4)(2)(4)(5)(1)(6)(1)(10)(5)(24)Android程序apk编译、打包、签名
我的图书馆
Android程序apk编译、打包、签名
1.Eclipse下打包unsigned apk
在Eclipse,选中对应的Project,右击选择Android Tools——Export unsigned application package
2. Eclipse下打包signed apk
在Eclipse,选中对应的Project,右击选择Android Tools——Export signed application package
选择已有的签名文件keystore,注意要知道密码;如果没有keystore,在练习中可以自己试着编一个keystore,参看apk签名设置文本 X:\csdn博客文章\apk打包练习
创建签名文件步骤:PS:keystore是由jdk自带的工具keytool生成的。
1.&&& 进入cmd命令行,cd到jdk/bin目录下;
2.&&& 然后输入:
命令:keytool -genkey -alias asaiAndroid.keystore -keyalg RSA -validity 20000 -keystore asaiAndroid.keystore &生成的mySign.keystore就在jdk/bin目录中。
解释:-alias 后面跟的是别名这里是 asaiAndroid.store
&&&&& -keyalg 是加密方式这里是RSA
&&&&& -validity 是有效期 这里是20000
&&&&& -keystore 就是要生成的keystore的名称 这里是asiAndroid.keystore
然后按回车键 ,按回车后首先会提示你输入的密码:这个在签名时要用的,要记住,然后会再确认你的密码。 之后会依次叫你输入姓名、组织单位、组织名称、城市区域、省份名称、国家代码
设置完信息,最后再次输入原来的密码进行确认,再输入yes/no确定完成签名,并生成mySign.keystore签名文件;
附:cmd下查找文件:
开始为unsigned.apk签名 步骤:PS:unsigned.apk mySigned.keystore必须在同个文件夹下,因为没有配置keytool的环境变量,所以暂时需要的文件均放在jdk/bin文件目录下;使用jarsigner
命令:jarsigner -verbose -keystore mySign.keystore-signedjar AndroidTest_signed.apk AndroidTest.apk mySign.keystore生成的Lotteryonline_signed.apk就在jdk/bin目录中
解释:-keystore: keystore的名称
&&&&& AndroidTest_signed.apk: 签名后的APK
&&&&& AndroidTest.apk: 签名前的APK
然后按回车:会要求输入刚才设置的密码,输入后按回车就开始签名了。
PS:第一次签名失败的原因:AndroidTest.apk没有和mySign.keystore同在jdk/bin目录中;
Apk包结构简介:转
keytool -genkey命令解释:
cmd下启动android emulator:
前提:配置android-sdk tools环境变量
命令:android avd (任意目录)
馆藏&23150
TA的最新馆藏
喜欢该文的人也喜欢下次自动登录
现在的位置:
& 综合 & 正文
使用ant让Android自动打包的build.xml,自动生成签名的apk文件(支持android4.0以上的版本) .
记得去年自己写过一个ant脚本,但是在android4.0以后的sdk里那个脚本就失效了,主要是因为 apkbuilder这个程序不见了;
人家sdk升级,我们的脚本也要跟上趟,修改一下喽。
上网一查,大家的文章还停留在我去年的脚本程度,算了,自己动手查阅了资料之后,具体实现如下:
在工程的根目录 创建2个文件,分别:
1、build.xml
2、build.properties
build.xml的内容:
&?xml version="1.0" encoding="UTF-8"?&
&project name="autoDeployAPK" default="deploy"&
&!-- 使用第三方的ant包,使ant支持for循环--&
&taskdef resource="net/sf/antcontrib/antcontrib.properties"&
&classpath&
&pathelement location="lib/ant-contrib-1.0b3.jar"/&
&/classpath&
&/taskdef&
&property file="build.properties" /&
&!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems.
&property file="local.properties" /&
&!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
&property file="ant.properties" /&
&property name="jar.libs.dir" value="${jar.libs.dir}" /&
&!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. --&
&loadproperties srcFile="${project.dir}/project.properties" /&
&!-- quick check on sdk.dir --&
&fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"/&
&property name="channelname" value="pateo" /&
&property name="channelkey" value="12347" /&
&!--循环打包 --&
&target name="deploy"&
&foreach target="modify_manifest" list="${channel.list}" param="nameandchannel" delimiter=","&&/foreach&
&target name="modify_manifest"&
&!-- 获取渠道名字 --&
&propertyregex override="true" property="channelname" input="${nameandchannel}" regexp="(.*):" select="\1"/&
&!-- 获取渠道号码 --&
&propertyregex override="true" property="channelkey" input="${nameandchannel}" regexp=":(.*)" select="\1"/&
&!-- 正则匹配替换渠道号
&replaceregexp flags="g" byline="false" encoding="UTF-8"&
&regexp pattern='meta-data android:name="CHANNEL" android:value="(.*)"' /&
&substitution expression='meta-data android:name="CHANNEL" android:value="${channelkey}"' /&
&fileset dir="" includes="AndroidManifest.xml" /&
&/replaceregexp&--&
&property name="out.final.file"
location="${apk.out.dir}/${project.name}_${channelname}_${project.version}.apk" /&
&antcall target="release" /&
&!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets --&
&target name="-pre-build"&
&target name="-pre-compile"&
&target name="-post-compile"&
&!--如果项目包含了jni代码,希望在打包时自动重新编译so库,可以修改build.xml文件。
修改方法为,在引用sdk的build.xml文件之前添加如下target:--&
&target name="-pre-build" depends="-ndk-build"&
&target name="-ndk-build"&
&exec executable="ndk-build" failonerror="true"&
&arg value="clean" /&
&exec executable="ndk-build" failonerror="true" /&
&!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
&import& task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the &import& task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
&!-- version-tag: 导入anroid sdk 默认的ant写好的build.xml --&
&import file="${sdk.dir}/tools/ant/build.xml" /&
&/project&
&?xml version="1.0" encoding="UTF-8"?&
&project name="autoDeployAPK" default="deploy"&
&!-- 使用第三方的ant包,使ant支持for循环--&
&taskdef resource="net/sf/antcontrib/antcontrib.properties"&
&classpath&
&pathelement location="lib/ant-contrib-1.0b3.jar"/&
&/classpath&
&/taskdef&
&property file="build.properties" /&
&!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems.
&property file="local.properties" /&
&!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
&property file="ant.properties" /&
&property name="jar.libs.dir" value="${jar.libs.dir}" /&
&!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. --&
&loadproperties srcFile="${project.dir}/project.properties" /&
&!-- quick check on sdk.dir --&
&fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"/&
&property name="channelname" value="pateo" /&
&property name="channelkey" value="12347" /&
&!--循环打包 --&
&target name="deploy"&
&foreach target="modify_manifest" list="${channel.list}" param="nameandchannel" delimiter=","&&/foreach&
&target name="modify_manifest"&
&!-- 获取渠道名字 --&
&propertyregex override="true" property="channelname" input="${nameandchannel}" regexp="(.*):" select="\1"/&
&!-- 获取渠道号码 --&
&propertyregex override="true" property="channelkey" input="${nameandchannel}" regexp=":(.*)" select="\1"/&
&!-- 正则匹配替换渠道号
&replaceregexp flags="g" byline="false" encoding="UTF-8"&
&regexp pattern='meta-data android:name="CHANNEL" android:value="(.*)"' /&
&substitution expression='meta-data android:name="CHANNEL" android:value="${channelkey}"' /&
&fileset dir="" includes="AndroidManifest.xml" /&
&/replaceregexp&--&
&property name="out.final.file"
location="${apk.out.dir}/${project.name}_${channelname}_${project.version}.apk" /&
&antcall target="release" /&
&!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets --&
&target name="-pre-build"&
&target name="-pre-compile"&
/* This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir} */
&target name="-post-compile"&
&!--如果项目包含了jni代码,希望在打包时自动重新编译so库,可以修改build.xml文件。
修改方法为,在引用sdk的build.xml文件之前添加如下target:--&
&target name="-pre-build" depends="-ndk-build"&
&target name="-ndk-build"&
&exec executable="ndk-build" failonerror="true"&
&arg value="clean" /&
&exec executable="ndk-build" failonerror="true" /&
&!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
&import& task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the &import& task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
&!-- version-tag: 导入anroid sdk 默认的ant写好的build.xml --&
&import file="${sdk.dir}/tools/ant/build.xml" /&
&/project&
这个文件主要就是打包的指令,其中大家不难看出
&import file="${sdk.dir}/tools/ant/build.xml" /&
&import file="${sdk.dir}/tools/ant/build.xml" /&
自动引用并且执行了你的sdk目录下tools/ant/build.xml,大家有精力可以自己看看这个文件.
build.properties的内容:
#Wed Oct 23 15:47:27 CST 2013
project.name=MOBILE_ANDROID_PROJECT
jar.libs.dir=libs
build.first=false
key.alias=maomao
key.alias.password=maomao
channel.list=test1\:100411-f91d7ad6c9d2c507679d,test2\:100411-f91d7ad6c9d2c507679d
java.dir=C\:\\Program Files (x86)\\Java\\jdk1.6.0_10
key.store=C\:\\changeself\\test.keystore
project.dir=C\:\\changeself\\project_android
sdk.dir=C\:\\changeself\\adt-bundle-windows-x86-\\sdk
project.version=1.0.3
key.store.password=maomao
apk.out.dir=apk
#Wed Oct 23 15:47:27 CST 2013
project.name=MOBILE_ANDROID_PROJECT
jar.libs.dir=libs
build.first=false
key.alias=maomao
key.alias.password=maomao
channel.list=test1\:d7ad6c9d2c507679d,test2\:d7ad6c9d2c507679d
java.dir=C\:\\Program Files (x86)\\Java\\jdk1.6.0_10
key.store=C\:\\changeself\\test.keystore
project.dir=C\:\\changeself\\project_android
sdk.dir=C\:\\changeself\\adt-bundle-windows-x86-\\sdk
project.version=1.0.3
key.store.password=maomao
apk.out.dir=apk
这个文件里面,
project.name 就是你的工程名,其实最后体现在APK的名字
key.alias和key.alias.password是你的 签名文件里的东西,自己先生成去
channel.list就是你的渠道名字,支持多个渠道,test1和test2,......testn,自己按照格式去填写,你写了几个渠道就会生成几个apk
自己的java本机的安装目录
自己签名文件的本机存放目录
project.dir 你的工程本机存放目录
你的android sdk本机存放目录
project.version
工程的版本号,最后也会体现在apk的名字里
key.store.password
apk.out.dir
在你的工程根目录存放apk生成的目录
ok,配置好上述2个文件后,在cmd命令行下,键入你的工程目录,执行 ant命令
最后会在你的apk.out.dir生成你需要的apk文件
大家如果有何疑问可以关注我的微博:/changeself 跟我交流
&&&&推荐文章:
【上篇】【下篇】23522人阅读
Android(68)
1.Eclipse工程中右键工程,弹出选项中选择 android工具-生成签名应用包:
2.选择需要打包的android项目工程:
3.如果已有私钥文件,选择私钥文件输入密码,如果没有参见第6和7步创建私钥文件:
4.输入私钥别名和密码:
5.选择APK存储的位置,并完成设置
开始生成:
6.没有私钥文件的情况,创建私钥文件:
7.输入私钥文件所需信息,并创建:
*自己的一点补充:SDK的安装目录最后不要有中文和空格,否则会出现不必要的错误。如果你的安装路径包含Program
Files(有空格),用ADT打包会报错,Ant方式打包的也会报错,没关系,不用重装,解决方法:配置SDk环境变量和在Eclipse中配置SDK路径的时候把Program Files改为Progra~1即可。(而且改成其他的都不行,只能是Progra~1,不信试试,这是Dos的规格)。
转自:http://jojol-/blog/719428
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1522315次
积分:8691
积分:8691
排名:第2225名
原创:61篇
转载:14篇
评论:230条
(3)(1)(1)(3)(2)(1)(3)(5)(4)(2)(4)(7)(3)(11)(13)(10)(2)

我要回帖

更多关于 dat文件解包打包工具 的文章

 

随机推荐