@@ -36,12 +36,10 @@ def getExtOrDefault(name) {
3636def getExtOrIntegerDefault (name ) {
3737 return rootProject. ext. has(name) ? rootProject. ext. get(name) : (project. properties[" ImageResizer_" + name]). toInteger()
3838}
39- def localShimmerSourceDir = new File (projectDir, " src/main/java/com/streamchatreactnative" )
40- def sharedShimmerSourceDir = new File (projectDir, " ../../shared-native/android/src/main/java/com/streamchatreactnative" )
41- def generatedShimmerSourceDir = new File (project. buildDir, " generated/stream-shimmer/src/main/java/com/streamchatreactnative" )
42- def shimmerSourceFiles = [" StreamShimmerFrameLayout.kt" , " StreamShimmerViewManager.kt" ]
43- def hasAllShimmerFiles = { File dir ->
44- shimmerSourceFiles. every { filename -> new File (dir, filename). exists() }
39+ def localSharedNativeRootDir = new File (projectDir, " src/main/java/com/streamchatreactnative/shared" )
40+ def sharedNativeRootDir = new File (projectDir, " ../../shared-native/android" )
41+ def hasNativeSources = { File dir ->
42+ dir. exists() && ! fileTree(dir). matching { include " **/*.kt" ; include " **/*.java" }. files. isEmpty()
4543}
4644
4745android {
@@ -87,6 +85,7 @@ android {
8785 if (isNewArchitectureEnabled()) {
8886 java. srcDirs + = [
8987 " src/newarch" ,
88+ " src/main/java/com/streamchatreactnative/shared" ,
9089 // This is needed to build Kotlin project with NewArch enabled
9190 " ${ project.buildDir} /generated/source/codegen/java"
9291 ]
@@ -98,34 +97,31 @@ android {
9897}
9998
10099tasks. register(" syncSharedShimmerSources" ) {
101- outputs. dir(generatedShimmerSourceDir )
100+ outputs. dir(localSharedNativeRootDir )
102101 outputs. upToDateWhen { false }
103102 doLast {
104- def sourceDir = null
105- if (hasAllShimmerFiles(sharedShimmerSourceDir )) {
106- sourceDir = sharedShimmerSourceDir
107- } else if (hasAllShimmerFiles(localShimmerSourceDir )) {
108- sourceDir = localShimmerSourceDir
103+ def sourceRootDir = null
104+ if (hasNativeSources(localSharedNativeRootDir )) {
105+ sourceRootDir = localSharedNativeRootDir
106+ } else if (hasNativeSources(sharedNativeRootDir )) {
107+ sourceRootDir = sharedNativeRootDir
109108 }
110109
111- if (sourceDir == null ) {
110+ if (sourceRootDir == null ) {
112111 throw new GradleException (
113- " Missing shimmer native sources. Expected either src/main/java/com/streamchatreactnative/*.kt " +
114- " or ../../shared-native/android/src/main/java/com/streamchatreactnative/*.kt ."
112+ " Missing shared native Android sources. Expected either src/main/java/com/streamchatreactnative/shared/**/*.{kt,java} " +
113+ " or ../../shared-native/android/**/*.{kt,java} ."
115114 )
116115 }
117116
118- generatedShimmerSourceDir. mkdirs()
119- localShimmerSourceDir. mkdirs()
120- shimmerSourceFiles. each { filename ->
121- def srcFile = new File (sourceDir, filename)
122- def generatedDstFile = new File (generatedShimmerSourceDir, filename)
123- generatedDstFile. bytes = srcFile. bytes
124-
125- if (sourceDir != localShimmerSourceDir) {
126- def localDstFile = new File (localShimmerSourceDir, filename)
127- localDstFile. bytes = srcFile. bytes
117+ if (sourceRootDir != localSharedNativeRootDir) {
118+ project. delete(localSharedNativeRootDir)
119+ project. copy {
120+ from(sourceRootDir)
121+ into(localSharedNativeRootDir)
128122 }
123+ } else if (! hasNativeSources(localSharedNativeRootDir)) {
124+ throw new GradleException (" Shared native source directory exists but has no Kotlin/Java files." )
129125 }
130126 }
131127}
0 commit comments