SDK开发怎么混淆代码?

ithouse 2016-06-06 09:10:37
我所在的公司要求我开发一个SDK供其他公司使用,但是我所在的公司不希望公开SDK的源代码。我使用的是Android Studio开发,建立了一个module,怎么混淆这个module的代码?我尝试了一下proguard,似乎并不奏效。
...全文
478 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ithouse 2016-06-15
  • 打赏
  • 举报
回复
谢谢大家了,找到了,因为是lib项目,不是Project,直接在安卓的module上编译提交并不能让混淆生效,唯有将lib代码导出为jar,再用ProGuard进行混淆,再将这个jar作为module的引用jar,再次上传,清空网站缓存,可以看到,混淆成功了。
网易云捕 2016-06-07
  • 打赏
  • 举报
回复
请配置android sdk模块的build.gradle文件,可以参考如下: buildTypes { debug { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } 然后修改proguard-rules.pro内容,例如在打包后优化掉log不再输出信息: -assumenosideeffects class android.util.Log { public static *** d(...); public static *** e(...); public static *** i(...); public static *** w(...); } 给你贴一份完整的proguard-rules.pro文件参考吧: # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in D:\IDE\adt-bundle-windows-x86-20130522\sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} -dontshrink -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -optimizationpasses 5 -dontusemixedcaseclassnames -keepattributes *Annotation* -dontpreverify -verbose -dontwarn android.support.v4.* -ignorewarnings -keep class * extends NativeCrashHandler -keep,allowshrinking class * extends android.app.ActivityManager -keep,allowshrinking class * extends android.app.Context -keep,allowshrinking class * extends android.content.Intent -keep,allowshrinking class * extends android.content.pm.ApplicationInfo -keepnames class **ReLinker* -keepnames class **CrashHandler* -keepnames class **UserStrategy* -keepnames class **H5JavaScriptInterface* -keepclassmembers class **CrashHandler* { public <methods>; } -keepclassmembers class **H5JavaScriptInterface* { public *; } -keepclassmembers class **UserStrategy* { public <methods>; } -keepclassmembers class **ReLinker* { public <methods>; } -assumenosideeffects class android.util.Log { public static *** d(...); public static *** e(...); public static *** i(...); public static *** w(...); } # Keep names - Native method names. Keep all native class/method names. -keepclasseswithmembers,allowshrinking class * { native <methods>; }
网易云捕 2016-06-07
  • 打赏
  • 举报
回复
使用proguard。具体可以查看:http://blog.sina.com.cn/s/blog_7da2c903010186wv.html
jeky_zhang2013 2016-06-06
  • 打赏
  • 举报
回复
怎么配置的?要找到不生效的原因

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