peacepassion peacepassion - 6 months ago 35
Android Question

How proguard can skip some reserved names as mapping result

I am developing a gradle plugin. It generates a source java file after proguard based on the mapping.txt. The content looks like following.

public class bmdb {

private static Map<Class<?>, Injector<Object>> map = new HashMap<>();

static {
try {
map.put(a.a.b.c.class, new a.a.b.d());

} catch (Exception e) {

public static Map<Class<?>, Injector<Object>> a() {
return map;

And this java file will be compiled to a class file. However, sometimes the mapped result would be java key words, like
. And the compilation would fail.

So I wonder if proguard has any option which can exclude some words for the mapping result.


Finally, I found proguard does not support such configuration.

And I use following workround:
1. I write a string array containing Java key words like following:
String[] keyWords = ["do", "if", ...];
2. I would check the proguard result if it is in the above array. If NO, the normal new abc() will be used, and If YES, the reflection Class.forName("for") will be used.

So the result might be like following:

map.put(a.a.b.c.class, new d());
map.put(a.a.b.d.class, Class.forName("for").newInstance());