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

Flutter app not building on Linux. CMake Error at flutter/ephemeral/.plugin_symlinks/realm/linux/CMakeLists.txt:38 (file): file does not recognize sub-command REAL_PATH #1381

Closed
thiagokisaki opened this issue Aug 16, 2023 · 17 comments · Fixed by #1444 or #1488

Comments

@thiagokisaki
Copy link
Contributor

thiagokisaki commented Aug 16, 2023

What happened?

Flutter application is not building on Linux after installing realm package.

It looks like we're trying to use a sub-command that has added in CMake 3.19 in CMakeLists.txt, while specifying the minimum CMake version as 3.10.

Note:
I installed Flutter using snap,

sudo snap install flutter --classic

which comes with CMake 3.16.3.

Repro steps

Create an app:

flutter create my_app
cd my_app

Install realm:

flutter pub add realm

Try to launch the app:

flutter run -d linux

Output:

Launching lib/main.dart on Linux in debug mode...
CMake Error at flutter/ephemeral/.plugin_symlinks/realm/linux/CMakeLists.txt:38 (file):
  file does not recognize sub-command REAL_PATH


Could not find file `realm`
Could not find file `realm`
Building Linux application...
Exception: Unable to generate build files### Version

Dart: 3.0.6 / Flutter: 3.10.6

What Atlas Services are you using?

Local Database only

What type of application is this?

Flutter Application

Client OS and version

Ubuntu 22.04

Code snippets

No response

Stacktrace of the exception/crash you're getting

No response

Relevant log output

flutter doctor -v

[✓] Flutter (Channel stable, 3.10.6, on Ubuntu 22.04.3 LTS 6.2.0-26-generic,
    locale en_US.UTF-8)
    • Flutter version 3.10.6 on channel stable at
      /home/thiago/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (5 weeks ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /home/thiago/Android/Sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /usr/local/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2022.2)
    • Android Studio at /usr/local/android-studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension version 3.70.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.3 LTS
      6.2.0-26-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 116.0.5845.96

[✓] Network resources
    • All expected network resources are available.

• No issues found!
@blagoev
Copy link
Contributor

blagoev commented Aug 16, 2023

Hi,
thanks for reporting. This seems an oversight on our side. As a workaround you can just install a newer version of cmake.

Thanks

@malaak-habashy
Copy link

malaak-habashy commented Sep 8, 2023

I'm getting the same error

Ubuntu 22.04.3 LTS (64-bit)
Flutter 3.13.2
Dart SDK version: 3.1.0

I updated cMake to:
cmake version 3.27.4

still getting the same error

CMake Error at flutter/ephemeral/.plugin_symlinks/realm/linux/CMakeLists.txt:38 (file):
file does not recognize sub-command REAL_PATH
Could not find file realm
Exception: Unable to generate build files

@malaak-habashy
Copy link

realm version: 1.2.0
works

realm versions: 1.3.0 and 1.4.0
don't work

@thiagokisaki
Copy link
Contributor Author

thiagokisaki commented Sep 18, 2023

I was able to fix it by adjusting the CMakeLists.txt.

To solve

file does not recognize sub-command REAL_PATH

Replace the line

file(REAL_PATH ${APP_PUBSPEC_FILE} ABSOLUTE_PATH_APP_PUBSPEC_FILE)

with:

get_filename_component(ABSOLUTE_PATH_APP_PUBSPEC_FILE ${APP_PUBSPEC_FILE} REALPATH)

To solve

Could not find file `realm`
Could not find file `realm`

I provided WORKING_DIRECTORY option to execute_process with a new declared variable:

