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-
401configurations {
412 compileClasspath
423}
434
445buildscript {
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'
7829if (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 {
14394repositories {
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
152103dependencies {
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+ }
0 commit comments