android不混淆包
A. android中為什麼要指定第三方包的中內容不混淆呢/
其實第三方jar包是不能混淆,這里指定第三方jar包不混淆的意思是,在你的項目中的調用到第三方jar包的語句不被混淆,你想想,如果jar包是com.umeng,你調用的地方被混淆成了a.b,這樣你生成的apk裡面不是找不到a.b了么,肯定會報錯撒
B. Android-android 怎麼實現只混淆自己的代碼,而不混淆第3方jar包
為了解決第三方包不被混淆,第三方包在混淆後,運行的時候會掛掉。我的錯誤是java.lang.ExceptionInInitializerError
[java] E/AndroidRuntime( 9608):
java.lang.ExceptionInInitializerError
E/AndroidRuntime( 9608): at
a.a.b.f.<init>(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.b.e.<init>(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.c.dg.b(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.c.dg.a(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.c.b.a(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.c.ad.a(Unknown Source)
………………………………………………………………………………中間部分省略
最終我通過 加LOG的調試方法定位到是由於第三方jar包被混淆後的原因導致的。
解決方法:
在proguard-android.txt文件最後加入了-keep class org.jsoup.**這樣一句代碼,就是保持這個類不被混淆
附上proguard-android.txt源文件[html] # This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-dontusemixedcaseclassnames
-
-verbose
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.
-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 <methods>;
}
# 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$* {
public static <fields>;
}
# 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.
-dontwarn android.support.**
-keep class org.jsoup.**
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-dontusemixedcaseclassnames
-
-verbose
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.
-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 <methods>;
}
# 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$* {
public static <fields>;
}
# 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.
-dontwarn android.support.**
-keep class org.jsoup.**
C. android 怎麼實現只混淆自己的代碼,而不混淆第3方jar包
第三方jar包避免混淆用下面的方法:
在proguard-project.txt 文件中加入:
-ignorewarnings
-libraryjars libs/XX (「XX」是jar包名)
-libraryjars libs/XX
-libraryjars libs/XX
。
。
例如:混淆android-support-v4.jar
-ignorewarnings
-libraryjars libs/android-support-v4.jar
D. android 怎麼實現只混淆自己的代碼,而不混淆第3方
混淆打包流程: 1在proguard-projecttxt文件中添加不需要混淆的類和第三方的jar包 這個是保持自己包中不需要混淆的類,如果有些類調用了jni也不需要混淆,不然會出錯。還有如果項目中有其他項目作為library引入,那這些項目的一些類也不能混淆android 怎麼實現只混淆自己的代碼,而不混淆第3方
E. android 不混淆代碼要怎麼使用Robust
什麼是代碼混淆:
Android SDK 自帶了混淆工具Proguard。它位於SDK根目錄\tools\proguard下面。如果開啟了混淆,Proguard默認情況下會對所有代碼,包括第三方包都進行混淆,可是有些代碼或者第三方包是不能混淆的,這就需要我們手動編寫混淆規則來保持不能被混淆的部分。
為什麼要混淆:
優化java的位元組碼
減小apk文件的大小,在混淆過程中會刪除未使用過的類和成員
代碼安全,使類、函數、變數名隨機變成無意義的代號形如:a,b,c...之類。防止app被反編譯之後能夠很容易的看懂代碼
F. Android如何保持指定類不被混淆
包名 package com.example.test
類名 public class WebAppInterface{}
加上完整的包名才行。
-keep class com.example.test.WebAppInterface {*;}
G. 為什麼這么多商業Android開發者不混淆代碼
代碼混淆技術基本原理是使反編譯工具反編譯出來的代碼人難以閱讀,從而達到防止被逆向破解的目的。PC上的代碼混淆技術已經很成熟,有加花指令、多態變形等技術手法,Android代碼混淆技術才剛剛起步,目前已知的技術手法如下。
Java類名、方法名混淆
Dalvik位元組碼包含了大量的調試信息,如類名、方法名、欄位名、參數名、變數名等,使用反編譯工具可以還原這些信息。由於類名、方法名等通常都會遵循一定的命名規范,破解者很容易根據這些信息來猜測代碼功能,閱讀起來就跟查看源代碼一樣。從Android 2.3開始,Google在SDK中加入了一款叫ProGuard的代碼混淆工具,ProGuard會刪除這些調試信息,並用無意義的字元序列來替換類名、方法名等,使得使用反編譯出來的代碼難以閱讀,提升逆向難度。使用ProGuard混淆過過後,反編譯出來的類名和方法名無法閱讀,但是反編譯出來的功能代碼仍然是非常容易閱讀的,和源代碼差不多,破解者仍通過閱讀功能代碼來自行標記類名、方法名等,然後逆向破解。[2]
Java代碼混淆
通過對功能代碼流程進行亂序混淆,實際運行時亂序混淆後的代碼流程卻和原始代碼流程是一樣的,但反編譯出來的代碼流程靜態閱讀時與原始流程有很大差異,使破解者很難通過靜態分析理解代碼功能,從而保護代碼不被逆向分析。比如,原始的代碼流程是1->2->3->4->5->6->7,經過亂序混淆後靜態反匯編查看到的代碼流程可能變成2->7->5->1->6->4->3,實際運行時代碼流程仍然是1->2->3->4->5->6->7。目前使用這種代碼混淆技術的Android保護工具有APKProtect。[1]
H. android-android怎麼實現只混淆自己的代碼,而不混淆第3方jar包
當項目中有第3方jar包時,怎麼實現混淆打包,而不對第3方包混淆
在項目中有第3方包時打包出錯日誌:
[2012-06-14 14:14:28 - humei_cc] Proguard returned with error code 1. See console
[2012-06-14 14:14:28 - humei_cc] Note: there were 2068 plicate class definitions.
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find superclass or interface java.awt.datatransfer.Transferable
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.NativeClipboard: can't find superclass or interface java.awt.datatransfer.Clipboard
[2012-06-14 14:14:28 - humei_cc] Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans
[2012-06-14 14:14:28 - humei_cc] Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans
[2012-06-14 14:14:28 - humei_cc] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException
[2012-06-14 14:14:28 - humei_cc] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
………………………………………………………………………………中間部分省略
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.NativeClipboard: can't find referenced class java.awt.datatransfer.Clipboard
[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.NativeClipboard: can't find referenced class java.awt.datatransfer.Clipboard
[2012-06-14 14:14:28 - humei_cc] Warning: there were 288 unresolved references to classes or interfaces.
[2012-06-14 14:14:28 - humei_cc] You may need to specify additional library jars (using '-libraryjars'),
[2012-06-14 14:14:28 - humei_cc] or perhaps the '-' option.
[2012-06-14 14:14:28 - humei_cc] java.io.IOException: Please correct the above warnings first.
[2012-06-14 14:14:28 - humei_cc] at proguard.Initializer.execute(Initializer.java:308)
[2012-06-14 14:14:28 - humei_cc] at proguard.ProGuard.initialize(ProGuard.java:210)
[2012-06-14 14:14:28 - humei_cc] at proguard.ProGuard.execute(ProGuard.java:85)
[2012-06-14 14:14:28 - humei_cc] at proguard.ProGuard.main(ProGuard.java:499)
我的proguard.cfg 文件時這樣的
-optimizationpasses 5
-dontusemixedcaseclassnames
-
-verbose
-ignorewarnings
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-libraryjars libs/bcprov-jdk15on-147.jar
-libraryjars libs/PanoramaGL.jar
-libraryjars libs/activation.jar
-libraryjars libs/additionnal.jar
-libraryjars libs/mail.jar
-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
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
已經嘗試的方案:方案一: 加入-ignorewarnings 可以正常打包了。 能過濾掉警告信息。但是治標不治本,打好的包,在實際運行中用到過的第3方包類庫時,均報空指針。方案二:不使用-ignorewarnings 添加-dontwarn java.awt.datatransfer.Transferable.** 警告信息並沒有減少,打包會失敗。
I. android 不混淆可以打包嗎
可以。
混淆打包流程:
1.在proguard-project.txt文件中添加不需要混淆的類和第三方的jar包
這個是保持自己包中不需要混淆的類,如果有些類調用了jni也不需要混淆,不然會出錯。還有如果項目中有其他項目作為library引入,那這些項目的一些類也不能混淆。
這個是保持項目中的第三方jar不混淆
另外加上上面幾句話,不然會在控制台中報warning警告
J. android 不混淆類和類中的變數名
指定某個包下的所有class不混淆
-keep class com.custom.view.** { *; }