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
-
40
1
configurations {
41
2
compileClasspath
42
3
}
43
4
44
5
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
51
9
52
10
repositories {
53
11
mavenCentral()
54
12
google()
55
13
}
56
14
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 "
58
17
}
59
18
}
60
19
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
- }
70
20
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
73
26
74
- // Use next storage implementation
75
- def useNextStorage = getFlagOrDefault(" AsyncStorage_useNextStorage" , false )
27
+ logger. info(" [AsyncStorage] Config used: {}" , ext.AsyncStorageConfig )
76
28
77
- apply plugin : ' com.android.library'
78
29
if (useNextStorage) {
30
+ apply plugin : ' com.google.devtools.ksp'
79
31
apply plugin : ' kotlin-android'
80
- apply plugin : ' kotlin-kapt'
81
32
apply from : ' ./testresults.gradle'
82
33
}
83
34
84
- if (isNewArchitectureEnabled() ) {
35
+ if (isNewArchitectureEnabled) {
85
36
apply plugin : " com.facebook.react"
86
37
}
87
38
@@ -94,7 +45,7 @@ android {
94
45
}
95
46
}
96
47
97
- compileSdkVersion safeExtGet( ' compileSdkVersion' , 32 )
48
+ compileSdkVersion project.ext.AsyncStorageConfig . compileSdkVersion
98
49
// Used to override the NDK path/version by allowing users to customize
99
50
// the NDK path/version from their root project (e.g. for M1 support)
100
51
if (rootProject. hasProperty(" ndkPath" )) {
@@ -106,10 +57,10 @@ android {
106
57
107
58
108
59
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} "
113
64
buildConfigField " boolean" , " AsyncStorage_useNextStorage" , " ${ useNextStorage} "
114
65
}
115
66
lintOptions {
@@ -133,7 +84,7 @@ android {
133
84
srcDirs + = ' src/javaPackage/java'
134
85
}
135
86
136
- if (! isNewArchitectureEnabled() ) {
87
+ if (! isNewArchitectureEnabled) {
137
88
srcDirs + = ' src/oldarch/java'
138
89
}
139
90
}
@@ -143,43 +94,30 @@ android {
143
94
repositories {
144
95
maven {
145
96
// 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"
147
98
}
148
99
google()
149
100
mavenCentral()
150
101
}
151
102
152
103
dependencies {
153
-
154
104
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
167
106
168
107
implementation " androidx.room:room-runtime:$room_version "
169
108
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
182
120
}
183
121
184
122
implementation ' com.facebook.react:react-native:+' // from node_modules
185
- }
123
+ }
0 commit comments