将Android Studio项目从git导入Android Studio(Gradle)

时间:2023-01-17 13:57:38

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中一个非常恼人的缺陷。

What should be in my .gitignore for an Android Studio project?

对于Android Studio项目,我的.gitignore应该是什么?

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

我有一个远程git仓库包含以下形式的项目:

将Android Studio项目从git导入Android Studio(Gradle)

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:

将Android Studio项目从git导入Android Studio(Gradle)

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

一切正常,测试成功,然后我点击克隆:

将Android Studio项目从git导入Android Studio(Gradle)

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

下一部分我按是,因为git没有克隆整个项目,只是基本的源文件:

将Android Studio项目从git导入Android Studio(Gradle)

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:

将Android Studio项目从git导入Android Studio(Gradle)

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

我应该在这里做什么,网上有明显的gradle文件,但我应该使用哪一个:

将Android Studio项目从git导入Android Studio(Gradle)

Create project from existing sources

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

如果我选择从现有源创建项目,我会遇到以下问题:

将Android Studio项目从git导入Android Studio(Gradle)

将Android Studio项目从git导入Android Studio(Gradle)

将Android Studio项目从git导入Android Studio(Gradle)

Results in this, I was expecting app directory:

结果在这,我期待的app目录:

将Android Studio项目从git导入Android Studio(Gradle)

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中创建的应用程序的示例):

将Android Studio项目从git导入Android Studio(Gradle)

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的项目,请检查此链接。我希望它有所帮助。此链接可能涵盖您可能遇到的问题。让我知道进展情况。

#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的项目,请检查此链接。我希望它有所帮助。此链接可能涵盖您可能遇到的问题。让我知道进展情况。