标签:
整了一天,感觉坑挺多。
1. 选择如图中的选项Android Studio进行签名打包:
2. 填写APP对应的信息:(最好用个文本记下来放在项目中同步给Team)
- Key store path: 如果是新APP则创建,如果已经有了选择就行;
- Key store password: *******
- Key alias(别名): 自定义
- 如果是新创建的文件需要选择时间,整个25年足够用了,公司信息填上就OK
- 下一步后选择release就开始打包
3. Android Studio的混淆功能需要在Gradle中添加:
apply plugin: ‘com.android.application‘ android { compileSdkVersion 19 buildToolsVersion ‘23.0.1‘ defaultConfig { applicationId "com.rayclear.juchang" minSdkVersion 17 targetSdkVersion 23 versionCode 4 versionName "1.03" } buildTypes { release { //代码混淆开关,一定要注意现在已经使用minifyEnabled代替runProguard了 minifyEnabled true // proguard-rules.pro 是当前使用的混淆文件(Eclipse中的proguard.cfg) proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘ } } packagingOptions { exclude ‘META-INF/DEPENDENCIES‘ exclude ‘META-INF/LICENSE‘ exclude ‘META-INF/LICENSE.txt‘ exclude ‘META-INF/license.txt‘ exclude ‘META-INF/NOTICE‘ exclude ‘META-INF/NOTICE.txt‘ exclude ‘META-INF/notice.txt‘ exclude ‘META-INF/ASL2.0‘ } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } }
4. 打包时遇到的问题:
1.一直处于Gradle Build Running... 被坑了两次,一直以为是真的在打包,IDE也木有个具体提示什么的,就干等了好久。 遇到这种情况,直接关掉Android Studio重新开始吧。正常来说一个普通的APP打包混淆时长也就是1~3分钟吧。 2.关于cache.properties.lock的错: Error:Timeout waiting to lock cp_proj class cache for build file ‘/Users/raomengyang/work/app/build.gradle‘ (/Users/raomengyang/.gradle/caches/2.8/scripts/build_aldsk0ke4ednnd4pf0nybqlhq/cp_proj). It is currently in use by another Gradle instance. Owner PID: unknown Our PID: 20080 Owner Operation: unknown Our operation: Initialize cache Lock file: /Users/raomengyang/.gradle/caches/2.8/scripts/build_aldsk0ke4ednnd4pf0nybqlhq/cp_proj/cache.properties.lock 之前遇到过同样的情况,是将带lock的文件给恢复权限解决的,可是这次不管用,于是退出AS重新来,每次遇到这个问题然后退出AS都会提示后台还有任务没有结束,所以这个错误个人感觉是AS还有后台任务没有被结束,以至于一直hold在这儿。 3.各种specified twice: java.io.IOException: The same input jar [/Users/raomengyang/work/app/libs/**] is specified twice. 删掉proguard文件中的重复声明引用的jar文件。 4.满天的Warning: Note: there were 157 duplicate class definitions. (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass) Warning:library class org.apache.http.auth.AuthenticationException extends or implements program class org.apache.http.ProtocolException Warning:library class org.apache.http.auth.MalformedChallengeException extends or implements program class org.apache.http.ProtocolException Warning:library class org.apache.http.auth.params.AuthParamBean extends or implements program class org.apache.http.params.HttpAbstractParamBean Warning:library class org.apache.http.client.NonRepeatableRequestException extends or implements program class org.apache.http.ProtocolException Warning:library class org.apache.http.client.RedirectException extends or implements program class org.apache.http.ProtocolException Warning:library class org.apache.http.client.entity.UrlEncodedFormEntity extends or implements program class org.apache.http.entity.StringEntity Warning:library class org.apache.http.client.methods.HttpEntityEnclosingRequestBase extends or implements program class org.apache.http.HttpEntityEnclosingRequest Warning:library class org.apache.http.client.methods.HttpRequestBase extends or implements program class org.apache.http.message.AbstractHttpMessage Warning:library class org.apache.http.client.methods.HttpUriRequest extends or implements program class org.apache.http.HttpRequest Warning:library class org.apache.http.client.params.AllClientPNames extends or implements program class org.apache.http.params.CoreConnectionPNames ………………………………………………………………………………………………Warning…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………Warning…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………Warning…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………Warning…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………Warning…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………Warning…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………Warning…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… Warning:library class org.apache.http.client.params.AllClientPNames extends or implements program class org.apache.http.params.CoreProtocolPNames Warning:library class org.apache.http.client.params.ClientParamBean extends or implements program class org.apache.http.params.HttpAbstractParamBean Warning:library class org.apache.http.client.protocol.RequestAddCookies extends or implements program class org.apache.http.HttpRequestInterceptor Warning:library class org.apache.http.client.protocol.RequestDefaultHeaders extends or implements program class org.apache.http.HttpRequestInterceptor Warning:library class org.apache.http.client.protocol.RequestProxyAuthentication extends or implements program class org.apache.http.HttpRequestInterceptor 该类问题都可以根据我们的class文件来进行以下声明: 例如:现在提示的是org.apache.http.* 这个包里的类有问题,那么就加入下述代码: -keep class org.apache.http.** { *; } -dontwarn org.apache.http.** 依此类推,注意一点,混淆完后,就算打包成功也需要再次测试,因为APP内部可能会出现上述问题。
【Android】Android Studio 进行代码混淆,打包release APK
标签:
原文地址:http://www.cnblogs.com/raomengyang/p/5059662.html