Proguard(R8)否定运算符除某些软件包外不保留任何其他内容 [英] Proguard (R8) negate operator not working to keep anything except certain packages

查看:135
本文介绍了Proguard(R8)否定运算符除某些软件包外不保留任何其他内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

proguard中的否定符(感叹号)应该允许我继续使用,但是apache库:

The negator (exclamation mark) in proguard should allow me to keep anthing but the apache libraries:

-keep class !org.apache.**

根据这些答案.那是要走的路:

According to those answers. That's the way to go:

  • How to negate classname with Proguard
  • Enable Proguard for only two packages in large Android application
  • Android proguard Ignore All Classes except of one
  • Proguard Android do not obfuscate anything except few classes
  • Proguard: How to keep everything except specific condition?
  • Can we shrink all classes but only obfuscate some with proguard?

但是,它混淆了我APK中的所有类.

However, it obfuscates all classes in my APK.

这是我的build.gradle的一部分(我有Android Studio 3.5.3)

That's part of my build.gradle (I have Android Studio 3.5.3)

compileSdkVersion 29
buildToolsVersion "29.0.2"
//...
buildTypes {

    release {

        minifyEnabled true
        proguardFiles /*getDefaultProguardFile('proguard-android.txt'),*/  'proguard-rules.pro'

        // Enables resource shrinking, which is performed by the
        // Android Gradle plugin.
        shrinkResources false
    }
}

dependencies {
    //Utility libs
    implementation 'org.apache.commons:commons-collections4:4.1'
    implementation 'org.apache.commons:commons-lang3:3.4'
    implementation group: 'commons-io', name: 'commons-io', version: '2.5'
}

-printconfiguration添加到我的proguard-rules.pro文件后,我看到在-keep class !org.apache.**

After I added -printconfiguration to my proguard-rules.pro file I saw there are numerous -keep rules following my -keep class !org.apache.**

-printconfiguration
-keep class !org.apache.**

# Referenced at ***anonymized***\app\build\intermediates\merged_manifests\release\AndroidManifest.xml:180
-keep class android.support.v4.app.CoreComponentFactory { <init>(); }
# Referenced at ***anonymized***\app\build\intermediates\merged_manifests\release\AndroidManifest.xml:180
-keep class com.mycompany.MyApplication { <init>(); }
# Referenced at C:\Users\***anonymized***\.gradle\caches\transforms-2\files-2.1\7f5f0b3369d8fa8a72a20e2278ec0acc\appcompat-v7-28.0.0\res\layout\abc_action_menu_item_layout.xml:17
-keep class android.support.v7.view.menu.ActionMenuItemView { <init>(...); }

Ezekiel Baniaga 建议的方法也不起作用.相反,它保留了包括apache软件包在内的所有内容:

That approach suggested by Ezekiel Baniaga also didn't work. Instead it keeps everything including the apache packages:

proguard-rules.pro

-printconfiguration

-dontshrink

-dontoptimize

-dontobfuscate

-keep,allowshrinking,allowoptimization,allowobfuscation class org.apache.**

推荐答案

我必须添加,**才能使其正常运行.谢谢T. Neidhart

I had to add ,** to get it working. Thanks T. Neidhart!

-keep class !org.apache.**,**

前面的示例保留了类名,但仍然混淆了成员.所以我不得不添加{ *; }:

The previous example preserved class names but still obfuscated members. So I had to add { *; }:

-keep class !org.apache.**,** { *; }

这就是我混淆多个软件包的方式(我必须一口气使用它们!)

That's how I obfuscate multiple packages (I have to use them all in one keep rule!)

-keep class !org.apache.**, !org.zeroturnaround.**, !com.drew.**, ** { *; }

要找出我对-dontshrink -dontoptimize -dontobfuscate -keep,allowshrinking,allowoptimization,allowobfuscation class org.apache.**的问题,我可以根据

To find out what my problem is with -dontshrink -dontoptimize -dontobfuscate -keep,allowshrinking,allowoptimization,allowobfuscation class org.apache.** I could add -whyareyoukeeping according to https://www.guardsquare.com/en/products/proguard/manual/usage

这篇关于Proguard(R8)否定运算符除某些软件包外不保留任何其他内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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