Skip to content

Commit 14489a7

Browse files
author
Krzysztof Borowy
authored
feat(android): Bump versions for Next storage (#1028)
- Bumped default Kotlin version to 1.9.20 - Coroutines bumped to 1.7.3 - Dropped kapt in favor of ksp, which version can be set via gradle property
1 parent 278c3ff commit 14489a7

File tree

6 files changed

+179
-126
lines changed

6 files changed

+179
-126
lines changed
Lines changed: 33 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,38 @@
1-
import java.nio.file.Paths
2-
3-
def resolveModulePath(packageName) {
4-
def basePath = rootDir.toPath().normalize()
5-
6-
// Node's module resolution algorithm searches up to the root directory,
7-
// after which the base path will be null
8-
while (basePath) {
9-
def candidatePath = Paths.get(basePath.toString(), 'node_modules', packageName)
10-
if (candidatePath.toFile().exists()) {
11-
return candidatePath.toString()
12-
}
13-
14-
basePath = basePath.getParent()
15-
}
16-
17-
return null
18-
}
19-
20-
def safeExtGet(prop, fallback) {
21-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
22-
}
23-
24-
def getFlagOrDefault(flagName, defaultValue) {
25-
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] == "true" : defaultValue
26-
}
27-
28-
def getVersionOrDefault(String flagName, String defaultVersion) {
29-
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] : defaultVersion
30-
}
31-
32-
def isNewArchitectureEnabled() {
33-
// To opt-in for the New Architecture, you can either:
34-
// - Set `newArchEnabled` to true inside the `gradle.properties` file
35-
// - Invoke gradle with `-newArchEnabled=true`
36-
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
37-
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
38-
}
39-
401
configurations {
412
compileClasspath
423
}
434

445
buildscript {
45-
// kotlin version is dictated by rootProject extension or property in gradle.properties
46-
ext.asyncStorageKtVersion = rootProject.ext.has('kotlinVersion')
47-
? rootProject.ext['kotlinVersion']
48-
: rootProject.hasProperty('AsyncStorage_kotlinVersion')
49-
? rootProject.properties['AsyncStorage_kotlinVersion']
50-
: '1.8.10'
6+
apply from: "config.gradle"
7+
def kotlinVersion = ext.AsyncStorageConfig.kotlinVersion
8+
def kspVersion = ext.AsyncStorageConfig.kspVersion
519

5210
repositories {
5311
mavenCentral()
5412
google()
5513
}
5614
dependencies {
57-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$asyncStorageKtVersion"
15+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
16+
classpath "com.google.devtools.ksp:symbol-processing-gradle-plugin:$kspVersion"
5817
}
5918
}
6019

61-
// AsyncStorage has default size of 6MB.
62-
// This is a sane limit to protect the user from the app storing too much data in the database.
63-
// This also protects the database from filling up the disk cache and becoming malformed.
64-
// If you really need bigger size, please keep in mind the potential consequences.
65-
long dbSizeInMB = 6L
66-
def newDbSize = rootProject.properties['AsyncStorage_db_size_in_MB']
67-
if (newDbSize != null && newDbSize.isLong()) {
68-
dbSizeInMB = newDbSize.toLong()
69-
}
7020

71-
// Instead of reusing AsyncTask thread pool, AsyncStorage can use its own executor
72-
def useDedicatedExecutor = getFlagOrDefault('AsyncStorage_dedicatedExecutor', false)
21+
apply plugin: 'com.android.library'
22+
apply from: 'config.gradle'
23+
24+
boolean isNewArchitectureEnabled = ext.AsyncStorageConfig.isNewArchitectureEnabled
25+
boolean useNextStorage = ext.AsyncStorageConfig.useNextStorage
7326

74-
// Use next storage implementation
75-
def useNextStorage = getFlagOrDefault("AsyncStorage_useNextStorage", false)
27+
logger.info("[AsyncStorage] Config used: {}", ext.AsyncStorageConfig)
7628

77-
apply plugin: 'com.android.library'
7829
if (useNextStorage) {
30+
apply plugin: 'com.google.devtools.ksp'
7931
apply plugin: 'kotlin-android'
80-
apply plugin: 'kotlin-kapt'
8132
apply from: './testresults.gradle'
8233
}
8334

