App size getting increased

佐手、 提交于 2020-01-06 20:18:55

问题


Recently i have used Fused Location API for location purpose. Before applying google play service library com.google.android.gms:play-services:8.3.0 the app size was 4.3MB(4,499,239 bytes) but after using this api it increased to 5.8 MB(6,085,932 bytes). Only one class has been added to the project. i.e LocationService.java where i am calling it from service class and here is the code.

LocationService.java

 public class LocationServiceRACE implements
            GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
        private GoogleApiClient mGoogleApiClient;

        private LocationRequest mLocationRequest;

        public LocationServiceRACE(Context serviceContext) {
            mGoogleApiClient = new GoogleApiClient.Builder(serviceContext)
                    .addApi(LocationServices.API)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();
        }

        public GoogleApiClient getmGoogleApiClient() {
             return this.mGoogleApiClient;
        }

        @Override
        public void onConnected(Bundle bundle) {
            if (mGoogleApiClient.isConnected())
            startLocationUpdates();
        }

        @Override
        public void onConnectionSuspended(int i) {

        }

        @Override
        public void onLocationChanged(Location location) {

        }

        @Override
        public void onConnectionFailed(ConnectionResult connectionResult) {

        }

        protected void startLocationUpdates() {
            mLocationRequest = LocationRequest.create();
            mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
            mLocationRequest.setInterval(60000); // Update location every 60 second
            mLocationRequest.setSmallestDisplacement(100);
            LocationServices.FusedLocationApi.requestLocationUpdates(
                    mGoogleApiClient, mLocationRequest, this);
        }
    }

I am not using no other api's other than Fused Location and nothing is added/changed in ProGuard after adding google play services. How can i reduce the app size where i just need fused location api?.


回答1:


Take a look here at setting up Google Play Services:

https://developers.google.com/android/guides/setup

It is broken down into modules so you can import only the API's you need. In your case you would need only

com.google.android.gms:play-services-location:8.3.0

instead of

com.google.android.gms:play-services:8.3.0

which is the entire package.

Additionally, if you are running Proguard at the end of your packaging (minifyEnabled true inside your build.gradle), it will strip out classes which your codebase isn't using, further minimizing the size of your final APK.




回答2:


How about using only location dependency?

com.google.android.gms:play-services-location:8.3.0



来源:https://stackoverflow.com/questions/33909451/app-size-getting-increased

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!