編輯:關於Android編程
本來整理了一份Android項目混淆與發布的文檔,突然想到何不寫篇博客,分享一下呢,如是便有了本文。
Android代碼混淆及項目發布步驟記錄
一、清理代碼中的調試信息,如Log、System.out
二、在清單文件中修改版本為當前版本,如果需要更新數據庫,則需要在配置類或配置文件中修改程序數據庫版本。
三、在清單文件中將項目的debugable設置為false
四、創建簽名證書keystore文件
五、在項目中的project.properites文件中添加語句proguard.config=proguard-project.txt來指定混淆規則文件
六、配置proguard-project.txt文件
七、如果項目引用了Library Project,則Eclipse應該會在project.properties文件中自動生產android.library.reference.1..n=../LibraryProjectName
八、如果項目中包含svntmp(通常位於項目的bin文件夾下),在打包時應及時刪除,否則會導致打包失敗。
九、項目打包,安裝測試(最好是使用現有生成包進行升級測試)
附:示例proguard-project.txt文件及相應說明:
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
# Optimizations: If you don't want to optimize, use the
# proguard-android.txt configuration file instead of this one, which
# turns off the optimization flags. Adding optimization introduces
# certain risks, since for example not all optimizations performed by
# ProGuard works on all versions of Dalvik. The following flags turn
# off various optimizations known to have issues, but the list may not
# be complete or up to date. (The "arithmetic" optimization can be
# used if you are only targeting Android 2.0 or later.) Make sure you
# test thoroughly if you go this route.
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
-allowaccessmodification
-dontpreverify
#-dontoptimize
# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-keepattributes Signature
-verbose
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
#-keepclassmembers public class * extends android.view.View {
# void set*(***);
# *** get*();
#}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
*;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-keep class * extends android.view.View{*;}
-keep class * extends android.app.Dialog{*;}
-keep class * implements java.io.Serializable{*;}
#-ignorewarnings
-libraryjars libs/locSDK_4.1.jar
-libraryjars libs/pinyin4j-2.5.0.jar
-libraryjars libs/libammsdk.jar
-libraryjars libs/WebtrendsAndroidClientLib.jar
#-libraryjars libs/afinallib.jar
#-libraryjars libs/stickylistheaders_lib.jar
-keep class android.support.v4.** {*;}
-keep class com.emilsjolander.** {*;}
-keep class org.kobjects.** {*;}
-keep class org.kxml2.** {*;}
-keep class org.xmlpull.** {*;}
-keep class net.tsz.** {*;}
-keep class com.hp.** {*;}
-keep class com.baidu.** {*;}
-keep class net.sourceforget.** {*;}
-keep class com.tencent.** {*;}
-dontwarn demo.**
-keep class demo {*;}
-keep class com.wly.xxx.bean.** {*;}
-keep class com.wly.xxx.tool.DbModelUtils{*;}
-keep class com.wly.xxx.tool.JsonUtils{*;}
-keep class com.wly.xxx.activity.InsuranceQuotesActivity
-keep public class com.wly.xxx.activity.InsuranceQuotesActivity$MyJavaScriptInterface
-keep public class * implements com.wly.xxx.activity.InsuranceQuotesActivity$MyJavaScriptInterface
-keepclassmembers class com.wly.xxx.activity.InsuranceQuotesActivity$MyJavaScriptInterface {
public *;
private *;
}
文件說明:
0.以上文件拷貝自筆者現在開發的項目,出於項目保護的目的,已將工程包名替換com.wly.xxx,讀者可以根據自己的項目加以修改!
1.藍色內容具有通用性質,可以復制黏貼;
2.橙色內容用於指定程序中用到的jar文件(可以看到引用的Library Project不需包含,因為他們已經在project.properties文件中指定了)。
3.紅色內容用於表示保留(不混淆)引用的jar包中的內容。
4.草綠色內容用於表示保留本地的bean文件下的實體類不被混淆。
5.紫色內容用於表示保留本地涉及反射的類不被混淆。
6.綠色內容用於特別處理Web JS與本地原生組件之間的調用過程不被混淆
本文實例講述了Android編程動態加載布局的方法。分享給大家供大家參考,具體如下:由於前段時間項目需要,需要在一個頁面上加載根據不同的按鈕加載不同的布局頁面,當時想到用
Service 是Android四大組件之一,通常是在後台運行的,執行一些耗時的操作。對於Service 我們需要掌握的知識點有:1、Service 的生命周期2、Ser
android-async-http開源項目可以是我們輕松的獲取網絡數據或者向服務器發送數據,使用起來非常簡單,關於android-async-http開源項目的介紹內
1. MediaScanner HEAD2. 應用層 MediaProviderpackagesprovidersMediaProvider(1) MediaProvid