Skip to content

Commit bbd5126

Browse files
committed
refactor(android): update SDK versions and dependencies
1 parent d926d3c commit bbd5126

File tree

5 files changed

+23
-49
lines changed

5 files changed

+23
-49
lines changed

android/build.gradle

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ def safeExtGet(prop, fallback) {
77

88
android {
99
namespace "com.onesignal.rnonesignalandroid"
10-
compileSdkVersion safeExtGet('compileSdkVersion', 28)
11-
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
10+
compileSdkVersion safeExtGet('compileSdkVersion', 34)
1211

1312
defaultConfig {
14-
minSdkVersion safeExtGet('minSdkVersion', 16)
13+
minSdkVersion safeExtGet('minSdkVersion', 21)
1514
}
1615
buildTypes {
1716
release {
@@ -20,20 +19,15 @@ android {
2019
}
2120

2221
compileOptions {
23-
sourceCompatibility JavaVersion.VERSION_1_8
24-
targetCompatibility JavaVersion.VERSION_1_8
22+
sourceCompatibility JavaVersion.VERSION_11
23+
targetCompatibility JavaVersion.VERSION_11
2524
}
2625
}
2726

2827
dependencies {
29-
implementation fileTree(include: ['*.jar'], dir: 'libs')
3028
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
31-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
32-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
3329

34-
// api is used instead of implementation so the parent :app project can access any of the OneSignal Java
35-
// classes if needed. Such as com.onesignal.NotificationExtenderService
3630
api 'com.onesignal:OneSignal:5.7.2'
37-
31+
3832
testImplementation 'junit:junit:4.12'
39-
}
33+
}

android/proguard-rules.pro

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,2 @@
1-
# Add project specific ProGuard rules here.
2-
# By default, the flags in this file are appended to flags specified
3-
# in /usr/local/Cellar/android-sdk/24.4.1_1/tools/proguard/proguard-android.txt
4-
# You can edit the include path and order by changing the proguardFiles
5-
# directive in build.gradle.
6-
#
7-
# For more details, see
8-
# http://developer.android.com/guide/developing/tools/proguard.html
9-
10-
# Add any project specific keep options here:
11-
12-
# If your project uses WebView with JS, uncomment the following
13-
# and specify the fully qualified class name to the JavaScript interface
14-
# class:
15-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16-
# public *;
17-
#}
1+
# OneSignal SDK ships its own consumer proguard rules.
2+
# Add project-specific rules here if needed.

android/src/main/java/com/onesignal/rnonesignalandroid/RNOneSignal.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ public class RNOneSignal extends NativeOneSignalSpec
8080
INotificationLifecycleListener {
8181
public static final String NAME = "OneSignal";
8282

83-
private ReactApplicationContext mReactApplicationContext;
84-
8583
private boolean oneSignalInitDone;
8684
private boolean hasSetPermissionObserver = false;
8785
private boolean hasSetPushSubscriptionObserver = false;
@@ -194,8 +192,7 @@ private void removeObservers() {
194192

195193
public RNOneSignal(ReactApplicationContext reactContext) {
196194
super(reactContext);
197-
mReactApplicationContext = reactContext;
198-
mReactApplicationContext.addLifecycleEventListener(this);
195+
reactContext.addLifecycleEventListener(this);
199196
notificationWillDisplayCache = new HashMap<String, INotificationWillDisplayEvent>();
200197
preventDefaultCache = new HashMap<String, INotificationWillDisplayEvent>();
201198

@@ -229,7 +226,6 @@ public void onCatalystInstanceDestroy() {
229226

230227
@Override
231228
public void initialize(String appId) {
232-
Context context = mReactApplicationContext.getCurrentActivity();
233229
OneSignalWrapper.setSdkType("reactnative");
234230
OneSignalWrapper.setSdkVersion("050213");
235231

@@ -238,10 +234,10 @@ public void initialize(String appId) {
238234
return;
239235
}
240236

237+
ReactApplicationContext reactContext = getReactApplicationContext();
238+
Context context = reactContext.getCurrentActivity();
241239
if (context == null) {
242-
// in some cases, especially when react-native-navigation is installed,
243-
// the activity can be null, so we can initialize with the context instead
244-
context = mReactApplicationContext.getApplicationContext();
240+
context = reactContext.getApplicationContext();
245241
}
246242

247243
OneSignal.initWithContext(context, appId);
@@ -362,7 +358,7 @@ public void onWillDisplay(INotificationWillDisplayEvent event) {
362358

363359
INotification notification = event.getNotification();
364360
String notificationId = notification.getNotificationId();
365-
notificationWillDisplayCache.put(notificationId, (INotificationWillDisplayEvent) event);
361+
notificationWillDisplayCache.put(notificationId, event);
366362
event.preventDefault();
367363

368364
try {
@@ -686,19 +682,21 @@ public void removeAliases(ReadableArray aliasLabels) {
686682
@Override
687683
public void getOnesignalId(Promise promise) {
688684
String onesignalId = OneSignal.getUser().getOnesignalId();
689-
if (onesignalId.isEmpty()) {
690-
onesignalId = null;
685+
if (onesignalId == null || onesignalId.isEmpty()) {
686+
promise.resolve(null);
687+
} else {
688+
promise.resolve(onesignalId);
691689
}
692-
promise.resolve(onesignalId);
693690
}
694691

695692
@Override
696693
public void getExternalId(Promise promise) {
697694
String externalId = OneSignal.getUser().getExternalId();
698-
if (externalId.isEmpty()) {
699-
externalId = null;
695+
if (externalId == null || externalId.isEmpty()) {
696+
promise.resolve(null);
697+
} else {
698+
promise.resolve(externalId);
700699
}
701-
promise.resolve(externalId);
702700
}
703701

704702
@Override

android/src/main/java/com/onesignal/rnonesignalandroid/RNUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static HashMap<String, Object> convertInAppMessageClickEventToMap(IInAppM
171171
return hash;
172172
}
173173

174-
public static HashMap<String, Object> convertPushSubscriptionStateToMap(PushSubscriptionState state) {
174+
private static HashMap<String, Object> convertPushSubscriptionStateToMap(PushSubscriptionState state) {
175175
HashMap<String, Object> hash = new HashMap<>();
176176
if (state.getToken() != null && !state.getToken().isEmpty()) {
177177
hash.put("token", state.getToken());
@@ -188,7 +188,7 @@ public static HashMap<String, Object> convertPushSubscriptionStateToMap(PushSubs
188188
return hash;
189189
}
190190

191-
public static HashMap<String, Object> convertUserStateToMap(UserState user) {
191+
private static HashMap<String, Object> convertUserStateToMap(UserState user) {
192192
HashMap<String, Object> hash = new HashMap<>();
193193

194194
if (user.getExternalId() != null && !user.getExternalId().isEmpty()) {

android/src/main/res/values/strings.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)