How to add 'autostart' to the app

From documentation:

# Name of the desktop file placed by the application in 
# $SNAP_USER_DATA/.config/autostart to indicate that application 
# should be started with the user's desktop session. The application
# is started using the app's command wrapper (<name>.<app>) plus
# any arguments  present in the Exec=.. line inside the autostart
# desktop file.
# (snapd 2.32.4+)
autostart: <command line>

From my yaml:

apps:
  my-app:
    command: desktop-launch my-app
    autostart: my-app

From console:

sploid@PC:~/soft/my-app$ snapcraft --version
snapcraft, version 2.43.1
sploid@PC:~/soft/my-app$ snapcraft
Issues while validating snapcraft.yaml: The 'apps/my-app' property does not match the required schema: Additional properties are not allowed ('autostart' was unexpected)

Can someone explain to me why it is not working?

I think this should work with snapcraft 3.0.

Otherwise you can try this:

apps:
  my-app:
    command: desktop-launch my-app
    passthrough:
      autostart: my-app

apps.my-app.autostart still requires passthrough as of snapcraft 3.4
Is autostart still considered experimental?

I am also cant use auto start.

I am using the below, not desktop
Ubuntu Core 18
snapcraft, version 2.43.1+18.4
snapd, version 2.42.4

snapcraft.yaml
apps:
#startup (dkentry)
startup-dkentry:
command: usr/bin/my_startup.sh dkentry
plugs: [ alsa, home, serial-port, network, network-control, network-bind, network-observe, system-files ]
passthrough:
autostart: startup-dkentry

? should this work for Ubuntu Core

on ubuntu core you shold make the app a system daemon, there are no desktop sessions on ubuntu core :wink: and typcally core is a single/non user system (i.e. an appliance, gateway, router, industrial contoller)

FWIW: If using the current “stable” snapcraft (3.8), the autostart property should work without passthrough.

? is there a procedure for how a snap can install its systemd files

The systemd units are created during installation of a snap if you use the daemon: keyword in your apps section …