63

I'm trying to connect to a GitLab repository using the I/O preview of Android Studio. Does anyone know how to do this/if it is possible yet?

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Liz Barrett
  • 707
  • 1
  • 7
  • 8
  • 2
    it's a pity Android Studio doesn't have a "GitLab" entry for File -> Settings -> Version Control. There's only a "GitHub" option and it's not compatible with GitLab. It seems to me, that GitHub is promoted over GitLab – Someone Somewhere Mar 31 '20 at 21:33

3 Answers3

111

How to add an Android Studio project to GitLab

This answer shows how to do it using the Android Studio GUI.

1. Create a new project on GitLab

Chose the + button on the menu bar. Add a project name and then click "Create project".

enter image description here

This will give you a new project address. Choose the https version.

enter image description here

It will look something like this:

https://gitlab.com/MyUserName/my-project.git

2. Create a Git repository in Android Studio

In the Android Studio menu go to VCS > Import into Version Control > Create Git Repository...

enter image description here

Select the root directory of your project. (It will be automatically selected if you already have it highlighted in the Project view. Otherwise you will have to browse up to find it.)

3. Add remote

Go to VCS > Git > Remotes.... Then paste in the https address you got from GitLab in step one.

enter image description here

You may need to log in with your GitLab username and password.

4. Add, commit, and push your files

Make sure you have the top level of the project selected. If you are in the Android view you can switch it to the Project view.

enter image description here

  • Add: Go to VCS > Git > Add.

  • Commit: After adding, do VCS > Git > Commit Directory. (You will need to write a commit message, something like initial commit.)

  • Push: Finally, go to VCS > Git > Push.

Finished!

You should be able to view your files in GitLab now.

See also

There is a plugin that would probably streamline the process. Check it out here.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • i got this error Remote URL test failed: Authentication failed for 'https://gitlab.com/codenex/shopping.git/ – Praveen Aug 30 '18 at 11:39
  • 1
    @Suragch Sir I am getting url like this http://192.168.0.52/pvijayalakshmi/eEmployee.git from step 1: But When I enter this url in android studio, It is giving me this Error:Remote URL test failed: Unable to find remote helper for 'http' – vishnu Sep 14 '18 at 12:05
  • 1
    Awesome guide, post it in Medium! – Erich García Oct 15 '18 at 13:37
  • 1
    it slightly changed since 2017 now its VCS > Get from Version Control, then select Git, give the url and the local directory of the gitlab project. It will do the steps 2 and 3 at the same time. – Cadeyrn Apr 23 '23 at 09:33
57

To clone a repo

Open a new project in Android Studio.

Click VCS -> Checkout from version control -> Git

then enter the URL of the repo and your local direcory

To commit

Open the project you want to push in Android Studio.

Click VCS -> Enable version Control -> Git

There does't seem to be a way to add a remote through the GUI. So open Git Bash in the root of the project add do git remote add <remote_name> <remote_url>.

Now when you do VCS -> Commit changes -> Commit & Push you should see your remote and everything should work through the GUI.


See these pages for details:

http://www.jetbrains.com/idea/webhelp/using-git-integration.html

http://youtrack.jetbrains.com/issue/IDEA-87099

jsc0
  • 3,807
  • 1
  • 17
  • 8
0

Use CodeStream plugin, easy configuration

mostapha
  • 189
  • 1
  • 7
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30835510) – Simas Joneliunas Jan 20 '22 at 07:11