標籤:
整了一天,感覺坑挺多。
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: unknownOur PID: 20080Owner Operation: unknownOur operation: Initialize cacheLock 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.ProtocolExceptionWarning:library class org.apache.http.auth.MalformedChallengeException extends or implements program class org.apache.http.ProtocolExceptionWarning:library class org.apache.http.auth.params.AuthParamBean extends or implements program class org.apache.http.params.HttpAbstractParamBeanWarning:library class org.apache.http.client.NonRepeatableRequestException extends or implements program class org.apache.http.ProtocolExceptionWarning:library class org.apache.http.client.RedirectException extends or implements program class org.apache.http.ProtocolExceptionWarning:library class org.apache.http.client.entity.UrlEncodedFormEntity extends or implements program class org.apache.http.entity.StringEntityWarning:library class org.apache.http.client.methods.HttpEntityEnclosingRequestBase extends or implements program class org.apache.http.HttpEntityEnclosingRequestWarning:library class org.apache.http.client.methods.HttpRequestBase extends or implements program class org.apache.http.message.AbstractHttpMessageWarning:library class org.apache.http.client.methods.HttpUriRequest extends or implements program class org.apache.http.HttpRequestWarning: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.CoreProtocolPNamesWarning:library class org.apache.http.client.params.ClientParamBean extends or implements program class org.apache.http.params.HttpAbstractParamBeanWarning:library class org.apache.http.client.protocol.RequestAddCookies extends or implements program class org.apache.http.HttpRequestInterceptorWarning:library class org.apache.http.client.protocol.RequestDefaultHeaders extends or implements program class org.apache.http.HttpRequestInterceptorWarning: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