Gradle task assembleRelease not found in CI build, works with Android Studio

am trying to use gitlab/fastlane to build my project. When i execute the scripts in the default project they work correctly, but when the runner checks out the project the build fails with the message “Task ‘assembleRelease’ not found in root project ‘projectname’”.

When i open the CI project location in Android Studio I have to execute “sync project with gradle files” before build is available. After I have done this i can execute ./gradlew assembleRelease (and the fastlane script also works correctly)

The console output shows that several files/directories are removed when the repository is checked out:

Removing .gradle/
Removing .idea/
Removing app/app.iml
Removing app/build/
Removing build/
Removing project.iml

I can’t seem to find what exactly Android Studio does when I select “Sync Project with Gradle Files” and how i reproduce that with my build script.