導航:首頁 > 操作系統 > android不混淆內部類

android不混淆內部類

發布時間:2022-11-18 20:54:36

android代碼混淆為什麼不混淆Activity

不混淆Activity 的類是因為這個在manifest中聲明了,如果混淆了就找不到了。
所有在xml中注冊的都不能混淆,而且設置的是不混淆這些類名或某些方法,如果是這樣寫:-keepclassmembers class * extends android.app.Activity {*;},就是內部所有都不混淆,要是只寫:-keep public class * extends android.app.Activity,只是類名不會混淆,可以反編譯下自己混淆過的代碼就看出來了。更多關於安卓混淆的辦法請參考android學習手冊,例子、源碼、文檔全部搞定,採用androidstudo的目錄結構,360手機助手中下載。下面是截圖。

② android 不混淆類和類中的變數名

指定某個包下的所有class不混淆
-keep class com.custom.view.** { *; }

③ 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.** 警告信息並沒有減少,打包會失敗。

④ android 不混淆可以打包嗎

可以。
混淆打包流程:
1.在proguard-project.txt文件中添加不需要混淆的類和第三方的jar包

這個是保持自己包中不需要混淆的類,如果有些類調用了jni也不需要混淆,不然會出錯。還有如果項目中有其他項目作為library引入,那這些項目的一些類也不能混淆。

這個是保持項目中的第三方jar不混淆

另外加上上面幾句話,不然會在控制台中報warning警告

⑤ android代碼混淆為什麼不混淆activity

一般四大組件不混淆的,主要有以下原因:

1.四大組件聲明必須在manifest中注冊,如果混淆後類名更改,而混淆後的類名沒有在2.manifest注冊,是不符合Android組件注冊機制的.

3.外部程序可能使用組件的字元串類名,如果類名混淆,可能導致出現異常

4.四大組件是要配置在清單文件的,混淆了找不到

⑥ Android如何保持指定類不被混淆

包名 package com.example.test
類名 public class WebAppInterface{}
加上完整的包名才行。
-keep class com.example.test.WebAppInterface {*;}

⑦ android 怎麼實現只混淆自己的代碼,而不混淆第3方jar包

1. 新建一個工程會看到項目下邊有這樣proguard-project.txt一個文件,這個對混淆代碼很重要,如果不小心刪掉了,沒關系,從其他地方拷貝一個過來
2. 最重要的就是在proguard-project.txt添加混淆的申明了:
a. 把所有的jar包都申明進來,例如:
-libraryjars libs/apns_1.0.6.jar
-libraryjars libs/armeabi/libBaiMapSDK_v2_3_1.so
-libraryjars libs/armeabi/liblocSDK4.so
-libraryjars libs/mapapi_v2_3_1.jar
-libraryjars libs/core.jar
-libraryjars libs/gesture-imageview.jar
-libraryjars libs/gson-2.0.jar
-libraryjars libs/infogracesound.jar
-libraryjars libs/locSDK_4.0.jar
-libraryjars libs/ormlite-android-4.48.jar
-libraryjars libs/ormlite-core-4.48.jar
-libraryjars libs/universal-image-loader-1.9.0.jar

b. 將你不需要混淆的部分申明進來,因為有些類經過混淆會導致程序編譯不通過,如下:

-keep public class * extends android.app.Fragment
-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 * extends android.support.v4.**
-keep public class com.android.vending.licensing.ILicensingService

--以上都是API里邊的類,最好都要避免混淆

有些很特殊的,例如網路地圖,你需要添加以下申明:

-keep class com..** { *; }
-keep class vi.com.gdi.bgl.android.**{*;}

根據我的經驗,一般model最好避免混淆(model無關緊要,不混淆也沒多大關系)如:

-keep class com.bank.pingan.model.** { *; }
下面在貼上關於Umeng分享統計的避免混淆的申明

-dontwarn android.support.v4.**
-dontwarn org.apache.commons.net.**
-dontwarn com.tencent.**

-keepclasseswithmembernames class * {
native <methods>;
}

-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

-keepclasseswithmembers class * {
public <init>(android.content.Context);
}

-dontshrink
-dontoptimize
-dontwarn com.google.android.maps.**
-dontwarn android.webkit.WebView
-dontwarn com.umeng.**
-dontwarn com.tencent.weibo.sdk.**
-dontwarn com.facebook.**

-keep enum com.facebook.**
-keepattributes Exceptions,InnerClasses,Signature
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable

-keep public interface com.facebook.**
-keep public interface com.tencent.**
-keep public interface com.umeng.socialize.**
-keep public interface com.umeng.socialize.sensor.**
-keep public interface com.umeng.scrshot.**

-keep public class com.umeng.socialize.* {*;}
-keep public class javax.**
-keep public class android.webkit.**

-keep class com.facebook.**
-keep class com.umeng.scrshot.**
-keep public class com.tencent.** {*;}
-keep class com.umeng.socialize.sensor.**

-keep class com.tencent.mm.sdk.openapi.WXMediaMessage {*;}

-keep class com.tencent.mm.sdk.openapi.** implements com.tencent.mm.sdk.openapi.WXMediaMessage$IMediaObject {*;}

-keep class im.yixin.sdk.api.YXMessage {*;}
-keep class im.yixin.sdk.api.** implements im.yixin.sdk.api.YXMessage$YXMessageData{*;}

-keep public class [your_pkg].R$*{
public static final int *;
}
3.以上工作完成,混淆工作就完成了一大半了,最後需要做的就是在project.properties文件中加上混淆文件申明了,如下
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
4. OK, 最後一步,打簽名包測試,如果有問題,仔細看下Log也許有得類不能混淆,那麼你得加入到proguard-project.txt文件中
-------以上就是混淆代碼的全過程了

⑧ android 內部類 為什麼不能混淆

針對1234的回答如下: 1,2,4要一起說,這是採用的是傳值的方式,這比較靈活。如果傳入的MainActivity與當前MainActivity是同一個對象,那麼可以直接使用MainActivity.this;如果傳入的MainActivity與當前的MainActivity不是同一個對象,這種傳...

⑨ android中為什麼要指定第三方包的中內容不混淆呢/

其實第三方jar包是不能混淆,這里指定第三方jar包不混淆的意思是,在你的項目中的調用到第三方jar包的語句不被混淆,你想想,如果jar包是com.umeng,你調用的地方被混淆成了a.b,這樣你生成的apk裡面不是找不到a.b了么,肯定會報錯撒

⑩ android中哪些東西不能做代碼混淆

常見的不能混淆的AndroidCodeAndroid 程序 ,下面這樣代碼混淆的時候要注意保留。

Android系統組件,系統組件有固定的方法被系統調用。

被Android Resource 文件引用到的。名字已經固定,也不能混淆,比如自定義的View 。

Android Parcelable ,需要使用android 序列化的。

其他Anroid 官方建議 不混淆的,如

android.app.backup.BackupAgentHelper
android.preference.Preference
com.android.vending.licensing.ILicensingService
Java序列化方法,系統序列化需要固定的方法。

枚舉 ,系統需要處理枚舉的固定方法。

本地方法,不能修改本地方法名

annotations 注釋

資料庫驅動

有些resource 文件

用到反射的地方

閱讀全文

與android不混淆內部類相關的資料

熱點內容
dvd光碟存儲漢子演算法 瀏覽:757
蘋果郵件無法連接伺服器地址 瀏覽:963
phpffmpeg轉碼 瀏覽:671
長沙好玩的解壓項目 瀏覽:145
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:737
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:485
h3c光纖全工半全工設置命令 瀏覽:143
公司法pdf下載 瀏覽:382
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:349
風翼app為什麼進不去了 瀏覽:778
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:150
伊克塞爾文檔怎麼進行加密 瀏覽:892
app轉賬是什麼 瀏覽:163