AndroidStudioのプロジェクトをGithubにPushしてみた

AndroidStudioとGithubの連携をしてみました。

AndroidStudioで「Share Project On Github」をすると、Github上にレポジトリを作ってくれて、Pushしてくれます。

昔はID,PWでGithubにログインする形だったと思いますが、Githubの仕様が変わりPersonal Access Token(PAT)でログインする形に変わっていました。

Beginning August 13, 2021, we will no longer accept account passwords when authenticating Git operations on GitHub.com.

https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/

2021年の8月13日から、パスワードでのログインができなくなり、代わりにトークン認証を使う必要があります。

AndroidStudioで「Generate Token」を押すと、Githubのページに遷移してトークンを作ることができます。

トークンはGithubのページから作ることができますが設定項目がよく分からんので、AndroidStudioから「Generate Token」を押して遷移した方が簡単です。

トークンが作成できると以下のメールが届きます。

A personal access token (Android Studio GitHub integration plugin) with gist, read:org, repo, and workflow scopes was recently added to your account.

無事Githubと連携できてレポジトリも作成できたのですが、プッシュ時に以下のエラーが出ました。

Can’t finish GitHub sharing process
Successfully created project ‘MapSample’ on GitHub, but initial push failed:
Invocation failed Unexpected end of file from server
java.lang.RuntimeException: Invocation failed Unexpected end of file from server
at git4idea.GitAppUtil.sendXmlRequest(GitAppUtil.java:30)
at git4idea.http.GitAskPassApp.main(GitAskPassApp.java:58)
Caused by: java.net.SocketException: Unexpected end of file from server
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:866)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:863)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
設定の「Use credential helper」のチェックをオンにします。
これで解決と思いきや、以下のエラーが発生。
14:47 Push failed
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
再度Pushすると、以下のエラーが発生。
fatal: could not read Username for ‘https://github.com’: Device not configured
全く同じ原因で困っている人の投稿が以下のサイトがありました。
PCを再起動すると直るみたい。
Macを再起動してPushしたら上手く行きました。

ABOUTこの記事をかいた人

個人アプリ開発者。Python、Swift、Unityのことを発信します。月間2.5万PVブログ運営。 Twitter:@yamagablog