应用程序大小增加

时间:2015-11-25 05:59:59

标签: android google-play-services application-size

最近我使用Fused Location API进行定位。 在应用Google Play服务库com.google.android.gms:play-services:8.3.0之前,应用大小为4.3MB(4,499,239字节),但在使用此API后,它增加到5.8 MB(6,085,932字节)。只有一个类添加到项目中。即LocationService.java我在服务类中调用它,这是代码。

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);
        }
    }

除了Fused Location之外,我没有使用其他api,并且在添加Google Play服务后,ProGuard中没有添加/更改任何内容。 如何减少我只需要fused location api的应用程序大小。

2 个答案:

答案 0 :(得分:3)

点击此处查看有关设置Google Play服务的信息:

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

它被分解为模块,因此您只能导入所需的API。在您的情况下,您只需要

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

而不是

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

这是整个包裹。

此外,如果您在打包结束时运行Proguard(minifyEnabled true内部build.gradle),它将删除您的代码库未使用的类,从而进一步减小尺寸你的最终APK。

答案 1 :(得分:1)

如何仅使用位置依赖?

com.google.android.gms:播放服务-位置:8.3.0

相关问题