Reputation: 3173
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?.
Upvotes: 0
Views: 748
Reputation: 59611
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.
Upvotes: 3
Reputation: 9461
How about using only location dependency?
com.google.android.gms:play-services-location:8.3.0
Upvotes: 1