Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Improve resulting APK size by using @Keep annotation #12490

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: "com.jaredsburrows.license"

dependencies {
lintChecks project(":MapboxGLAndroidSDKLint")
api (dependenciesList.mapboxAndroidTelemetry) {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
Expand Down
7 changes: 4 additions & 3 deletions platform/android/MapboxGLAndroidSDK/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
-keepattributes Signature, *Annotation*, EnclosingMethod

# config for the SDK
-keep class com.mapbox.mapboxsdk.** { *; }
-keep interface com.mapbox.mapboxsdk.** { *; }
-keep class com.google.gson.JsonArray { *; }
-keep class com.google.gson.JsonElement { *; }
-keep class com.google.gson.JsonObject { *; }
-keep class com.google.gson.JsonPrimitive { *; }

# config for okhttp 3.8.0, https://github.com/square/okhttp/pull/3354
-dontwarn okio.**
Expand All @@ -23,7 +25,6 @@

# config for mapbox-sdk-geojson:3.0.1
-keep class com.mapbox.geojson.** { *; }
-keep class com.google.gson.** { *; }
-dontnote com.google.gson.internal.UnsafeAllocator

# config for mapbox-android-gestures:0.0.1-20180228.152340-13
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mapbox.mapboxsdk.annotations;

import android.support.annotation.Keep;

import com.mapbox.mapboxsdk.geometry.LatLng;

import java.util.ArrayList;
Expand All @@ -10,7 +12,9 @@
*/
public abstract class BasePointCollection extends Annotation {

@Keep
private List<LatLng> points;
@Keep
private float alpha = 1.0f;

protected BasePointCollection() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.mapboxsdk.annotations;

import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
Expand Down Expand Up @@ -27,10 +28,12 @@
*/
public class Marker extends Annotation {

@Keep
private LatLng position;
private String snippet;
private Icon icon;
//Redundantly stored for JNI access
@Keep
private String iconId;
private String title;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.annotations;

import android.graphics.Color;
import android.support.annotation.Keep;

import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
Expand All @@ -13,8 +14,11 @@
*/
public final class Polygon extends BasePointCollection {

@Keep
private int fillColor = Color.BLACK; // default fillColor is black
@Keep
private int strokeColor = Color.BLACK; // default strokeColor is black
@Keep
private List<List<LatLng>> holes;

Polygon() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.annotations;

import android.graphics.Color;
import android.support.annotation.Keep;

import com.mapbox.mapboxsdk.maps.MapboxMap;

Expand All @@ -9,7 +10,9 @@
*/
public final class Polyline extends BasePointCollection {

@Keep
private int color = Color.BLACK; // default color is black
@Keep
private float width = 10; // As specified by Google API Docs (in pixels)

Polyline() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.FloatRange;
import android.support.annotation.Keep;

import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
Expand Down Expand Up @@ -35,23 +36,27 @@ public CameraPosition[] newArray(int size) {
/**
* Direction that the camera is pointing in, in degrees clockwise from north.
*/
@Keep
public final double bearing;

/**
* The location that the camera is pointing at.
*/
@Keep
public final LatLng target;

/**
* The angle, in degrees, of the camera angle from the nadir (directly facing the Earth).
* See tilt(float) for details of restrictions on the range of values.
*/
@Keep
public final double tilt;

/**
* Zoom level near the center of the screen. See zoom(float) for the definition of the camera's
* zoom level.
*/
@Keep
public final double zoom;

/**
Expand All @@ -67,6 +72,7 @@ public CameraPosition[] newArray(int size) {
* @throws NullPointerException if target is null
* @throws IllegalArgumentException if tilt is outside the range of 0 to 90 degrees inclusive.
*/
@Keep
CameraPosition(LatLng target, double zoom, double tilt, double bearing) {
this.target = target;
this.bearing = bearing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.FloatRange;
import android.support.annotation.Keep;

import com.mapbox.mapboxsdk.constants.GeometryConstants;

Expand Down Expand Up @@ -35,7 +36,9 @@ public LatLng[] newArray(int size) {
}
};

@Keep
private double latitude;
@Keep
private double longitude;
private double altitude = 0.0;

Expand All @@ -53,6 +56,7 @@ public LatLng() {
* @param latitude Latitude in degrees
* @param longitude Longitude in degrees
*/
@Keep
public LatLng(double latitude, double longitude) {
setLatitude(latitude);
setLongitude(longitude);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.FloatRange;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.constants.GeometryConstants;
Expand All @@ -19,9 +20,13 @@
*/
public class LatLngBounds implements Parcelable {

@Keep
private final double latitudeNorth;
@Keep
private final double latitudeSouth;
@Keep
private final double longitudeEast;
@Keep
private final double longitudeWest;

/**
Expand All @@ -37,6 +42,7 @@ public class LatLngBounds implements Parcelable {
* @param southLatitude Southern Latitude
* @param westLongitude Western Longitude
*/
@Keep
LatLngBounds(final double northLatitude, final double eastLongitude, final double southLatitude,
final double westLongitude) {
this.latitudeNorth = northLatitude;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Keep;

/**
* A geographical area representing a non-aligned quadrilateral
Expand All @@ -11,15 +12,20 @@
*/
public class LatLngQuad implements Parcelable {

@Keep
private final LatLng topLeft;
@Keep
private final LatLng topRight;
@Keep
private final LatLng bottomRight;
@Keep
private final LatLng bottomLeft;

/**
* Construct a new LatLngQuad based on its corners,
* in order top left, top right, bottom left, bottom right
*/
@Keep
public LatLngQuad(final LatLng topLeft, final LatLng topRight, final LatLng bottomRight, final LatLng bottomLeft) {
this.topLeft = topLeft;
this.topRight = topRight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Keep;

/**
* ProjectedMeters is a projection of longitude, latitude points in Mercator meters.
Expand Down Expand Up @@ -35,6 +36,7 @@ public ProjectedMeters[] newArray(int size) {
* @param northing the northing in meters
* @param easting the easting in meters
*/
@Keep
public ProjectedMeters(double northing, double easting) {
this.northing = northing;
this.easting = easting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
Expand Down Expand Up @@ -48,9 +49,11 @@ class HTTPRequest implements Callback {
// Reentrancy is not needed, but "Lock" is an abstract class.
private ReentrantLock lock = new ReentrantLock();
private String userAgentString;
@Keep
private long nativePtr = 0;
private Call call;

@Keep
private HTTPRequest(long nativePtr, String resourceUrl, String etag, String modified) {
this.nativePtr = nativePtr;

Expand All @@ -62,6 +65,7 @@ private HTTPRequest(long nativePtr, String resourceUrl, String etag, String modi
executeRequest(resourceUrl, etag, modified);
}

@Keep
public void cancel() {
// call can be null if the constructor gets aborted (e.g, under a NoRouteToHostException).
if (call != null) {
Expand Down Expand Up @@ -266,8 +270,10 @@ private String getApplicationIdentifier() {
}
}

@Keep
private native void nativeOnFailure(int type, String message);

@Keep
private native void nativeOnResponse(int code, String etag, String modified, String cacheControl, String expires,
String retryAfter, String xRateLimitReset, byte[] body);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.mapbox.mapboxsdk.maps;

import android.support.annotation.Keep;

@Keep
class Image {
private final byte[] buffer;
private final float pixelRatio;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import com.mapbox.android.gestures.AndroidGesturesManager;
import com.mapbox.android.gestures.MoveGestureDetector;
import com.mapbox.android.gestures.RotateGestureDetector;
Expand Down Expand Up @@ -44,11 +45,12 @@
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.light.Light;
import com.mapbox.mapboxsdk.style.sources.Source;
import timber.log.Timber;

import java.util.HashMap;
import java.util.List;

import timber.log.Timber;

/**
* The general class to interact with in the Android Mapbox SDK. It exposes the entry point for all
* methods related to the MapView. You cannot instantiate {@link MapboxMap} object directly, rather,
Expand Down Expand Up @@ -827,7 +829,7 @@ public final void animateCamera(@NonNull CameraUpdate update, int durationMs) {
public final void animateCamera(@NonNull final CameraUpdate update, final int durationMs,
@Nullable final MapboxMap.CancelableCallback callback) {
if (durationMs <= 0) {
throw new IllegalArgumentException("Null duration passed into animageCamera");
throw new IllegalArgumentException("Null duration passed into animateCamera");
}

transform.animateCamera(MapboxMap.this, update, durationMs, callback);
Expand Down Expand Up @@ -1138,7 +1140,9 @@ public Marker addMarker(@NonNull BaseMarkerOptions markerOptions) {
* @param markerOptions A marker options object that defines how to render the marker
* @return The {@code Marker} that was added to the map
* @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
* SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
* SDK views to be used as a symbol see https://github
* .com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android
* /MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
@NonNull
@Deprecated
Expand All @@ -1157,7 +1161,9 @@ public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions) {
* @param onMarkerViewAddedListener Callback invoked when the View has been added to the map
* @return The {@code Marker} that was added to the map
* @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
* SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
* SDK views to be used as a symbol see https://github
* .com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android
* /MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
@Deprecated
@NonNull
Expand All @@ -1176,7 +1182,9 @@ public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions,
* @param markerViewOptions A list of markerView options objects that defines how to render the markers
* @return A list of the {@code MarkerView}s that were added to the map
* @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
* SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
* SDK views to be used as a symbol see https://github
* .com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android
* /MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
@NonNull
@Deprecated
Expand All @@ -1191,7 +1199,9 @@ public List<MarkerView> addMarkerViews(@NonNull List<? extends
* @param rect the rectangular area on the map to query for markerViews
* @return A list of the markerViews that were found in the rectangle
* @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
* SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
* SDK views to be used as a symbol see https://github
* .com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android
* /MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
@NonNull
@Deprecated
Expand Down Expand Up @@ -2625,7 +2635,9 @@ public interface InfoWindowAdapter {
*
* @param <U> the instance type of MarkerView
* @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
* SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
* SDK views to be used as a symbol see https://github
* .com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android
* /MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
@Deprecated
public abstract static class MarkerViewAdapter<U extends MarkerView> {
Expand Down
Loading