如何从删除类型参数停止Proguard的? [英] How do you stop Proguard from removing type parameters?

查看:122
本文介绍了如何从删除类型参数停止Proguard的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在试图混淆一系列库。我的基本库,其中包含几类,并使用类型参数的方法,是无法使用其他code,由于通过Proguard的混淆要删除的类型参数。消除混淆消除这些问题。我已经通过所有ProGuard的使用文档,示例和故障排除的阅读,但一直无法找到如何应对类型参数或ProGuard的方面剥离类型参数的任何文件。

构造类型参数问题:

库1包含以下类:

 公共抽象类AbstractFactoryFactory< T>
 

库2中的多个类扩展上述类,但在构造函数抛出一个编译器错误,指出:

 错误:类型AbstractFactoryFactory不带参数
 

返回类型参数问题:

库1具有以下方法Foo类:

 公开名单<字符串>做一点事()
 

Libary 2尝试使用doSomething的方法,但模糊处理后该方法返回一个类型化的列表生成以下编译器错误,指出:

 错误:不兼容的对象类型
 

Proguard.cfg

  -dontoptimize

-renamesourcefileattribute的SourceFile
-keepparameternames
-keepattributes例外,*注释*,InnerClasses,的SourceFile,LineNumberTable,德precated

-keep公共类* {
    公众保护*;
}

-keepclassmembers枚举* {
    公共静态** []值();
    公共静态**的valueOf(java.lang.String中);
}

-keepclassmembernames类* {
    它是java.lang.Class类$(java.lang.String中);
    它是java.lang.Class类$(java.lang.String中,布尔值);
}

-keepclasseswithmembernames类* {
    天然的LT;方法&gt ;;
}

-keepclassmembers类*实现了java.io.Serializable {
    静态最后长的serialVersionUID;
    私有静态最后java.io.ObjectStreamField [] serialPersistentFields;
    私人无效的writeObject(java.io.ObjectOutputStream中);
    私人无效的readObject(java.io.ObjectInputStream中);
    java.lang.Object中writeReplace();
    java.lang.Object中的readResolve();
}
 

解决方案

据ProGuard的典型的图书馆使用指南< /一>:

  

签名属性是必需的JDK 5.0编译和更高时,能够访问泛型类型。

添加以下行固定我的问题,缺少的类型参数:

  -keepattributes签名
 

I am currently attempting to obfuscate a series of libraries. My base library, which contains several classes and methods that use type parameters, is unusable by other code due to the type parameters being removed by Proguard obfuscation. Eliminating the obfuscation removes these issues. I have read through all of the ProGuard usage documents, examples, and troubleshooting, but have been unable to find any documentation on how to deal with type parameters or which aspect of ProGuard strips the type parameters.

Constructor Type Parameter Issue:

Library 1 contains the following class:

public abstract class AbstractFactoryFactory<T>

Library 2 contains several classes that extend the above class but the constructor throws a compiler error that states:

error: type AbstractFactoryFactory does not take parameters

Return Type Parameter Issue:

Library 1 has a Foo class with the following method:

public List<String> doSomething()

Libary 2 tries to use the doSomething method, but after obfuscation the method returns an untyped list that generates the following compiler error that states:

error: incompatible types Object

Proguard.cfg

-dontoptimize

-renamesourcefileattribute SourceFile
-keepparameternames
-keepattributes Exceptions,*Annotation*,InnerClasses,SourceFile,LineNumberTable,Deprecated

-keep public class * {
    public protected *;
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keepclassmembernames class * {
    java.lang.Class class$(java.lang.String);
    java.lang.Class class$(java.lang.String, boolean);
}

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

解决方案

According to the ProGuard Typical Library usage guide:

The "Signature" attribute is required to be able to access generic types when compiling in JDK 5.0 and higher.

Adding the following line fixed my issues with missing type parameters:

-keepattributes Signature

这篇关于如何从删除类型参数停止Proguard的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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