ammarahm-ed / react-native-jsi-template

Template library and blog that explain how JSI modules are built from scratch in React Native
https://blog.notesnook.com/getting-started-react-native-jsi/
MIT License
163 stars 24 forks source link

Symlink template in example #12

Closed JiriHoffmann closed 2 years ago

JiriHoffmann commented 2 years ago

Note that there is a weird quirk I have not been able to figure out. While building the example on Android I kept running into issues with REACT_NATIVE_JNI_LIB in android/CMakeLists.txt not being found. Simply logging the LIBRN_DIR variable with message() seems to fix the issue. Also, this happens only during the first build. So even if the message() is removed after the first successful build, it will keep working. For now, I just left it there.

Closes #11

ammarahm-ed commented 2 years ago

Thanks for the PR. The issue with REACT_NATIVE_JNI_LIB is known. It happens because we have to copy over all RN aar file before compiling c++ code. But for some reason the copying function in gradle build does not get called. Probably because different versions of gradle work differently. Here is how I have fixed the problem:

def extracted = false;
task extractJNIFiles {
  if (extracted) return
  doLast {
    configurations.extractJNI.files.each {
      def file = it.absoluteFile

      copy {
        from zipTree(file)
        into "$buildDir/$file.name"
        include "jni/**/*"
      }
      extracted = true;
    }
  }
}

// Attach extraction function tasks to all tasks
tasks.whenTaskAdded { task ->
  task.dependsOn(extractJNIFiles);
}

As soon as gradle build starts, it makes all the task depend on extractJNIFiles function. Then later, once files are extracted, we set extracted:true after which we ignore all calls made to extractJNIFiles by other tasks.

JiriHoffmann commented 2 years ago

I included that code in the PR, but the issue is still there

ammarahm-ed commented 2 years ago

@JiriHoffmann I think this is a seperate problem. I will look into it again. It has been working on my library but i guess it isn't 100% perfect. Maybe we should read gradle docs to see how to run a task before all other tasks so we are sure rn aar is there always.