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.9.20'
51
-
52
- def kspVersion = rootProject. hasProperty(" AsyncStorage_next_kspVersion" )
53
- ? rootProject. properties[" AsyncStorage_next_kspVersion" ]
54
- : ' 1.9.20-1.0.14'
6
+ apply from : " config.gradle"
7
+ def kotlinVersion = ext.AsyncStorageConfig . kotlinVersion
8
+ def kspVersion = ext.AsyncStorageConfig . kspVersion
55
9
56
10
repositories {
57
11
mavenCentral()
58
12
google()
59
13
}
60
14
dependencies {
61
- classpath " org.jetbrains.kotlin:kotlin-gradle-plugin:$a syncStorageKtVersion "
15
+ classpath " org.jetbrains.kotlin:kotlin-gradle-plugin:$k otlinVersion "
62
16
classpath " com.google.devtools.ksp:symbol-processing-gradle-plugin:$kspVersion "
63
17
}
64
18
}
65
19
66
- // AsyncStorage has default size of 6MB.
67
- // This is a sane limit to protect the user from the app storing too much data in the database.
68
- // This also protects the database from filling up the disk cache and becoming malformed.
69
- // If you really need bigger size, please keep in mind the potential consequences.
70
- long dbSizeInMB = 6L
71
- def newDbSize = rootProject. properties[' AsyncStorage_db_size_in_MB' ]
72
- if (newDbSize != null && newDbSize. isLong()) {
73
- dbSizeInMB = newDbSize. toLong()
74
- }
75
20
76
- // Instead of reusing AsyncTask thread pool, AsyncStorage can use its own executor
77
- def useDedicatedExecutor = getFlagOrDefault( ' AsyncStorage_dedicatedExecutor ' , false )
21
+ apply plugin : ' com.android.library '
22
+ apply from : " config.gradle "
78
23
79
- // Use next storage implementation
80
- def useNextStorage = getFlagOrDefault(" AsyncStorage_useNextStorage" , false )
24
+ boolean isNewArchitectureEnabled = ext.AsyncStorageConfig . isNewArchitectureEnabled
25
+ boolean useNextStorage = ext.AsyncStorageConfig . useNextStorage
26
+
27
+ println (" [AsyncStorage] Config: ${ ext.AsyncStorageConfig} " )
81
28
82
- apply plugin : ' com.android.library'
83
29
if (useNextStorage) {
84
30
apply plugin : ' com.google.devtools.ksp'
85
31
apply plugin : ' kotlin-android'
86
32
apply from : ' ./testresults.gradle'
87
33
}
88
34
89
- if (isNewArchitectureEnabled() ) {
35
+ if (isNewArchitectureEnabled) {
90
36
apply plugin : " com.facebook.react"
91
37
}
92
38
@@ -99,7 +45,7 @@ android {
99
45
}
100
46
}
101
47
102
- compileSdkVersion safeExtGet( ' compileSdkVersion' , 32 )
48
+ compileSdkVersion project.ext.AsyncStorageConfig . compileSdkVersion
103
49
// Used to override the NDK path/version by allowing users to customize
104
50
// the NDK path/version from their root project (e.g. for M1 support)
105
51
if (rootProject. hasProperty(" ndkPath" )) {
@@ -111,10 +57,10 @@ android {
111
57
112
58
113
59
defaultConfig {
114
- minSdkVersion safeExtGet( ' minSdkVersion' , 23 )
115
- targetSdkVersion safeExtGet( ' targetSdkVersion' , 32 )
116
- buildConfigField " Long" , " AsyncStorage_db_size" , " ${ dbSizeInMB } L"
117
- 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} "
118
64
buildConfigField " boolean" , " AsyncStorage_useNextStorage" , " ${ useNextStorage} "
119
65
}
120
66
lintOptions {
@@ -138,7 +84,7 @@ android {
138
84
srcDirs + = ' src/javaPackage/java'
139
85
}
140
86
141
- if (! isNewArchitectureEnabled() ) {
87
+ if (! isNewArchitectureEnabled) {
142
88
srcDirs + = ' src/oldarch/java'
143
89
}
144
90
}
@@ -148,16 +94,15 @@ android {
148
94
repositories {
149
95
maven {
150
96
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
151
- url " ${ resolveModulePath("react-native")} /android"
97
+ url " ${ project.ext. resolveModulePath("react-native")} /android"
152
98
}
153
99
google()
154
100
mavenCentral()
155
101
}
156
102
157
103
dependencies {
158
-
159
104
if (useNextStorage) {
160
- def room_version = getVersionOrDefault( ' AsyncStorage_next_roomVersion ' , ' 2.4.3 ' )
105
+ def room_version = project.ext.AsyncStorageConfig . roomVersion
161
106
def coroutines_version = " 1.7.3"
162
107
def junit_version = " 4.13.2"
163
108
def robolectric_version = " 4.7.3"
@@ -181,4 +126,4 @@ dependencies {
181
126
}
182
127
183
128
implementation ' com.facebook.react:react-native:+' // from node_modules
184
- }
129
+ }
0 commit comments