get_filename_component(ABSOLUTE_PATH_APP_DIR ${APP_DIR} REALPATH)
execute_process(COMMAND "${FLUTTER_ROOT}/bin/dart" "run" "realm" "install" "--target-os-type" "linux" "--flavor" "flutter" #"--debug"
  WORKING_DIRECTORY ${ABSOLUTE_PATH_APP_DIR}
  OUTPUT_VARIABLE output
  RESULT_VARIABLE result
  # COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
  COMMAND "${FLUTTER_ROOT}/bin/dart" "run" "realm" "metrics" "--verbose" "--flutter-root" "${FLUTTER_ROOT}/bin" "--target-os-type" "linux" "--target-os-version" "${CMAKE_HOST_SYSTEM_VERSION}" #"--pause-isolates-on-start" "--enable-vm-service"
  # COMMAND ${CMAKE_COMMAND} -E true
  WORKING_DIRECTORY ${ABSOLUTE_PATH_APP_DIR}
  OUTPUT_VARIABLE output
  RESULT_VARIABLE result
  # COMMAND_ERROR_IS_FATAL LAST
)

After all the changes, my file looks like this:

cmake_minimum_required(VERSION 3.10)

set(PROJECT_NAME "realm")
project(${PROJECT_NAME} LANGUAGES CXX)

# This value is used when generating builds using this plugin, so it must
# not be changed.
set(PLUGIN_NAME "realm_plugin")

add_library(${PLUGIN_NAME} SHARED "realm_plugin.cpp")

apply_standard_settings(${PLUGIN_NAME})

set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)

target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)

set(realm_bundled_libraries
  "${PROJECT_SOURCE_DIR}/binary/linux/librealm_dart.so"
  PARENT_SCOPE
)

# message ("CMAKE_BINARY_DIR is ${CMAKE_BINARY_DIR}")
# message ("PROJECT_SOURCE_DIR is ${PROJECT_SOURCE_DIR}")
# message ("CMAKE_CURRENT_SOURCE_DIR is ${CMAKE_CURRENT_SOURCE_DIR}")

# This works cause realm plugin is always accessed through the .plugin_symlinks directory.
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../ephemeral")
include(${EPHEMERAL_DIR}/generated_config.cmake)

set(APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../..")
# message ("APP_DIR is ${APP_DIR}")
get_filename_component(ABSOLUTE_PATH_APP_DIR ${APP_DIR} REALPATH)
# message ("ABSOLUTE_PATH_APP_DIR is ${ABSOLUTE_PATH_APP_DIR}")
set(APP_PUBSPEC_FILE "${APP_DIR}/pubspec.yaml")
# message ("APP_PUBSPEC_FILE is ${APP_PUBSPEC_FILE}")
# file(REAL_PATH ${APP_PUBSPEC_FILE} ABSOLUTE_PATH_APP_PUBSPEC_FILE)
get_filename_component(ABSOLUTE_PATH_APP_PUBSPEC_FILE ${APP_PUBSPEC_FILE} REALPATH)
# message ("ABSOLUTE_PATH_APP_PUBSPEC_FILE is ${ABSOLUTE_PATH_APP_PUBSPEC_FILE}")
file(READ "${ABSOLUTE_PATH_APP_PUBSPEC_FILE}" PUBSPEC_CONTENT)
string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT})
# message ("Pubspec name 0 is ${CMAKE_MATCH_0}")
# message ("Package name is ${CMAKE_MATCH_1}")
set(BUNDLE_ID ${CMAKE_MATCH_1})

add_definitions(-DAPP_DIR_NAME="${APPLICATION_ID}")
add_definitions(-DBUNDLE_ID="${BUNDLE_ID}")


# message ("FLUTTER_TOOL_ENVIRONMENT is ${FLUTTER_TOOL_ENVIRONMENT}")
# message ("FLUTTER_ROOT is ${FLUTTER_ROOT}")

execute_process(COMMAND "${FLUTTER_ROOT}/bin/dart" "run" "realm" "install" "--target-os-type" "linux" "--flavor" "flutter" #"--debug"
  WORKING_DIRECTORY ${ABSOLUTE_PATH_APP_DIR}
  OUTPUT_VARIABLE output
  RESULT_VARIABLE result
  # COMMAND_ERROR_IS_FATAL ANY
)
message(STATUS "cmd output: ${output}")
message(STATUS "cmd result: ${result}")

# message("CMAKE_HOST_SYSTEM_VERSION ${CMAKE_HOST_SYSTEM_VERSION}")
execute_process(
  COMMAND "${FLUTTER_ROOT}/bin/dart" "run" "realm" "metrics" "--verbose" "--flutter-root" "${FLUTTER_ROOT}/bin" "--target-os-type" "linux" "--target-os-version" "${CMAKE_HOST_SYSTEM_VERSION}" #"--pause-isolates-on-start" "--enable-vm-service"
  # COMMAND ${CMAKE_COMMAND} -E true
  WORKING_DIRECTORY ${ABSOLUTE_PATH_APP_DIR}
  OUTPUT_VARIABLE output
  RESULT_VARIABLE result
  # COMMAND_ERROR_IS_FATAL LAST
)
message(STATUS "cmd output: ${output}")
message(STATUS "cmd result: ${result}")

@blagoev
Copy link
Contributor

blagoev commented Sep 18, 2023

If you update cmake to a version 3.19 or newer this should go away. are you sure you are using the newer cmake version on your env?

@thiagokisaki
Copy link
Contributor Author

I can't update the CMake version because I installed Flutter using snap.

@blagoev
Copy link
Contributor

blagoev commented Sep 18, 2023

How is the cmake installed on the machine related to the Flutter install? You should be able to just install cmake on your machine separately.

@thiagokisaki
Copy link
Contributor Author

After changing the file I was able to make it work with CMake 3.16.3 and the latest realm package version (1.5.0).

@blagoev
Copy link
Contributor

blagoev commented Sep 18, 2023

great. and thanks for reporting.

@thiagokisaki
Copy link
Contributor Author

How is the cmake installed on the machine related to the Flutter install? You should be able to just install cmake on your machine separately.

It looks like Flutter installation with snap comes with a fixed CMake version and that can't be upgraded.
flutter/flutter#100183 (comment)

I installed a new CMake version:

cmake --version

Output:

cmake version 3.22.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

But flutter doctor -v still shows:

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

@blagoev
Copy link
Contributor

blagoev commented Sep 18, 2023

This makes sense now. Unfortunately for now we don't support this version from the snap. As a workaround you can use a version of Flutter that's not from the snap. Luckily this is easily achievable on all platforms. You can just install Flutter from the zip they provide.

@Tembocs
Copy link

Tembocs commented Sep 22, 2023

@blagoev I'm Ubuntu 23.04 x64 and my Flutter install is NOT from snap. I have CMake version 3.27.4 and Realm 1.5. I still get the same error message. Flutter version 3.13.5.

@cmedamine
Copy link

is there any fix for this issue?

@nirinchev
Copy link
Member

There's no fix, but there's a workaround suggested in this comment: #1381 (comment)

@Tembocs
Copy link

Tembocs commented Dec 25, 2023

In case the context is lost here is the output from trying again.

flutter run -d linux
Launching lib/main.dart on Linux in debug mode...
Could not find file 'realm'
Could not find file 'realm'
CMake Error at cmake_install.cmake:124 (file):
  file INSTALL cannot find
  "~/<projectroot>/linux/flutter/ephemeral/.plugin_symlinks/realm/linux/binary/linux/librealm_dart.so":
  No such file or directory.


Building Linux application...
Exception: Build process failed

I can confirm again that the issue still persists.

  • Ubuntu 23.10
  • Flutter 3.16.5
  • CMake 3.27.4
  • Realm 1.6.1

The same app builds fine on Windows 11.

@Tembocs
Copy link

Tembocs commented Jan 9, 2024

@blagoev any updates on this issue?

@nirinchev
Copy link
Member

This issue is closed because the original problem - incorrect cmake version being required is now resolved. The error message you're getting doesn't seem to be related to what this issue is about, so please file a new one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants