简体   繁体   English

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

[英]Import Android Studio project from git into Android Studio (Gradle)

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. Android Studio .gitignore只包含app目录,这是故意的。 For what reason I do not know. 出于什么原因我不知道。 When trying to clone the git repo Android Studio does not know how to handle it. 当试图克隆git repo时,Android Studio不知道如何处理它。 A very annoying flaw in 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仓库包含以下形式的项目:

在此输入图像描述

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 : 然后我尝试通过Check out project from Version Control导入它并选择git

在此输入图像描述

Everything works, the Test is successful and then I click on Clone : 一切正常, Test成功,然后我点击Clone

在此输入图像描述

The next part I press Yes as git did not clone the entire project but just the essential source files: 下一部分我按Yes因为git没有克隆整个项目,只是基本的源文件:

在此输入图像描述

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

在此输入图像描述

What am I supposed to do here, there are apparently gradle files on the net but which one am I supposed to use: 我应该在这里做什么,网上有明显的gradle文件,但我应该使用哪一个:

在此输入图像描述

Create project from existing sources 从现有来源创建项目

If I choose Create project from existing sources I get the following problem: 如果我选择Create project from existing sources我会遇到以下问题:

在此输入图像描述

在此输入图像描述

在此输入图像描述

Results in this, I was expecting app directory: 结果在这,我期待的app目录:

在此输入图像描述

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

在此输入图像描述

The answer is obvious when looking at the .gitignore file of a newly created project. 查看新创建的项目的.gitignore文件时,答案很明显。 The build.gradle file is and should be included in the push to the remote repo. 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. 如图所示,应该将更多文件上传到远程仓库。

选择现有来源而不是导入

IF your project is showing error like The project 'xxxxxxx-xx' is not a Gradle-based project then check this link . 如果您的项目显示错误,例如The project 'xxxxxxx-xx' is not a Gradle-based project请检查此链接 I hope it helps. 我希望它有所帮助。 This link might cover your possible problem. 此链接可能涵盖您可能遇到的问题。 Let me know the progress. 让我知道进展情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM