
進階打包步驟
|
135
ProGuard
ProGuard
是一個免費的
Java
工具而可以將你的程式碼縮減、最佳化、混淆來準備發佈。
它透過移除沒用到的程式碼、用不同語意的名稱來取代類別及方法名稱,以及優化位
元碼(
bytecode
)來執行此操作。這會讓你的程式更小、更有效率,且更難被逆向工程;
這個過程可以防止你的程式碼被重用且保護你的機密資料。
開啟
ProGuard
執行這個工具非常容易,當你是使用程式匯出精靈(第
126
頁「簽署
App
」)來打包
APK
時,大部分是自動完成的。如果你的建置目標高於
2.3
版本,則在打包過程中會
自動執行此工具。一個預設的設置檔位於專案的根目錄,名為
proguard-project.txt
,
內容會像是以下的範例:
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
# # Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path ...