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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30127943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:59:43  来源:igfitidea点击:

Import Android Studio project from git into Android Studio (Gradle)

androidgitandroid-studiogradle

提问by Karl Morrison

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 只包含应用程序目录,这是故意的。至于什么原因我不知道。尝试克隆 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 repo:

enter image description here

在此处输入图片说明

as you can see the git repo contains the /appdirectory.

如您所见,git repo 包含该/app目录。

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

然后我尝试通过导入它Check out project from Version Control并选择git

enter image description here

在此处输入图片说明

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

一切正常,Test成功,然后我点击Clone

enter image description here

在此处输入图片说明

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

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

enter image description here

在此处输入图片说明

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

这是我迷路的部分,我猜我要通过创建项目Gradle,所以我选择Gradle并按Next

enter image description here

在此处输入图片说明

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

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

enter image description here

在此处输入图片说明

Create project from existing sources

从现有源创建项目

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

如果我选择,Create project from existing sources我会遇到以下问题:

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

Results in this, I was expecting appdirectory:

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

enter image description here

在此处输入图片说明

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

enter image description here

在此处输入图片说明

采纳答案by Karl Morrison

The answer is obvious when looking at the .gitignorefile of a newly created project. The build.gradlefile isand shouldbe 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 .gitignorefile 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.

正如所见,应该将更多文件上传到远程存储库。

回答by Danny Buonocore

Choose Existing Sources instead of Import

选择现有源而不是导入

回答by Roon13

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

如果您的项目显示错误,The project 'xxxxxxx-xx' is not a Gradle-based project请查看此链接。我希望它有帮助。此链接可能涵盖您可能遇到的问题。让我知道进展。