'launch.xml' launch error in ros-foxy snap package

I am packaging my code into a snap package using snapcraft and ran into this error

[INFO] [launch]: All log files can be found below /home/ragesh/snap/multirobot-sim/x3/.ros/log/2023-05-23-14-05-35-905904-ipa-rar-136909
[INFO] [launch]: Default logging verbosity is set to INFO
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<LaunchService._process_one_event() done, defined at /snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py:226> exception=InvalidLaunchFileError('')>
Traceback (most recent call last):
  File "/snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 228, in _process_one_event
    await self.__process_event(next_event)
  File "/snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 248, in __process_event
    visit_all_entities_and_collect_futures(entity, self.__context))
  File "/snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
    futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
  File "/snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
    futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
  File "/snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futures
    sub_entities = entity.visit(context)
  File "/snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/action.py", line 108, in visit
    return self.execute(context)
  File "/snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/include_launch_description.py", line 130, in execute
    launch_description = self.__launch_description_source.get_launch_description(context)
  File "/snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_source.py", line 84, in get_launch_description
    self._get_launch_description(self.__expanded_location)
  File "/snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_description_source.py", line 53, in _get_launch_description
    return get_launch_description_from_any_launch_file(location)
  File "/snap/multirobot-sim/x3/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py", line 56, in get_launch_description_from_any_launch_file
    raise InvalidLaunchFileError(extension, likely_errors=exceptions)
launch.invalid_launch_file_error.InvalidLaunchFileError: The launch file may have a syntax error, or its format is unknown

My snapcraft.yaml looks like this

name: multirobot-sim
version: "0.1"
summary: Multirobot simulation for swarmBot project
description: |
  This launches a complete simulation with 4 robots and its navigation2 stack

base: core20
confinement: devmode

parts:
  multirobot-sim:
    plugin: colcon
    source: https://github.com/swarmBots-ipa/multirobot_simulation.git
    source-branch: rar_devel
    build-packages: 
      - ros-foxy-ros2cli
    stage-packages: 
      - ros-foxy-ros2launch
      - ros-foxy-ros2cli

apps:
  multirobot-sim:
    command: opt/ros/foxy/bin/ros2 launch multirobot_bringup multirobot_bringup.launch.xml
    extensions: [ros2-foxy]
    plugs: [network, network-bind]
    command-chain: [snap/command-chain/ros2-launch]
    environment:
      PYTHONPATH: $SNAP/opt/ros/foxy/lib/python3.8/site-packages:$SNAP/usr/lib/python3/dist-packages:${PYTHONPATH}
      ROS_DISTRO: foxy
      ROS_VERSION: '2'

And my launch file is a launchfile.launch.xml and not launchfile.launch.py. What could be possiblity of the error and how to fix it.

Hi @ragesh_r,

You most likely need to add ros-foxy-launch-xml as a stage-packages:

stage-packages:
      - ros-foxy-launch-xml
      - ros-foxy-ros2launch
      - ros-foxy-ros2cli

Let me know if that solves your issue.

1 Like

@artivis Thank you for the hint. Now I am able to launch but have a package not foud error.

LookupError: Could not find the resource 'gazebo_ros' of type 'packages'
raise PackageNotFoundError(
ament_index_python.packages.PackageNotFoundError: "package 'gazebo_ros' not found, searching: ['/snap/multirobot-sim/x5/opt/ros/snap', '/snap/multirobot-sim/x5/opt/ros/foxy']"

How do I declare the dependencies that are not specified in package.xml. Is there someway to do this or have to declare it in the package.xml ?

You can simply declare them as stage-packages as we did for the ros-foxy-launch-xml package. This being said, it’s probably better to have them in your package.xml file if they are indeed required.

I haven’t looked at the application you are trying to build but I see the gazebo_ros package. Are you intending to run a graphical application (gazebo?) from the snap? If so, you will need some extra work and most probably the kde-neon extension.

1 Like

@artivis I am trying to run a simulation world of multi-robots with nav2 stack inside the snap. It will launch the gazebo world and rviz for interaction.