84-
if (isNewArchitectureEnabled()) {
35+
if (isNewArchitectureEnabled) {
8536
apply plugin: "com.facebook.react"
8637
}
8738

@@ -94,7 +45,7 @@ android {
9445
}
9546
}
9647

97-
compileSdkVersion safeExtGet('compileSdkVersion', 32)
48+
compileSdkVersion project.ext.AsyncStorageConfig.compileSdkVersion
9849
// Used to override the NDK path/version by allowing users to customize
9950
// the NDK path/version from their root project (e.g. for M1 support)
10051
if (rootProject.hasProperty("ndkPath")) {
@@ -106,10 +57,10 @@ android {
10657

10758

10859
defaultConfig {
109-
minSdkVersion safeExtGet('minSdkVersion', 23)
110-
targetSdkVersion safeExtGet('targetSdkVersion', 32)
111-
buildConfigField "Long", "AsyncStorage_db_size", "${dbSizeInMB}L"
112-
buildConfigField "boolean", "AsyncStorage_useDedicatedExecutor", "${useDedicatedExecutor}"
60+
minSdkVersion project.ext.AsyncStorageConfig.minSdkVersion
61+
targetSdkVersion project.ext.AsyncStorageConfig.targetSdkVersion
62+
buildConfigField "Long", "AsyncStorage_db_size", "${project.ext.AsyncStorageConfig.databaseSizeMB}L"
63+
buildConfigField "boolean", "AsyncStorage_useDedicatedExecutor", "${project.ext.AsyncStorageConfig.useDedicatedExecutor}"
11364
buildConfigField "boolean", "AsyncStorage_useNextStorage", "${useNextStorage}"
11465
}
11566
lintOptions {
@@ -133,7 +84,7 @@ android {
13384
srcDirs += 'src/javaPackage/java'
13485
}
13586

136-
if (!isNewArchitectureEnabled()) {
87+
if (!isNewArchitectureEnabled) {
13788
srcDirs += 'src/oldarch/java'
13889
}
13990
}
@@ -143,43 +94,30 @@ android {
14394
repositories {
14495
maven {
14596
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
146-
url "${resolveModulePath("react-native")}/android"
97+
url "${project.ext.resolveModulePath("react-native")}/android"
14798
}
14899
google()
149100
mavenCentral()
150101
}
151102

152103
dependencies {
153-
154104
if (useNextStorage) {
155-
def room_version = getVersionOrDefault('AsyncStorage_next_roomVersion', '2.4.3')
156-
def coroutines_version = "1.6.4"
157-
def coroutinesTest_version = "1.6.4"
158-
// if we don't provide explicit dependency on reflection, kotlin plugin
159-
// would add one automatically, probably a version that is not compatible with
160-
// used kotlin
161-
def kotlinReflect_version = project.ext.asyncStorageKtVersion
162-
def junit_version = "4.13.2"
163-
def robolectric_version = "4.7.3"
164-
def truth_version = "1.1.3"
165-
def androidxtest_version = "1.4.0"
166-
def androidtest_junit_version = "1.1.3"
105+
def room_version = project.ext.AsyncStorageConfig.roomVersion
167106

168107
implementation "androidx.room:room-runtime:$room_version"
169108
implementation "androidx.room:room-ktx:$room_version"
170-
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinReflect_version"
171-
172-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
173-
kapt "androidx.room:room-compiler:$room_version"
174-
175-
testImplementation "junit:junit:$junit_version"
176-
testImplementation "androidx.test:runner:$androidxtest_version"
177-
testImplementation "androidx.test:rules:$androidxtest_version"
178-
testImplementation "androidx.test.ext:junit:$androidtest_junit_version"
179-
testImplementation "org.robolectric:robolectric:$robolectric_version"
180-
testImplementation "com.google.truth:truth:$truth_version"
181-
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesTest_version"
109+
ksp "androidx.room:room-compiler:$room_version"
110+
111+
implementation project.ext.AsyncStorageLibs.coroutines
112+
113+
testImplementation project.ext.AsyncStorageLibs.testCoroutines
114+
testImplementation project.ext.AsyncStorageLibs.testJunit
115+
testImplementation project.ext.AsyncStorageLibs.testExtJunit
116+
testImplementation project.ext.AsyncStorageLibs.testRunner
117+
testImplementation project.ext.AsyncStorageLibs.testRules
118+
testImplementation project.ext.AsyncStorageLibs.testRobolectric
119+
testImplementation project.ext.AsyncStorageLibs.testTruth
182120
}
183121

184122
implementation 'com.facebook.react:react-native:+' // from node_modules
185-
}
123+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import java.nio.file.Paths
2+
3+
def DEFAULT_KOTLIN_VERSION = "1.9.20"
4+
def DEFAULT_ROOM_VERSION = "2.4.3"
5+
6+
project.ext.AsyncStorageConfig = [
7+
kotlinVersion : getKotlinVersion(DEFAULT_KOTLIN_VERSION),
8+
kspVersion : getKspVersion(kotlinVersion),
9+
roomVersion : getPropertyOfDefault('AsyncStorage_next_roomVersion', DEFAULT_ROOM_VERSION),
10+
minSdkVersion : safeExtGet('minSdkVersion', 23),
11+
targetSdkVersion : safeExtGet('targetSdkVersion', 32),
12+
compileSdkVersion : safeExtGet('compileSdkVersion', 32),
13+
useNextStorage : getFlagOrDefault("AsyncStorage_useNextStorage", false),
14+
databaseSizeMB : getDatabaseSize(),
15+
isNewArchitectureEnabled: isNewArchitectureEnabled(),
16+
useDedicatedExecutor : getFlagOrDefault('AsyncStorage_dedicatedExecutor', false),
17+
]
18+
19+
project.ext.AsyncStorageLibs = [
20+
coroutines : "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3",
21+
testCoroutines : "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3",
22+
testJunit : "junit:junit:4.13.2",
23+
testRunner : "androidx.test:runner:1.4.0",
24+
testRules : "androidx.test:rules:1.4.0",
25+
testExtJunit : "androidx.test.ext:junit:1.1.3",
26+
testRobolectric: "org.robolectric:robolectric:4.11.1",
27+
testTruth : "com.google.truth:truth:1.1.3",
28+
]
29+
30+
31+
def getKotlinVersion(String defaultVersion) {
32+
return rootProject.ext.has('kotlinVersion')
33+
? rootProject.ext['kotlinVersion']
34+
: rootProject.hasProperty('AsyncStorage_kotlinVersion')
35+
? rootProject.properties['AsyncStorage_kotlinVersion']
36+
: defaultVersion
37+
}
38+
39+
def isNewArchitectureEnabled() {
40+
// To opt-in for the New Architecture, you can either:
41+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
42+
// - Invoke gradle with `-newArchEnabled=true`
43+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
44+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
45+
}
46+
47+
String getKspVersion(String kotlinVersion) {
48+
49+
String overriddenKspVersion = getPropertyOfDefault("AsyncStorage_next_kspVersion", null)
50+
if (overriddenKspVersion != null) {
51+
return overriddenKspVersion
52+
}
53+
// https://github.com/google/ksp/releases
54+
def kspVersions = [
55+
"1.9.20-1.0.14",
56+
"1.9.10-1.0.13",
57+
"1.9.0-1.0.13",
58+
"1.8.22-1.0.11",
59+
"1.8.21-1.0.11",
60+
"1.8.20-1.0.11",
61+
"1.8.10-1.0.9",
62+
"1.8.0-1.0.9",
63+
"1.7.22-1.0.8",
64+
"1.7.21-1.0.8",
65+
"1.7.20-1.0.8",
66+
"1.7.10-1.0.6",
67+
"1.7.0-1.0.6",
68+
"1.6.21-1.0.6",
69+
"1.6.20-1.0.5",
70+
"1.6.10-1.0.4",
71+
"1.6.0-1.0.2",
72+
"1.5.31-1.0.1",
73+
"1.5.30-1.0.0",
74+
]
75+
76+
return kspVersions.find { it.startsWith(kotlinVersion) } ?: kspVersions.first()
77+
}
78+
79+
// AsyncStorage has default size of 6MB.
80+
// This is a sane limit to protect the user from the app storing too much data in the database.
81+
// This also protects the database from filling up the disk cache and becoming malformed.
82+
// If you really need bigger size, please keep in mind the potential consequences.
83+
long getDatabaseSize() {
84+
long dbSizeInMB = 6L
85+
def newDbSize = getPropertyOfDefault('AsyncStorage_db_size_in_MB', null)
86+
if (newDbSize != null && newDbSize.isLong()) {
87+
dbSizeInMB = newDbSize.toLong()
88+
}
89+
return dbSizeInMB
90+
}
91+
92+
def safeExtGet(prop, fallback) {
93+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
94+
}
95+
96+
def getFlagOrDefault(flagName, defaultValue) {
97+
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] == "true" : defaultValue
98+
}
99+
100+
def getPropertyOfDefault(String flagName, String defaultVersion) {
101+
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] : defaultVersion
102+
}
103+
104+
ext.resolveModulePath = { packageName ->
105+
def basePath = rootDir.toPath().normalize()
106+
107+
// Node's module resolution algorithm searches up to the root directory,
108+
// after which the base path will be null
109+
while (basePath) {
110+
def candidatePath = Paths.get(basePath.toString(), 'node_modules', packageName)
111+
if (candidatePath.toFile().exists()) {
112+
return candidatePath.toString()
113+
}
114+
115+
basePath = basePath.getParent()
116+
}
117+
118+
return null
119+
}

packages/default-storage/example/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ newArchEnabled=true
4242
#ANDROID_NDK_VERSION=21.4.7075529
4343

4444
# Version of Kotlin to build against.
45-
KOTLIN_VERSION=1.8.10
45+
KOTLIN_VERSION=1.9.20
4646

4747
# This is an example of how you can change default DB size (6MB) to 10MB
4848
#AsyncStorage_db_size_in_MB=10

packages/default-storage/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"types": "lib/typescript/index.d.ts",
99
"files": [
1010
"RNCAsyncStorage.podspec",
11-
"android/build.gradle",
12-
"android/src",
13-
"android/testresults.gradle",
11+
"android/",
12+
"!android/.gradle",
13+
"!android/build",
1414
"ios/",
1515
"jest/",
1616
"lib/",
@@ -97,7 +97,7 @@
9797
"react-native-builder-bob": "^0.18.0",
9898
"react-native-codegen": "^0.71.5",
9999
"react-native-macos": "^0.71.0",
100-
"react-native-test-app": "^2.5.8",
100+
"react-native-test-app": "^2.5.33",
101101
"react-native-web": "~0.18.10",
102102
"react-native-windows": "^0.71.0",
103103
"react-test-renderer": "18.2.0",

packages/website/docs/advanced/Next.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ AsyncStorage_useNextStorage=true
4747

4848
**Kotlin version**
4949

50-
Next storage is tested against Kotlin version `1.8.10`.
50+
Next storage is tested against Kotlin version `1.9.20`.
5151
You can specify different version, in one of two ways:
5252

5353
- add `kotlinVersion` extension to the `rootProject`:
5454

5555
```groovy
56-
rootProject.ext.kotlinVersion = '1.8.10'
56+
rootProject.ext.kotlinVersion = '1.9.20'
5757
```
5858

5959
- specify `AsyncStorage_kotlinVersion` in `gradle.properties`:
6060

6161
```groovy
62-
AsyncStorage_kotlinVersion=1.8.10
62+
AsyncStorage_kotlinVersion=1.9.20
6363
```
6464

6565
**Room**
@@ -71,6 +71,14 @@ Currently, tested version is `2.4.3`. You can specify different version, by addi
7171
AsyncStorage_next_roomVersion=2.4.3
7272
```
7373

74+
KSP is enabled for symbol processing for the Room library.
75+
KSP version will be selected based on Kotlin version in your project.
76+
If you want to use different KSP version, you can set a property in `gradle.properties`:
77+
78+
```groovy
79+
AsyncStorage_next_kspVersion=1.9.20-1.0.14
80+
```
81+
7482
### Notable changes
7583

7684
Alongside of a warning regarding `key`/`value`, errors are thrown when:

0 commit comments

Comments
 (0)