简体   繁体   English

使用 Proguard 在 Android 中禁用日志

[英]Disabling Logs in Android with Proguard

i added proguard rule -assumenosideeffects class android.util.Log {public *;} so my release version have no logs.我添加了 proguard rule -assumenosideeffects class android.util.Log {public *;}所以我的发布版本没有日志。 but after that a specific methode stoped working:但在那之后,一个特定的方法停止工作:

SingleShotLocationProvider.requestSingleUpdate(PassagerActivity.this,
                        new SingleShotLocationProvider.LocationCallback() {
                            @Override public void onNewLocationAvailable(SingleShotLocationProvider.GPSCoordinates location) {

                              //  Log.e("xxx",location.latitude + "/" +location.longitude);

                                map.setCenter(new GeoCoordinate(location.latitude, location.longitude, 0.0),
                                        Map.Animation.NONE);

                                currentloc = new LatLng(location.latitude, location.longitude);
                               // loadingDialog.stopLoadingDialog();
                                new Thread(new Runnable() {
                                    public void run() {
                        
                                GeoCoderApi.getAdressfromLatLng(PassagerActivity.this , location ,new GeoCoderApi.AdressCallback() {
                                    @Override
                                    public void onAdressAvailable(String adress) {

                                      //  Log.e("xxxadress",adress);
                                        addDepart.post(new Runnable() {
                                            public void run() {
                                                addDepart.setText(adress);
                                            }
                                        });
                                    }
                                });    }}).start(); 
                            }
                        });

this methode get the lat and lng and get an adress from google GeoCoder.此方法获取 lat 和 lng 并从 google GeoCoder 获取地址。 when i remove the proguard rule everything works just fine .当我删除 proguard 规则时,一切正常。 Dont even know how it s related.甚至不知道它是如何相关的。 i tried it in 4 different devices.我在 4 种不同的设备上尝试过。

EDIT:编辑:

Here u can see that the map.center() works and i can get the localisation it s just the addDepart.setText() that doesnt work.在这里你可以看到 map.center() 工作,我可以得到本地化它只是 addDepart.setText() 不起作用。

我删除 proguard 规则后的活动

在我删除 proguard 规则之前的活动

Apparently using this显然使用这个

-assumenosideeffects class android.util.Log {
  *;
}

did break my code because确实破坏了我的代码,因为

this rule says that anything public in android.util.Log and its superclasses has no side-effects.此规则表示 android.util.Log 及其超类中的任何公共内容都没有副作用。 That include the synchronization methods defined on Object class.这包括在 Object 类上定义的同步方法。 Because the single one super class of android.util.Log is java.lang.Object .因为 android.util.Log 的一个超类是 java.lang.Object 。 And Object#notify is very much with side effects. Object#notify 有很多副作用。

So be really careful with assumenosideeffectsand always think about specifying exact signatures because it affects the super classes as well.所以要非常小心假设无副作用,并始终考虑指定确切的签名,因为它也会影响超类。

and use this instead :并改用它:

-assumenosideeffects class android.util.Log {
  v(...);
  d(...);
  i(...);
  w(...);
  e(...);
  println(...);
}

Source 来源

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM