Android如何保持指定类不被混淆?

作者&投稿:营石 (若有异议请与网页底部的电邮联系)
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 duplicate 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 '-dontskipnonpubliclibraryclasses' 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

-dontskipnonpubliclibraryclasses

-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 ;

}

-keepclasseswithmembers class * {

public (android.content.Context, android.util.AttributeSet);

}

-keepclasseswithmembers class * {

public (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.** 警告信息并没有减少,打包会失败。

  为了解决第三方包不被混淆,第三方包在混淆后,运行的时候会挂掉。我的错误是java.lang.ExceptionInInitializerError


[java] E/AndroidRuntime( 9608):
java.lang.ExceptionInInitializerError
E/AndroidRuntime( 9608): at
a.a.b.f.(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.b.e.(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
  -dontskipnonpubliclibraryclasses
  -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 ;
  }
  
  # 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 ;
  }
  
  # 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
  -dontskipnonpubliclibraryclasses
  -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 ;
  }

  # 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 ;
  }

  # 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.**

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




android手机如何保资料解锁
若三星手机屏幕锁密码忘记,建议您尝试通过远程控制功能解锁:手机需要支持Samsung Dive远程控制功能,且开启远程控制、移动数据(或WLAN);手机绑定三星账户,请登陆三星远程控制网址,使用三星账户登陆后,点击“解锁我的设备”,通过此方式操作后将会把之前设置的锁屏方式更改为默认的滑动解锁方式。若手机不...

Android安全App大调查:大多无法有效保护用户!介绍_Android安全App大调 ...
在Android系统广泛使用的背景下,许多用户期待安装防病毒应用来提升设备安全性。然而,一项针对250款Android防病毒软件的深入评估揭示了令人担忧的事实:大部分产品并未达到预期的保护效果。独立评测机构AV-Comparatives进行的大规模测试结果显示,这些安全应用的功能表现模糊,甚至存在安全隐患,未能有效识别和阻止...

怎么让android手机通过USB线连接电脑时屏幕保持常亮
手机屏幕长亮:在手机“设置”-->“显示”-->“休眠”选项设置永不休眠,这是我的android手机的设置方式,不同的手机可能会有区别,你自己找下!

怎么让一个软件一直在后台运行?
也就是手机的操作系统。主要的手机基频厂家有德州仪器、爱立信移动后台、高通、联发科、NXP、飞思卡尔、英飞凌、博通、展讯。手机操作后台已经形成LiMo、Symbian、Android、WindowsPhone(旧称WindowsMobile)等群雄争霸的局面,但无论它们如何发展,开源都将是必然的趋势。

华硕ZenFone 8的Android 12稳定版更新带来了哪些隐私保护功能?
结论:华硕ZenFone 8,常被称为安卓版iPhone 12 mini,近日迎来了Android 12的稳定版更新,版本号为31.1004.0404.55。这款小巧的安卓旗舰因其5.9英寸、2400×1080分辨率的高刷屏幕而备受瞩目,尺寸在当前安卓旗舰中独树一帜。更新亮点主要体现在个性化设置上,用户可以自定义调色板和小工具,充分展现...

Android手机的软件问题在保修范围内吗?(我误删了系统文件,导致不能开机...
不同公司的保修条款不一样,一般情况下售后会免费给你刷回系统。但按标准说,你这属于人为损坏,是不在免费保修范围的。其实你也可以上网查看相应机型的ROM刷机教程,自行解决。多问问网友,加入一些机型讨论群,刷机其实不难。

android开发,关于资源保护问题
不要使用系统默认的这种drawable方式保存直接的png等图片,把图片的像素数据自己处理一下,比如可以简单的做一下压缩,或者复杂一点的加密,然后在加载的时候做逆运算,用Bitmap的加载数据流的方式加载,而不是资源ID。

com.android.com进程意外停止,在有效期内拿保修卡到营业厅里,能保修吗...
这个包名应该不是ANDROID原生自带的包名啊,检查你安装的APK吧。坏你你中毒了。这个问题是软件问题。和手机本身没关系。建议你刷下机器吧。

android 获取root权限会失去质保吗
会的,不管你有没删,都不会给你保的。不过放心root吧,通常是没啥问题的。

谷歌删除Android隐私保护功能是真的吗?
12月14日消息,谷歌删除了其Android手机软件上一款实验性隐私保护功能,该功能可使用户阻止应用随意访问个人隐私数据,比如地址簿和用户位置数据等。这意味着谷歌Android 4.4.2版本智能手机的用户,未来在使用某些特定应用时,必须对外提供他们个人数据的访问权。

峄城区13411609873: Android如何保持指定类不被混淆? -
原航苏可: 加上完整的包名才行.-keep class com.example.test.WebAppInterface {*;}

峄城区13411609873: android 怎么实现只混淆自己的代码,而不混淆第3方 -
原航苏可: 混淆打包流程: 1在proguard-projecttxt文件中添加不需要混淆的类和第三方的jar包 这个是保持自己包中不需要混淆的类,如果有些类调用了jni也不需要混淆,不然会出错.还有如果项目中有其他项目作为library引入,那这些项目的一些类也不能混淆android 怎么实现只混淆自己的代码,而不混淆第3方

峄城区13411609873: android 如何取消第三方包混淆
原航苏可: keep 住第三方包对应的包名或或者指定类.如: -keep public class android.app.**

峄城区13411609873: android中为什么要指定第三方包的中内容不混淆呢/ -
原航苏可: 其实第三方jar包是不能混淆,这里指定第三方jar包不混淆的意思是,在你的项目中的调用到第三方jar包的语句不被混淆,你想想,如果jar包是com.umeng,你调用的地方被混淆成了a.b,这样你生成的apk里面不是找不到a.b了么,肯定会报错撒

峄城区13411609873: Android 开发怎样做代码加密或混淆 -
原航苏可: Proguard对一般用途来说足够了,但是也需要注意一些程序风格,增强proguard的效果:1. 特定类的public函数不做实际的事情,只做简单处理后调用private函数.proguard对会对一些特定类的public函数不做混淆,以便被AndroidManifest.xml和各种layout引用.2. 会被AndroidMinifest.xml和layout引用的类放在浅层的包中,需要隐藏的类放在较深处,以便proguard混淆包名带来好处.如果一个包中有需要不混淆的内容,则整个包名都不会被混淆.3. 将函数根据功能分细切短也会有些益处.如果隐藏代码的要求比较高,还是用native好了.

峄城区13411609873: 如何禁止android默认编译选项 -
原航苏可: 为Android应用开发者,不得不面对一个尴尬的局面,就是自己辛辛苦苦开发的应用可以被别人很轻易的就反编译出来.Google似乎也发现了这个问题,从SDK2.3开始我们可以看到在android-sdk-windows\tools\下面多了一个proguard文件夹 ...

峄城区13411609873: 关于Android studio 怎么使用代码混淆的问题 -
原航苏可: 1,在build.grandle添加,其中规则写在proguard-rules.pro中,也可以自定义一个文件,将其代替,比如eclipse常用的 proguard-project.txt buildTypes { release { signingConfig signingConfigs.release minifyEnabled true proguardFiles ...

峄城区13411609873: android 加入library如何混淆 -
原航苏可: android工程会看到项目有 project.properties 这个文件就是用来开启项目是否混淆 proguard-project.txt 这个文件就是记录了代码混淆的属性 要开启混淆,只需要将project.properties 文件中的# proguard.config=${sdk.dir}/tools/proguard/proguard-...

峄城区13411609873: android 代码混淆怎么没效果 -
原航苏可: 如果你没用到第三方的library或者jar包,那么只要在工程目录下project.properties里面,把#proguard.config=xxxxxx前面的#去掉就好了.如果有第三方的jar包,那么把需要的配置加到proguard-project.txt里面就好.

峄城区13411609873: android代码混淆以及怎么判断一个apk代码是否被混淆过 -
原航苏可: 反编译一下,没有混淆过的反编译过来和你正常的代码一样 混淆过的反编译过来的,代码结构和原来一样,但是里面的方法名可能都被改成 public void a()这样的了

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网