androidloggingproguardgoogle-geocoder

Disabling Logs in Android using Proguard


i added proguard rule -assumenosideeffects class android.util.Log {public *;} so my release version have no logs. 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. when i remove the proguard rule everything works just fine . Dont even know how it s related. i tried it in 4 different devices.

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.

Activity after i removed the proguard rule

Activity before i removed the proguard rule


Solution

  • 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. That include the synchronization methods defined on Object class. Because the single one super class of android.util.Log is java.lang.Object . And Object#notify is very much with side effects.

    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