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

Android build fails #10

Open
olliiiver opened this issue Dec 4, 2024 · 5 comments · May be fixed by #11
Open

Android build fails #10

olliiiver opened this issue Dec 4, 2024 · 5 comments · May be fixed by #11

Comments

@olliiiver
Copy link
Contributor

Hello.

I'm trying to build the library for iOS and Android. iOS build works perfectly fine by using Expo.

I was wondering, if I can also do a build for Android as well, but that fails with the following message:

  C++ build system [configure] failed while executing:
      /Users/oliver/Library/Android/sdk/cmake/3.22.1/bin/cmake \
        -H/Users/oliver/Documents/cc/matrix-test/matrix-test/node_modules/react-native/ReactAndroid/cmake-utils/default-app-setup \
        -DCMAKE_SYSTEM_NAME=Android \
        -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
        -DCMAKE_SYSTEM_VERSION=24 \
        -DANDROID_PLATFORM=android-24 \
        -DANDROID_ABI=arm64-v8a \
        -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
        -DANDROID_NDK=/Users/oliver/Library/Android/sdk/ndk/26.1.10909125 \
        -DCMAKE_ANDROID_NDK=/Users/oliver/Library/Android/sdk/ndk/26.1.10909125 \
        -DCMAKE_TOOLCHAIN_FILE=/Users/oliver/Library/Android/sdk/ndk/26.1.10909125/build/cmake/android.toolchain.cmake \
        -DCMAKE_MAKE_PROGRAM=/Users/oliver/Library/Android/sdk/cmake/3.22.1/bin/ninja \
        -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/oliver/Documents/cc/matrix-test/matrix-test/android/app/build/intermediates/cxx/Debug/536k5e17/obj/arm64-v8a \
        -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/Users/oliver/Documents/cc/matrix-test/matrix-test/android/app/build/intermediates/cxx/Debug/536k5e17/obj/arm64-v8a \
        -DCMAKE_BUILD_TYPE=Debug \
        -DCMAKE_FIND_ROOT_PATH=/Users/oliver/Documents/cc/matrix-test/matrix-test/android/app/.cxx/Debug/536k5e17/prefab/arm64-v8a/prefab \
        -B/Users/oliver/Documents/cc/matrix-test/matrix-test/android/app/.cxx/Debug/536k5e17/arm64-v8a \
        -GNinja \
        -DPROJECT_BUILD_DIR=/Users/oliver/Documents/cc/matrix-test/matrix-test/android/app/build \
        -DREACT_ANDROID_DIR=/Users/oliver/Documents/cc/matrix-test/matrix-test/node_modules/react-native/ReactAndroid \
        -DANDROID_STL=c++_shared \
        -DANDROID_USE_LEGACY_TOOLCHAIN_FILE=ON
    from /Users/oliver/Documents/cc/matrix-test/matrix-test/android/app
  CMake Error at /Users/oliver/Documents/cc/matrix-test/matrix-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:9 (add_subdirectory):
    add_subdirectory given source
    "/Users/oliver/Documents/cc/matrix-test/matrix-test/node_modules/@unomed/react-native-matrix-sdk/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/oliver/Documents/cc/matrix-test/matrix-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:85 (include)
    CMakeLists.txt:31 (include)


  CMake Error at /Users/oliver/Documents/cc/matrix-test/matrix-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:88 (target_link_libraries):
    Cannot specify link libraries for target
    "react_codegen_RNReactNativeMatrixSdkSpec" which is not built by this
    project.

For reproducing this, I've added a small repo here:

https://github.com/olliiiver/matrix_rust_sdk_test

It seems the build process is missing a build step. How can I fix this?

Any help would be greatly appreciated!

Regards,

Oliver

@Johennes
Copy link
Collaborator

Johennes commented Dec 4, 2024

This might mean that the code generation didn't run. 🤔

    "/Users/oliver/Documents/cc/matrix-test/matrix-test/node_modules/@unomed/react-native-matrix-sdk/android/build/generated/source/codegen/jni/"
    which is not an existing directory.

I'm not at all familiar with Expo, unfortunately, but in the example app in this repo, codegen is triggered in build.gradle: https://github.com/unomed-dev/react-native-matrix-sdk/blob/main/example/android/app/build.gradle#L125

@olliiiver
Copy link
Contributor Author

Hi @Johennes.

Thanks for the quick response. Looks like the code is being built automatically in android/generated/jni without the need of any specific config in the react native project.

If I copy over the files after a first run, the Android build works:

mkdir -p ./node_modules/@unomed/react-native-matrix-sdk/android/build/generated/source/codegen
cp -r ./node_modules/@unomed/react-native-matrix-sdk/android/generated/jni ./node_modules/@unomed/react-native-matrix-sdk/android/build/generated/source/codegen

I would provide a PR, but I couldn't figure out where the codegen directory is (or can be) specified inside build process of the library.

Any idea?

Regards,

Oliver

@Johennes
Copy link
Collaborator

Johennes commented Dec 9, 2024

Oh, interesting. The output directories for codegen are specified in package.json.

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

It's interesting that they're being expected in another location in your build. 😵‍💫

Could you check if changing the outputDir values makes it codegen into the right location in your build?

We made a fix in uniffi-bindgen-react-native to handle non-standard codegen output dirs a while ago that hasn't been consumed in react-native-matrix-sdk yet. However, I'm not sure that's related.

@olliiiver
Copy link
Contributor Author

Hi @Johennes,

I've changed the outputDir in package.json, but without any luck.

It seems that React Native expects the files at android/build/generated/source/codegen/ rather than in android/generated, see:

https://github.com/facebook/react-native/blob/3cc67fed36c9bc52e5aafec6aeceb21c95a1f919/packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake#L99

However, I couldn't find the right place where the build process creates android/generated, so that this part could be changed...

@Johennes
Copy link
Collaborator

I think you might have to trigger codegen manually after changing package.json with yarn react-native codegen --path node_modules/@unomed/react-native-matrix-sdk.

When I apply the following diff, I'm getting the generated code under the expected path.

diff --git a/package.json b/package.json
index 38a562a..36aeacd 100644
--- a/package.json
+++ b/package.json
@@ -201,7 +201,7 @@
     "jsSrcsDir": "src",
     "outputDir": {
       "ios": "ios/generated",
-      "android": "android/generated"
+      "android": "android/build/generated/source/codegen"
     },
     "android": {
       "javaPackageName": "com.unomed.reactnativematrixsdk"
diff --git a/react-native.config.js b/react-native.config.js
index 21980d4..66211da 100644
--- a/react-native.config.js
+++ b/react-native.config.js
@@ -5,7 +5,7 @@ module.exports = {
   dependency: {
     platforms: {
       android: {
-        cmakeListsPath: 'generated/jni/CMakeLists.txt',
+        cmakeListsPath: 'build/generated/source/codegen/jni/CMakeLists.txt',
       },
     },
   },

I'm still confused that ReactNative-application.cmake hardcodes a specific path when the output folder is configurable in package.json.

I'm also not sure why I haven't seen this in the project I'm consuming react-native-matrix-sdk but maybe it's because I'm not on the latest RN version there.

Johennes added a commit that referenced this issue Dec 11, 2024
@Johennes Johennes linked a pull request Dec 11, 2024 that will close this issue
Johennes added a commit that referenced this issue Dec 11, 2024
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