⑴ 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 Studio在真機上運行的APP啟動速度特別慢,而通過簽名打出的apk安裝後app速度卻很快怎麼回事
Android Studio提供debug和release兩種構建類型,默認採用debug類型調試Android項目,debug和release的區別有幾個方面:
debug模式的幾個特點:
1. 支持斷點調試和log信息列印,debuggable屬性值為true
2. 使用系統默認的密鑰庫簽署apk文件
3. 沒有對apk文件進行代碼和資源文件的優化(包括文件壓縮、冗餘文件刪除)
4. 沒有對代碼進行混淆
release模式需要注意的幾個特點:
1. 不支持斷點調試,debuggable默認為false
2. 沒有壓縮類文件代碼,minifyEnabled,默認為false
3. 沒有壓縮資源文件,shrinkResources,默認為false
4. 沒有指定自定義簽名文件,默認使用系統的密鑰庫簽署apk
真機上直接連接調試,因為沒有代碼、資源文件進行壓縮,同時支持斷點調試等原因造成運行緩慢;相反,簽名後的apk文件,相對來說比較快,可以深入理解Android Studio構建文件build.gradle配置相關資料
⑶ android 不混淆可以打包嗎
可以。
混淆打包流程:
1.在proguard-project.txt文件中添加不需要混淆的類和第三方的jar包
這個是保持自己包中不需要混淆的類,如果有些類調用了jni也不需要混淆,不然會出錯。還有如果項目中有其他項目作為library引入,那這些項目的一些類也不能混淆。
這個是保持項目中的第三方jar不混淆
另外加上上面幾句話,不然會在控制台中報warning警告
⑷ android studio怎麼混淆代碼
Android Studio上混淆打包apk方法:
//混淆,新版本是ninifyEnabled不再是runproguard
minifyEnabled true
//載入默認混淆配置文件及自定義混淆 配置
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard.cfg'
設置minifyEnabled true,就會在打包的時候進行代碼混淆處理. 其中proguard-android.txt不用管,在sdk目錄裡面,主要是配置了proguard.cfg文件。
直接在android studio創建項目不會有這個文件,而是 proguard-rules.pro文件,其實一樣的,因為項目是從eclipse遷移過來的,之前在eclipse上混淆是 proguard.cfg文件.
⑸ AndroidStudio自帶的混淆配置
###########################以下是AndroidStudio自尺液帶的混淆配好嫌置協議###############################
-dontusemixedcaseclassnames
-
-verbose
-dontoptimize
-dontpreverify
-keepattributes Annotation
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers public class * extends android.view.View {
void set ( * );
*** get ();
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class * .R$ {
public static <fields>;
}
-dontwarn android.support.**
-keep class android.support.annotation.Keep
-keep @android.support.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <init>(...);
}
###########################以友困手下是需要手動的混淆配置協議###############################
-libraryjars "C:Program FilesJavajre1.8.0_151lib t.jar"
-optimizationpasses 5
-dontusemixedcaseclassnames
-ignorewarnings
-keep class com.zhuge.analysis.stat.ZhugeParam{
*;
}
-keep class com.zhuge.analysis.listeners.ZhugeInAppDataListener{
*;
}