简体   繁体   English

-keep类com.sample.Foo {*;}和-keep类com.sample.Foo有什么区别?

[英]What's the difference between -keep class com.sample.Foo {*;} and -keep class com.sample.Foo?

I just built two release APKs. 我刚刚建立了两个发行版APK。

One of them had 其中一个有

-keep class com.sample.Foo

And the other had 另一个有

-keep class com.sample.Foo {*;}

When I decompiled the app on http://www.javadecompilers.com/apk , Foo was the same for both builds. 当我在http://www.javadecompilers.com/apk上对应用程序进行反编译时,两个版本的Foo都是相同的。

The code of Foo is below: Foo的代码如下:

package com.sample;

import android.util.Log;

public class Foo {

    public int field;

    public Foo() {
        field = 90;
    }

    public int doSth() {
        doPrivate();
        return 2 * field;
    }

    private void doPrivate() {
        Log.d("Proguard", "doPrivate");
    }

    void doDef() {
        Log.d("Proguard", "doDef");
    }
}

That's how I made sure Foo and its methods weren't obfuscated: 这就是我确保Foo及其方法没有被混淆的方式:

package com.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.lang.reflect.Method;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try {
            Class<?> aClass = Class.forName("com.sample.Foo");
            Object instance = aClass.newInstance();
            Method method = aClass.getMethod("doSth");
            Integer res = (Integer) method.invoke(instance);
            Log.d("Proguard", "doSth res=" + res);
        } catch (Exception e) {
            Log.e("Proguard", "", e);
        }
    }
}

Update #1 更新#1

My Proguard config. 我的Proguard配置。

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

The first one only keeps the class and its constructor. 第一个仅保留类及其构造函数。

The second one keeps the class and its constructor and any field or method inside the class. 第二个则保留该类及其构造函数以及该类内的任何字段或方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 -keep class和-dontwarn有什么区别 - what is the difference between -keep class and -dontwarn &#39;-keep class ab **&#39;和&#39;-keep class ab ** {}&#39;之间的区别 - Difference between '-keep class a.b.**' and '-keep class a.b.** {}' Class &lt;*&gt;和Class有什么区别<T> - What's the difference between Class<*> and Class<T> com.actionbarsherlock.app.SherlockListActivity.class和ListView之间的区别 - difference between com.actionbarsherlock.app.SherlockListActivity.class and ListView Firebase for Unity示例应用程序因以下原因崩溃:找不到类&#39;com.google.android.gms.common.api.PendingResult&#39; - Firebase for Unity sample app crashes with: Could not find class 'com.google.android.gms.common.api.PendingResult' proguard - keep 和 keep { } 语句有什么区别? - proguard - what is difference between - keep and keep { } statement? android 和 com.android 有什么区别? - What's the difference between android and com.android? 如何仅混淆com.foo。*但不混淆com.foo.bar。*? (Proguard) - How can I obfuscate only com.foo.* but excluding com.foo.bar.*? (Proguard) “foo_model”引用的 JVM object 属于“类”类型<foo> ' 并且它无权访问在 'Foo' 中声明的字段 'float a'</foo> - JVM object referenced by 'foo_model' is of type 'Class<Foo>' and it does not have access to field 'float a' declared in 'Foo' 样本适配器类错误 - error with sample adapter class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM