Skip to content

Commit bc47200

Browse files
authored
Merge pull request #223 from OneSignal/fixed_proguard_android_optimize_config
Fixed build errors with proguard-android-optimize.txt
2 parents 7493442 + 2db02a4 commit bc47200

File tree

4 files changed

+41
-24
lines changed

4 files changed

+41
-24
lines changed

OneSignalSDK/app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ android {
2020
// minify does not work with GMS 7.0.0 with the current settings. Use 8.4.0 to test.
2121
minifyEnabled true
2222

23-
// Normally `getDefaultProguardFile('proguard-android.txt')` is included in Andorid projects.
24-
// however testing without for compatibility with projects that may not have this.
23+
// Normally `getDefaultProguardFile('proguard-android.txt')` is included in Android projects.
24+
// however testing without a modified proguard-android-optimize.txt for compatibility.
2525
proguardFiles 'proguard-rules.pro'
2626
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2727
}
@@ -70,7 +70,7 @@ dependencies {
7070
// compile 'com.android.support:support-core-utils:24.2.1'
7171

7272
// For Chrome tabs
73-
compile 'com.android.support:customtabs:24.0.0'
73+
compile 'com.android.support:customtabs:24.0.0'
7474

7575

7676
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'

OneSignalSDK/app/proguard-rules.pro

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,34 @@
2121

2222

2323

24-
# File contents below from "android-sdk\tools\proguard\proguard-android.txt"
24+
####### File contents below from "android-sdk\tools\proguard\proguard-android-optimize.txt"
2525
# This is a configuration file for ProGuard.
2626
# http://proguard.sourceforge.net/index.html#manual/usage.html
2727

28+
# Optimizations: If you don't want to optimize, use the
29+
# proguard-android.txt configuration file instead of this one, which
30+
# turns off the optimization flags. Adding optimization introduces
31+
# certain risks, since for example not all optimizations performed by
32+
# ProGuard works on all versions of Dalvik. The following flags turn
33+
# off various optimizations known to have issues, but the list may not
34+
# be complete or up to date. (The "arithmetic" optimization can be
35+
# used if you are only targeting Android 2.0 or later.) Make sure you
36+
# test thoroughly if you go this route.
37+
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
38+
-optimizationpasses 5
39+
-allowaccessmodification
40+
41+
#### Omitting flag as it is not hard to keep compiblity and have done some in the past
42+
#-dontpreverify
43+
44+
# The remainder of this file is identical to the non-optimized version
45+
# of the Proguard configuration file (except that the other file has
46+
# flags to turn off optimization).
47+
2848
-dontusemixedcaseclassnames
2949
-dontskipnonpubliclibraryclasses
3050
-verbose
3151

32-
# Optimization is turned off by default. Dex does not like code run
33-
# through the ProGuard optimize and preverify steps (and performs some
34-
# of these optimizations on its own).
35-
-dontoptimize
36-
37-
## Normally enabled but testing without as compibility isn't hard to meet
38-
#-dontpreverify
39-
40-
# Note that if you want to enable optimization, you cannot just
41-
# include optimization flags in your own project configuration file;
42-
# instead you will need to point to the
43-
# "proguard-android-optimize.txt" file instead of this one from your
44-
# project.properties file.
45-
4652
-keepattributes *Annotation*
4753
-keep public class com.google.vending.licensing.ILicensingService
4854
-keep public class com.android.vending.licensing.ILicensingService

OneSignalSDK/onesignal/consumer-proguard-rules.pro

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
-dontwarn com.onesignal.**
22

3+
# These 2 methods are called with reflection.
34
-keep class com.google.android.gms.common.api.GoogleApiClient {
45
void connect();
56
void disconnect();
67
}
78

9+
810
-keep public interface android.app.OnActivityPausedListener {*;}
911
-keep class com.onesignal.ActivityLifecycleListenerCompat** {*;}
1012

13+
14+
# Observer backcall methods are called with reflection
1115
-keep class com.onesignal.OSSubscriptionState {
1216
void changed(com.onesignal.OSPermissionState);
1317
}
@@ -44,5 +48,8 @@
4448
-keep class com.onesignal.shortcutbadger.impl.XiaomiHomeBadger { <init>(...); }
4549
-keep class com.onesignal.shortcutbadger.impl.ZukHomeBadger { <init>(...); }
4650

51+
4752
-dontwarn com.amazon.**
53+
54+
# Proguard ends up removing this class even if it is used in AndroidManifest.xml so force keeping it.
4855
-keep public class com.onesignal.ADMMessageHandler {*;}

OneSignalSDK/onesignal/src/main/java/com/onesignal/ADMMessageHandler.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727

2828
package com.onesignal;
2929

30+
import android.content.Context;
3031
import android.content.Intent;
3132
import android.os.Bundle;
3233

3334
import com.amazon.device.messaging.ADMMessageHandlerBase;
3435
import com.amazon.device.messaging.ADMMessageReceiver;
3536

37+
// WARNING: Do not pass 'this' to any methods as it will cause proguard build errors
38+
// when "proguard-android-optimize.txt" is used.
3639
public class ADMMessageHandler extends ADMMessageHandlerBase {
3740

3841
public static class Receiver extends ADMMessageReceiver {
@@ -47,16 +50,17 @@ public ADMMessageHandler() {
4750

4851
@Override
4952
protected void onMessage(Intent intent) {
53+
Context context = getApplicationContext();
5054
Bundle bundle = intent.getExtras();
51-
52-
NotificationBundleProcessor.ProcessedBundleResult processedResult = NotificationBundleProcessor.processBundle(this, bundle);
53-
55+
56+
NotificationBundleProcessor.ProcessedBundleResult processedResult = NotificationBundleProcessor.processBundle(context, bundle);
57+
5458
if (processedResult.processed())
5559
return;
56-
57-
NotificationGenerationJob notifJob = new NotificationGenerationJob(this);
60+
61+
NotificationGenerationJob notifJob = new NotificationGenerationJob(context);
5862
notifJob.jsonPayload = NotificationBundleProcessor.bundleAsJSONObject(bundle);
59-
63+
6064
NotificationBundleProcessor.Process(notifJob);
6165
}
6266

0 commit comments

Comments
 (0)