Skip to content

Commit 3d1e0e4

Browse files
proggen-comproggenniek
authored
allow reinit and update packages (#47)
* allow reinit update package versions * fix ios build * update version Co-authored-by: proggen <[email protected]> Co-authored-by: niek <[email protected]>
1 parent a48410f commit 3d1e0e4

File tree

18 files changed

+2984
-2973
lines changed

18 files changed

+2984
-2973
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# Changelog
22

3+
## 1.1.1
4+
5+
* [CHANGED] Allow re-init of the Pusher singleton.
6+
* [CHANGED] Update dependencies
7+
38
## 1.1.0
49

5-
* [CHANGED] Add support for the new subscription_count event
10+
* [CHANGED] Add support for the new subscription_count event
611
* [CHANGED] Using latest pusher-websocket-java and pusher-websocket-swift
712

813
## 1.0.2
914

10-
* [CHANGED] Use latest pusher websocket java sdk.
11-
* [ADDED] Example to use a custom authorizer.
15+
* [CHANGED] Use latest pusher websocket java sdk.
16+
* [ADDED] Example to use a custom authorizer.
1217

1318
## 1.0.1
1419

android/gradle.properties

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
## For more details on how to configure your build environment visit
2-
# http://www.gradle.org/docs/current/userguide/build_environment.html
3-
#
4-
# Specifies the JVM arguments used for the daemon process.
5-
# The setting is particularly useful for tweaking memory settings.
6-
# Default value: -Xmx1024m -XX:MaxPermSize=256m
7-
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
8-
#
9-
# When configured, Gradle will run in incubating parallel mode.
10-
# This option should only be used with decoupled projects. More details, visit
11-
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
12-
# org.gradle.parallel=true
13-
#Fri Aug 19 11:19:42 CEST 2022
14-
PusherWebsocketReactNative_kotlinVersion=1.7.10
15-
PusherWebsocketReactNative_targetSdkVersion=33
16-
PusherWebsocketReactNative_compileSdkVersion=33
17-
android.useAndroidX=true
18-
android.enableJetifier=true
1+
## For more details on how to configure your build environment visit
2+
# http://www.gradle.org/docs/current/userguide/build_environment.html
3+
#
4+
# Specifies the JVM arguments used for the daemon process.
5+
# The setting is particularly useful for tweaking memory settings.
6+
# Default value: -Xmx1024m -XX:MaxPermSize=256m
7+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
8+
#
9+
# When configured, Gradle will run in incubating parallel mode.
10+
# This option should only be used with decoupled projects. More details, visit
11+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
12+
# org.gradle.parallel=true
13+
#Fri Aug 19 11:19:42 CEST 2022
14+
PusherWebsocketReactNative_kotlinVersion=1.7.21
15+
PusherWebsocketReactNative_targetSdkVersion=33
16+
PusherWebsocketReactNative_compileSdkVersion=33
17+
android.useAndroidX=true
18+
android.enableJetifier=true

android/src/main/java/com/pusherwebsocketreactnative/PusherWebsocketReactNativeModule.kt

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,30 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
5959
promise: Promise
6060
) {
6161
try {
62-
if (pusher == null) {
63-
val options = PusherOptions()
64-
if (arguments.hasKey("cluster")) options.setCluster(arguments.getString("cluster"))
65-
if (arguments.hasKey("useTLS")) options.isUseTLS =
66-
arguments.getBoolean("useTLS")
67-
if (arguments.hasKey("activityTimeout")) options.activityTimeout =
68-
arguments.getInt("activityTimeout").toLong()
69-
if (arguments.hasKey("pongTimeout")) options.pongTimeout =
70-
arguments.getInt("pongTimeout").toLong()
71-
if (arguments.hasKey("maxReconnectionAttempts")) options.maxReconnectionAttempts =
72-
arguments.getInt("maxReconnectionAttempts")
73-
if (arguments.hasKey("maxReconnectGapInSeconds")) options.maxReconnectGapInSeconds =
74-
arguments.getInt("maxReconnectGapInSeconds")
75-
if (arguments.hasKey("authEndpoint")) options.channelAuthorizer =
76-
HttpChannelAuthorizer(arguments.getString("authEndpoint"))
77-
if (arguments.hasKey("authorizer") && arguments.getBoolean("authorizer")) options.channelAuthorizer =
78-
this
79-
if (arguments.hasKey("proxy")) {
80-
val (host, port) = arguments.getString("proxy")!!.split(':')
81-
options.proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress(host, port.toInt()))
82-
}
83-
pusher = Pusher(arguments.getString("apiKey"), options)
84-
} else {
85-
throw Exception("Pusher Channels already initialized.")
62+
if (pusher != null) {
63+
pusher!!.disconnect()
8664
}
65+
val options = PusherOptions()
66+
if (arguments.hasKey("cluster")) options.setCluster(arguments.getString("cluster"))
67+
if (arguments.hasKey("useTLS")) options.isUseTLS =
68+
arguments.getBoolean("useTLS")
69+
if (arguments.hasKey("activityTimeout")) options.activityTimeout =
70+
arguments.getInt("activityTimeout").toLong()
71+
if (arguments.hasKey("pongTimeout")) options.pongTimeout =
72+
arguments.getInt("pongTimeout").toLong()
73+
if (arguments.hasKey("maxReconnectionAttempts")) options.maxReconnectionAttempts =
74+
arguments.getInt("maxReconnectionAttempts")
75+
if (arguments.hasKey("maxReconnectGapInSeconds")) options.maxReconnectGapInSeconds =
76+
arguments.getInt("maxReconnectGapInSeconds")
77+
if (arguments.hasKey("authEndpoint")) options.channelAuthorizer =
78+
HttpChannelAuthorizer(arguments.getString("authEndpoint"))
79+
if (arguments.hasKey("authorizer") && arguments.getBoolean("authorizer")) options.channelAuthorizer =
80+
this
81+
if (arguments.hasKey("proxy")) {
82+
val (host, port) = arguments.getString("proxy")!!.split(':')
83+
options.proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress(host, port.toInt()))
84+
}
85+
pusher = Pusher(arguments.getString("apiKey"), options)
8786
Log.i(TAG, "Start $pusher")
8887
promise.resolve(null)
8988
} catch (e: Exception) {

example/android/app/build.gradle

Lines changed: 118 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: "com.android.application"
22

33
import com.android.build.OutputFile
4+
import org.apache.tools.ant.taskdefs.condition.Os
45

56
/**
67
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
@@ -15,7 +16,9 @@ import com.android.build.OutputFile
1516
* // the name of the generated asset file containing your JS bundle
1617
* bundleAssetName: "index.android.bundle",
1718
*
18-
* // the entry file for bundle generation
19+
* // the entry file for bundle generation. If none specified and
20+
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
21+
* // default. Can be overridden with ENTRY_FILE environment variable.
1922
* entryFile: "index.android.js",
2023
*
2124
* // https://reactnative.dev/docs/performance#enable-the-ram-format
@@ -37,7 +40,7 @@ import com.android.build.OutputFile
3740
* // bundleInBeta: true,
3841
*
3942
* // whether to disable dev mode in custom build variants (by default only disabled in release)
40-
* // for PusherWebsocketReactNativeExample: to disable dev mode in the staging build type (if configured)
43+
* // for example: to disable dev mode in the staging build type (if configured)
4144
* devDisabledInStaging: true,
4245
* // The configuration property can be in the following formats
4346
* // 'devDisabledIn${productFlavor}${buildType}'
@@ -64,7 +67,7 @@ import com.android.build.OutputFile
6467
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
6568
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
6669
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
67-
* // for PusherWebsocketReactNativeExample, you might want to remove it from here.
70+
* // for example, you might want to remove it from here.
6871
* inputExcludes: ["android/**", "ios/**"],
6972
*
7073
* // override which node gets called and with what additional arguments
@@ -76,8 +79,7 @@ import com.android.build.OutputFile
7679
*/
7780

7881
project.ext.react = [
79-
enableHermes: false, // clean and rebuild if changing
80-
entryFile: "index.tsx",
82+
enableHermes: true, // clean and rebuild if changing
8183
]
8284

8385
apply from: "../../node_modules/react-native/react.gradle"
@@ -100,7 +102,7 @@ def enableProguardInReleaseBuilds = false
100102
/**
101103
* The preferred build flavor of JavaScriptCore.
102104
*
103-
* For PusherWebsocketReactNativeExample, to use the international variant, you can use:
105+
* For example, to use the international variant, you can use:
104106
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
105107
*
106108
* The international variant includes ICU i18n library and necessary data
@@ -113,35 +115,102 @@ def jscFlavor = 'org.webkit:android-jsc:+'
113115
/**
114116
* Whether to enable the Hermes VM.
115117
*
116-
* This should be set on project.ext.react and mirrored here. If it is not set
118+
* This should be set on project.ext.react and that value will be read here. If it is not set
117119
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
118120
* and the benefits of using Hermes will therefore be sharply reduced.
119121
*/
120122
def enableHermes = project.ext.react.get("enableHermes", false);
121123

124+
/**
125+
* Architectures to build native code for.
126+
*/
127+
def reactNativeArchitectures() {
128+
def value = project.getProperties().get("reactNativeArchitectures")
129+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
130+
}
131+
122132
android {
123-
compileSdkVersion rootProject.ext.compileSdkVersion
133+
ndkVersion rootProject.ext.ndkVersion
124134

125-
compileOptions {
126-
sourceCompatibility JavaVersion.VERSION_1_8
127-
targetCompatibility JavaVersion.VERSION_1_8
128-
}
135+
compileSdkVersion rootProject.ext.compileSdkVersion
129136

130137
defaultConfig {
131138
applicationId "com.example.pusherwebsocketreactnative"
132139
minSdkVersion rootProject.ext.minSdkVersion
133140
targetSdkVersion rootProject.ext.targetSdkVersion
134141
versionCode 1
135142
versionName "1.0"
143+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
144+
145+
if (isNewArchitectureEnabled()) {
146+
// We configure the CMake build only if you decide to opt-in for the New Architecture.
147+
externalNativeBuild {
148+
cmake {
149+
arguments "-DPROJECT_BUILD_DIR=$buildDir",
150+
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
151+
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
152+
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
153+
"-DANDROID_STL=c++_shared"
154+
}
155+
}
156+
if (!enableSeparateBuildPerCPUArchitecture) {
157+
ndk {
158+
abiFilters (*reactNativeArchitectures())
159+
}
160+
}
161+
}
136162
}
163+
164+
if (isNewArchitectureEnabled()) {
165+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
166+
externalNativeBuild {
167+
cmake {
168+
path "$projectDir/src/main/jni/CMakeLists.txt"
169+
}
170+
}
171+
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
172+
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
173+
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
174+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
175+
into("$buildDir/react-ndk/exported")
176+
}
177+
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
178+
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
179+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
180+
into("$buildDir/react-ndk/exported")
181+
}
182+
afterEvaluate {
183+
// If you wish to add a custom TurboModule or component locally,
184+
// you should uncomment this line.
185+
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
186+
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
187+
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
188+
189+
// Due to a bug inside AGP, we have to explicitly set a dependency
190+
// between configureCMakeDebug* tasks and the preBuild tasks.
191+
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
192+
configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
193+
configureCMakeDebug.dependsOn(preDebugBuild)
194+
reactNativeArchitectures().each { architecture ->
195+
tasks.findByName("configureCMakeDebug[${architecture}]")?.configure {
196+
dependsOn("preDebugBuild")
197+
}
198+
tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure {
199+
dependsOn("preReleaseBuild")
200+
}
201+
}
202+
}
203+
}
204+
137205
splits {
138206
abi {
139207
reset()
140208
enable enableSeparateBuildPerCPUArchitecture
141209
universalApk false // If true, also generate a universal APK
142-
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
210+
include (*reactNativeArchitectures())
143211
}
144212
}
213+
namespace 'com.example.pusherwebsocketreactnative'
145214
signingConfigs {
146215
debug {
147216
storeFile file('debug.keystore')
@@ -150,7 +219,6 @@ android {
150219
keyPassword 'android'
151220
}
152221
}
153-
namespace 'com.example.pusherwebsocketreactnative'
154222
buildTypes {
155223
debug {
156224
signingConfig signingConfigs.debug
@@ -163,16 +231,18 @@ android {
163231
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
164232
}
165233
}
234+
166235
// applicationVariants are e.g. debug, release
167236
applicationVariants.all { variant ->
168237
variant.outputs.each { output ->
169238
// For each separate APK per architecture, set a unique version code as described here:
170239
// https://developer.android.com/studio/build/configure-apk-splits.html
240+
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
171241
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
172242
def abi = output.getFilter(OutputFile.ABI)
173243
if (abi != null) { // null for the universal-debug, universal-release variants
174244
output.versionCodeOverride =
175-
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
245+
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
176246
}
177247

178248
}
@@ -181,33 +251,52 @@ android {
181251

182252
dependencies {
183253
implementation fileTree(dir: "libs", include: ["*.jar"])
254+
184255
//noinspection GradleDynamicVersion
185256
implementation "com.facebook.react:react-native:+" // From node_modules
186257

187-
188258
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
259+
189260
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
190-
exclude group:'com.facebook.fbjni'
261+
exclude group:'com.facebook.fbjni'
191262
}
263+
192264
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
193265
exclude group:'com.facebook.flipper'
194266
exclude group:'com.squareup.okhttp3', module:'okhttp'
195267
}
268+
196269
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
197270
exclude group:'com.facebook.flipper'
198271
}
199272

200273
if (enableHermes) {
201-
def hermesPath = "../../node_modules/hermes-engine/android/";
202-
debugImplementation files(hermesPath + "hermes-debug.aar")
203-
releaseImplementation files(hermesPath + "hermes-release.aar")
274+
//noinspection GradleDynamicVersion
275+
implementation("com.facebook.react:hermes-engine:+") { // From node_modules
276+
exclude group:'com.facebook.fbjni'
277+
}
204278
} else {
205279
implementation jscFlavor
206280
}
207-
208281
implementation project(':pusher-websocket-react-native')
209282
}
210283

284+
if (isNewArchitectureEnabled()) {
285+
// If new architecture is enabled, we let you build RN from source
286+
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
287+
// This will be applied to all the imported transtitive dependency.
288+
configurations.all {
289+
resolutionStrategy.dependencySubstitution {
290+
substitute(module("com.facebook.react:react-native"))
291+
.using(project(":ReactAndroid"))
292+
.because("On New Architecture we're building React Native from source")
293+
substitute(module("com.facebook.react:hermes-engine"))
294+
.using(project(":ReactAndroid:hermes-engine"))
295+
.because("On New Architecture we're building Hermes from source")
296+
}
297+
}
298+
}
299+
211300
// Run this once to be able to run the application with BUCK
212301
// puts all compile dependencies into folder libs for BUCK to use
213302
task copyDownloadableDepsToLibs(type: Copy) {
@@ -216,3 +305,11 @@ task copyDownloadableDepsToLibs(type: Copy) {
216305
}
217306

218307
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
308+
309+
def isNewArchitectureEnabled() {
310+
// To opt-in for the New Architecture, you can either:
311+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
312+
// - Invoke gradle with `-newArchEnabled=true`
313+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
314+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
315+
}

0 commit comments

Comments
 (0)