IntelliJ and AndroidStudio - connect to Gitlab.com respository

1.9k Views Asked by At

Via Git UI and Turtoise UI I updated the local and remote GIT repositories. I would like to interact with the gitlab.com repositories in Android Studio and IntelliJ. I keep on getting 401 or read errors.

In IntelliJ I tried to connect to the remote repository via VCS > GIT > Remotes and added the gitlab.com SSH entry. Also in Android Studio I could not connect to the remote repository.

SOLUTION: thanks to VonC. The SSH keys I registered at Gitlab.com were in my c:\users\myusername\.ssh folder. Via the Turtoise and GIT UI I could refer directly to these files.

Both the Android Studio and IJ IDE's use the %HOME% folder to find the SSH keys. This folder may refer tot the System's SSH folder. Because no SSH keys were available in that folder, I kept on getting connection errors.

The solution was in creating a command (.bat) file that does the following for IntelliJ:

set HOME=%USERPROFILE%
c:
cd "C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.1\bin"
idea.exe

And for AS:

set HOME=%USERPROFILE%
c:
cd C:\Program Files\Android\Android Studio1\bin
studio64.exe
2

There are 2 best solutions below

21
On BEST ANSWER

Let's be clear: if you are using https url, and your username/password GitLab.com account, your ssh keys have nothing to do with your connection attempt: those ssh keys (puttygen or not) will be ignored.

For https, you need your GitLab account credentials, and if your GitLab password has a special character in it, it needs to be percent encoded (like a @).

See also "Handling Passwords for Git Remote Repositories" (again, nothing to do with ssh).

If you select "Clone git repositories using ssh" (as in this answer), then, even if Git does not find your ssh keys (or if your public key is not properly registered in your GitLab account), ssh will be able to fallback to the username/password authentication scheme.


To use ssh urls in AS (Andoird Studio):

  • make sure to launch AS in a CMD session when HOME (type set HOME) is set to %USERPROFILE%,
  • make sure to have generated openssh keys, as described by GitLab and registered to your GitLAb profile, again as described by GitLab.
    You must see in %USERPROFILE%\.ssh (or %HOME%\.ssh) the files id_rsa and id_rsa.pub. No ppk puttygen keys required.

The OP adds:

Ah, the %HOME% and %USERPROFILE% pointed to different locations. I set the id_rsa at %USERPROFILE% and %HOME% points to the system folder. So, using the id_rsa.pub from the C:\WINDOWS\system32\config \systemprofile should also sufficie?

Actually, if HOME points to the system folder, it means AS is running with the system account, or Git was installed for the system account.
Don't: HOME should refers to %USERPROFILE%, and make sure AS is launched with your account. The OP notes:

HOME=%USERPROFILE% solution also works perfectly for IntelliJ, so it is not only for Android Studio.

8
On

I think you have mistaken GitHub supportwith GitLab projects plugin and trying to authenticate to GitHub using GitLab credentials. Search for GitLab plugin, install gitlab projects: enter image description here

and configure it using GitLab URL and API Key that you can find in your account settings.

enter image description here