Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work anymore with create-react-native-library@0.41.2 & react-native@0.76.1 #161

Closed
Johennes opened this issue Nov 12, 2024 · 3 comments · Fixed by #165
Closed

Doesn't work anymore with create-react-native-library@0.41.2 & react-native@0.76.1 #161

Johennes opened this issue Nov 12, 2024 · 3 comments · Fixed by #165

Comments

@Johennes
Copy link
Collaborator

The codegenConfig block now seems to include output dirs for the generated code.

  "codegenConfig": {
    "name": "RNReactNativeMatrixSdkSpec",
    "type": "all",
    "jsSrcsDir": "src",
    "outputDir": {
      "ios": "ios/generated",
      "android": "android/generated"
    },
    "android": {
      "javaPackageName": "com.unomed.reactnativematrixsdk"
    },
    "includesGeneratedCode": true
  },

UBRN doesn't appear to use these for Android and instead tries to include the generated code from android/build/generated/source/codegen/java in android/build.gradle.

          java.srcDirs += [
            // This is needed to build Kotlin project with NewArch enabled
            "${project.buildDir}/generated/source/codegen/java"
          ]

I tried changing the output dir for Android in package.json to comply with the value UBRN expects but this gave me another error. The only thing I found working so far is to manually patch build.gradle.

          java.srcDirs += [
            // This is needed to build Kotlin project with NewArch enabled
-            "${project.buildDir}/generated/source/codegen/java"
+            "${project.buildDir}/../generated/java"
          ]

UBRN should read the values from package.json and use them accordingly.

@jhugman
Copy link
Owner

jhugman commented Nov 12, 2024

@Johennes I'm not sure if you want to fix this yourself, or not. If you don't then, no worries, but it will take a week or two for me to get to it. If you do, great! This is what I'd suggest:

Reading the outputDir from package.json should be a case of adding a struct to npm.rs. I think that file has some #[serde(default ="…")]` functions.

You may need to add something to AndroidConfig and IosConfig so it's accessible from the templates. The javaPackageName property is a reasonable template for how all this ties together.

I'm not sure if you need to add something to build.gradle too but you'll likely want to add to build.kt.gradle. I haven't looked at the current build.gradle from CRNL, so it may be better just to add some lines, or to completely re-do it.

Looking up a relative path has a utility method on RenderedFile; here it is used in the templates:

  {%- let root = self.project_root() %}
  {%- let dir = self.config.project.ios.framework_path(root) %}
  {%- let framework = self.relative_to(root, dir) %}

I think you have a good handle on what's going on with the script/test-turbo-modules.sh.

What do you think?

@Johennes
Copy link
Collaborator Author

Johennes commented Nov 13, 2024

Thanks for the detailed steps. Let me try and take a stab at this.

I wanted to first set up the bob / rn test matrix we spoke about but was surprised when the issue didn't reproduce there. It turns out that build.kt.gradle doesn't have this issue as long as you don't change the default paths that crnl puts into package.json because of this:

java.srcDirs += [
"generated/java",
"generated/jni"

When I first generated my project, however, crnl wasn't yet using Kotlin so this check always failed for me:

That in turn meant that ubrn would always generate from the build.gradle template which expects the generated code in another folder:

java.srcDirs += [
// This is needed to build Kotlin project with NewArch enabled
"${project.buildDir}/generated/source/codegen/java"

@Johennes
Copy link
Collaborator Author

Given that as of writing the lowest version of crnl that is not broken1 is 0.42.2 and given that this version uses Kotlin rather than Java, maybe we can ditch the build.gradle template and always use build.kt.gradle?

Footnotes

  1. 0.42.1 is missing @react-native-community/cli and all lower versions have the unknown option '--npm' issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants