Android库模块使用proguard [英] Android Library module use proguard

查看:52
本文介绍了Android库模块使用proguard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个安全的库模块,没有人可以从apk文件中提取代码.但是当尝试在库gradle中启用proguard时,获取错误包不存在.然后我在Proguard规则文件中添加以下行

I want to create secure library module that no one can extract code from apk file. but when try to enable proguard in library gradle getting error package does not exists. then i add following line in proguard rules file

-keep class com.alprocr.** { *; }
-keep class com.xyz.alpr.** { *; }
-keep class com.xyz.alpr.doc.** { *; }

添加此代码应用程序工作文件后.但是当我使用apktool从apk提取代码时,我从apk文件中获取了完整的源代码.当有人尝试提取apk文件时,我需要不可读的代码.有可能吗?

after add this code app working file. but when i extract code from apk using apktool then i got complete source code from apk file. I want non-readable code when someone try to extract apk file. Is it possible?

我还尝试允许收缩资源,但不存在获得相同错误包的情况

i also try to allow shrinkresource but getting same error package does not exists

-keep,allowshrinking class com.alprocr.** { *; }
-keep,allowshrinking class com.xyz.alpr.** { *; }
-keep,allowshrinking class com.xyz.alpr.doc.** { *; }

等级代码

buildTypes {

        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

推荐答案

您必须更加准确地告诉Proguard如何工作.

You have to be more precise with telling Proguard how to work.

首先最好使用别名-keepnames代替-keep,allowshrinking.然后只保留公共班级和受保护的班级成员.实际上意味着不缩小这些部分.

First better use the alias -keepnames instead of -keep,allowshrinking. Then only keep the public classes and protected class members. Meaning actually to not shrink these parts.

-keep,allowobfuscation public class com.alprocr.** { public protected *; }
-keep,allowobfuscation public class com.xyz.alpr.** { public protected *; }
-keep,allowobfuscation public class com.xyz.alpr.doc.** { public protected *; }

这些是您进入图书馆的入口点.默认情况下,所有不公开或不受保护的内容都会被缩小和/或模糊化.

These are your entry-points to the library. Everything not public or protected will be shrunk and/or obfuscated by default.

这篇关于Android库模块使用proguard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