git android studio project,將Android Studio項目從git導入Android Studio(Gradle)

博客作者在尝试从远程Git仓库克隆Android Studio项目时遇到问题,发现.gitignore仅包含app目录,导致Android Studio无法正确处理。解决方案包括检查项目的.gitignore文件,确保必要的build.gradle文件被包含在推送至远程仓库的文件中;选择“从现有源创建项目”而非“导入”;以及解决Gradle相关问题。
摘要由CSDN通过智能技术生成

I've been reading this for hours now and everyone seems to have a different approach or that the tutorials are out of date.

我現在已經閱讀了好幾個小時,每個人似乎都有不同的方法,或者教程已經過時了。

Android Studio .gitignore only includes the app directory, this is on purpose. For what reason I do not know. When trying to clone the git repo Android Studio does not know how to handle it. A very annoying flaw in Android Studio.

Android Studio .gitignore只包含app目錄,這是故意的。出於什么原因我不知道。當試圖克隆git repo時,Android Studio不知道如何處理它。 Android Studio中一個非常惱人的缺陷。

對於Android Studio項目,我的.gitignore應該是什么?

I have a remote git repo containing the project in the form:

我有一個遠程git倉庫包含以下形式的項目:

aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9DdE1kNy5wbmc=

as you can see the git repo contains the /app directory.

正如您所看到的,git repo包含/ app目錄。

I then try to import it via Check out project from Version Control and select git:

然后我嘗試通過從Version Control中檢出項目導入它並選擇git:

aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9VRnJiWS5wbmc=

Everything works, the Test is successful and then I click on Clone:

一切正常,測試成功,然后我點擊克隆:

fd920d5dd12d1e6a9ad03347f4934850.png

The next part I press Yes as git did not clone the entire project but just the essential source files:

下一部分我按是,因為git沒有克隆整個項目,只是基本的源文件:

92c642b67400d29859467f5d3d08615b.png

This is the part where I am lost, I am guessing I am to create the project via Gradle, so I select Gradle and press Next:

這是我迷失的部分,我猜我是通過Gradle創建項目的,所以我選擇Gradle並按Next:

d86c8be5bfe18ce39ae1005ddcf208a1.png

What am I supposed to do here, there are apparently gradle files on the net but which one am I supposed to use:

我應該在這里做什么,網上有明顯的gradle文件,但我應該使用哪一個:

ac119a2259debb8f67394a8c879b273f.png

Create project from existing sources

If I choose Create project from existing sources I get the following problem:

如果我選擇從現有源創建項目,我會遇到以下問題:

aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9DTEtRTC5wbmc=

b3b46cf2339f3cfa6a090e1b48527981.png

06a2e46cd8abfbaa161c5a19e3a5fc21.png

Results in this, I was expecting app directory:

結果在這,我期待的app目錄:

a25dac87298135e8f4bb4db699f4d537.png

File structure (as you can see fela is missing a lot of files, this is when I chose create project from existing sources, MyApplication is an example of an app which was created in Android Studio):

文件結構(正如你所看到的,fela缺少很多文件,這是當我選擇從現有源創建項目時,MyApplication是在Android Studio中創建的應用程序的示例):

e55f39c89499adac4f209fd6a3d5f3d6.png

3 个解决方案

#1

The answer is obvious when looking at the .gitignore file of a newly created project. The build.gradle file is and should be included in the push to the remote repo.

查看新創建的項目的.gitignore文件時,答案很明顯。 build.gradle文件是並且應該包含在推送到遠程倉庫中。

So the person who made the repo in my question is doing it wrong. The .gitignore file includes:

所以在我的問題中成立回購的人做錯了。 .gitignore文件包括:

.gradle

/local.properties

/.idea/workspace.xml

/.idea/libraries

.DS_Store

/build

/captures

As seen, more files should of been uploaded to the remote repo.

如圖所示,應該將更多文件上傳到遠程倉庫。

#2

Choose Existing Sources instead of Import

選擇現有來源而不是導入

#3

IF your project is showing error like The project 'xxxxxxx-xx' is not a Gradle-based project then check this link. I hope it helps. This link might cover your possible problem. Let me know the progress.

如果您的項目顯示錯誤,例如項目'xxxxxxx-xx'不是基於Gradle的項目,請檢查此鏈接。我希望它有所幫助。此鏈接可能涵蓋您可能遇到的問題。讓我知道進展情況。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值