diff --git a/Example/android/gradle.properties b/Example/android/gradle.properties index 4896485f57..729cdc9f66 100644 --- a/Example/android/gradle.properties +++ b/Example/android/gradle.properties @@ -49,3 +49,5 @@ hermesEnabled=true # This is necessary, because the code checking for multiple instances # detects package versions from other example applications in the repository. disableMultipleInstancesCheck=true + +isScreensExampleApp=true diff --git a/FabricExample/android/gradle.properties b/FabricExample/android/gradle.properties index 99fc223edf..be4b1f207c 100644 --- a/FabricExample/android/gradle.properties +++ b/FabricExample/android/gradle.properties @@ -39,3 +39,5 @@ newArchEnabled=true # Use this property to enable or disable the Hermes JS engine. # If set to false, you will be using JSC instead. hermesEnabled=true + +isScreensExampleApp=true diff --git a/FabricTestExample/android/gradle.properties b/FabricTestExample/android/gradle.properties index 67b6139770..e1104c5ddd 100644 --- a/FabricTestExample/android/gradle.properties +++ b/FabricTestExample/android/gradle.properties @@ -41,3 +41,5 @@ newArchEnabled=true hermesEnabled=true disableMultipleInstancesCheck=true + +isScreensExampleApp=true diff --git a/TVOSExample/android/gradle.properties b/TVOSExample/android/gradle.properties index d21d03f2b4..2b0e2126ce 100644 --- a/TVOSExample/android/gradle.properties +++ b/TVOSExample/android/gradle.properties @@ -26,3 +26,5 @@ android.enableJetifier=true # Version of flipper SDK to use with React Native FLIPPER_VERSION=0.75.1 + +isScreensExampleApp=true diff --git a/TestsExample/android/gradle.properties b/TestsExample/android/gradle.properties index bb048c5716..36f80eca00 100644 --- a/TestsExample/android/gradle.properties +++ b/TestsExample/android/gradle.properties @@ -41,3 +41,5 @@ newArchEnabled=false hermesEnabled=true disableMultipleInstancesCheck=true + +isScreensExampleApp=true diff --git a/android/build.gradle b/android/build.gradle index b751186b1b..89ea486f6d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -192,3 +192,79 @@ dependencies { } } } + +def isScreensExampleApp() { + return project.hasProperty('isScreensExampleApp') && project.property('isScreensExampleApp') == "true" +} + +def getAbsoluteCodegenArtifactsPaperDestination() { + if (!project.hasProperty('codegenArtifactsPaperDestination')) { + throw new Exception('[RNScreens] Please fill codegenArtifactsPaperDestination variable in android/gradle.properties correct path to paper paper destination') + } + + return "${project.rootDir}/../../${project.property('codegenArtifactsPaperDestination')}" +} + +def getAbsoluteCodegenArtifactsSource() { + if (!project.hasProperty('codegenArtifactsSource')) { + throw new Exception('[RNScreens] Please fill codegenArtifactsSource variable in android/gradle.properties correct path to codegenerated artifacts') + } + + return "${project.rootDir}/../../${project.property('codegenArtifactsSource')}" +} + + +tasks.register("copyCodegenArtifacts") { + group 'After build tasks' + description 'Tasks which copy codegen artifacts to paper architecture' + + if (!isScreensExampleApp() || !isNewArchitectureEnabled()) { + return + } + + dependsOn tasks.generateCodegenArtifactsFromSchema + + doLast { + + def absoluteCodegenArtifactsPaperDestination = getAbsoluteCodegenArtifactsPaperDestination() + def absoluteCodegenArtifactsSource = getAbsoluteCodegenArtifactsSource() + + def existingFiles = fileTree(absoluteCodegenArtifactsPaperDestination).matching { + include '**/*.java' + } + + def generatedFiles = fileTree(absoluteCodegenArtifactsSource).matching { + include '**/*.java' + } + + def existingFilesMap = [:] + + existingFiles.forEach { existingFile -> + existingFilesMap[existingFile.name] = 1 + } + + generatedFiles.forEach { generatedFile -> + if (!existingFilesMap.containsKey(generatedFile.name)) { + logger.warn("[RNScreens] ${generatedFile.name} not found in paper dir, if it's used in Android you need to copy it manually and implement yourself before using auto-copy feature") + } + } + + if (existingFiles.size() == 0) { + logger.warn("[RNScreens] Paper destination with codegen interfaces is empty. This might be okay if you don't have any interfaces/delegates used in Android, if that's not the case please check if codegenArtifactsPaperDestination in android/gradle.properties is correct") + } + + if (existingFiles.size() > generatedFiles.size()) { + throw new Exception("[RNScreens] Number od generated artifacts should be greather then or equal to paper interfaces. Please check if codegenArtifactsSource in android/gradle.properties is correct") + } + + copy { + from absoluteCodegenArtifactsSource + include existingFiles.collect { it.name } + into absoluteCodegenArtifactsPaperDestination + } + } +} + +if (isScreensExampleApp() && isNewArchitectureEnabled()) { + tasks.generateCodegenArtifactsFromSchema.finalizedBy('copyCodegenArtifacts') +} diff --git a/android/gradle.properties b/android/gradle.properties index 708d4222b3..c2b7b4bedf 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -21,3 +21,10 @@ android.useAndroidX=true android.enableJetifier=true kotlin.code.style=official + +# Path to codegen output directory with this library view manager's interfaces & delegates. Used by `copyCodegenArtifacts` task that helps to synchronise newly generated files with their Paper conterparts. +codegenArtifactsSource=android/build/generated/source/codegen/java/com/facebook/react/viewmanagers + +# Path to directory with view manager's interfaces & delegates used while running on Paper architecture. This property is used as output path for `copyCodegenArtifacts` task. +# Used for task (copyCodegenArtifacts) that automates copying those interfaces/delegates when codegen is run +codegenArtifactsPaperDestination=android/src/paper/java/com/facebook/react/viewmanagers/