Skip to content

Commit 5f2b809

Browse files
authored
Merge pull request #3 from Leanplum/feature/fix-lp-4216
feat(proguard): adds consumer proguard to be bundled with aar
2 parents 1164877 + ccbcccf commit 5f2b809

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

AndroidSDK/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ android {
3636
publishNonDefault true
3737

3838
defaultConfig {
39-
consumerProguardFiles 'proguard-rules.pro'
39+
consumerProguardFiles 'consumer-proguard-rules.pro'
4040
}
4141

4242
buildTypes {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Keep default Leanplum classes.
2+
-keepclassmembers class * {
3+
@com.leanplum.annotations.* <fields>;
4+
}
5+
6+
-keep class com.leanplum.** { *; }
7+
-dontwarn com.leanplum.**
8+
9+
# Keep bytebuddy classes.
10+
-keep class net.bytebuddy.** { *; }
11+
-dontwarn net.bytebuddy.**
12+
13+
# Keep Support Library classes.
14+
-dontwarn android.support.v7.**
15+
-keep class android.support.v7.** { *; }
16+
-keep interface android.support.v7.** { *; }

AndroidSDK/src/com/leanplum/LeanplumGcmProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ public String getRegistrationId() {
9090
Util.handleException(e);
9191
}
9292
} catch (Throwable t) {
93-
Log.e("Failed to complete registration token refresh.");
94-
Util.handleException(t);
93+
Log.w("There was a problem setting up GCM, please make sure you follow instructions " +
94+
"on how to set it up. Please verify that you are using correct version of " +
95+
"Google Play Services and Android Support Library v4.");
9596
}
9697
return registrationId;
9798
}

AndroidSDK/src/com/leanplum/internal/ActionManager.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.content.Intent;
99
import android.content.SharedPreferences;
1010

11+
import com.google.android.gms.location.LocationServices;
1112
import com.leanplum.ActionContext;
1213
import com.leanplum.ActionContext.ContextualValues;
1314
import com.leanplum.Leanplum;
@@ -17,7 +18,6 @@
1718
import com.leanplum.callbacks.ActionCallback;
1819

1920
import java.io.Serializable;
20-
import java.lang.reflect.Modifier;
2121
import java.util.HashMap;
2222
import java.util.List;
2323
import java.util.Map;
@@ -58,13 +58,7 @@ public static synchronized ActionManager getInstance() {
5858
public static LocationManager getLocationManager() {
5959
if (Util.hasPlayServices()) {
6060
try {
61-
Class<?> googleApiClientClass =
62-
Class.forName("com.google.android.gms.common.api.GoogleApiClient");
63-
if (googleApiClientClass != null
64-
&& Modifier.isAbstract(googleApiClientClass.getModifiers())
65-
&& Modifier.isAbstract(
66-
googleApiClientClass.getMethod("isConnected").getModifiers())
67-
&& Class.forName("com.google.android.gms.location.LocationServices") != null) {
61+
if (LocationServices.API != null) {
6862
// Reflection here prevents linker errors
6963
// in Google Play Services is not used in the client app.
7064
return (LocationManager) Class

AndroidSDK/src/com/leanplum/internal/Util.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.text.TextUtils;
2323
import android.util.TypedValue;
2424

25+
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
2526
import com.leanplum.Leanplum;
2627
import com.leanplum.LeanplumActivityHelper;
2728
import com.leanplum.LeanplumDeviceIdMode;
@@ -181,24 +182,17 @@ private static String getWifiMacAddressHash(Context context) {
181182
*/
182183
private static DeviceIdInfo getAdvertisingId(Context caller) throws Exception {
183184
try {
184-
// Using reflection because the app will either crash or print warnings
185-
// if the app doesn't link to Google Play Services, even if this method is not called.
186-
Object adInfo = Class.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient")
187-
.getMethod("getAdvertisingIdInfo", Context.class).invoke(null, caller);
188-
String id = checkDeviceId(
189-
"advertising id", (String) adInfo.getClass().getMethod("getId").invoke(adInfo));
190-
if (id != null) {
191-
boolean limitTracking = (Boolean) adInfo.getClass()
192-
.getMethod("isLimitAdTrackingEnabled").invoke(adInfo);
193-
Log.v("Using advertising device id: " + id);
194-
return new DeviceIdInfo(id, limitTracking);
195-
}
196-
} catch (Exception e) {
197-
if (e.getClass().getName().equals("GooglePlayServicesNotAvailableException")) {
198-
Log.w("Error getting advertising ID. Google Play services are not available.");
199-
} else {
200-
throw e;
185+
AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(caller);
186+
if (info != null) {
187+
String advertisingId = info.getId();
188+
String deviceId = checkDeviceId("advertising id", advertisingId);
189+
if (deviceId != null) {
190+
boolean limitedTracking = info.isLimitAdTrackingEnabled();
191+
return new DeviceIdInfo(deviceId, limitedTracking);
192+
}
201193
}
194+
} catch (Throwable ignored) {
195+
Log.e("Error getting advertising ID. Google Play Services are not available.");
202196
}
203197
return null;
204198
}

0 commit comments

Comments
 (0)