Trying to use Git with Android Studio

2019-03-03 14:03发布

With a friend we were a long time trying to work with Git and Android Studio, but we had a problem (we are very new to git and Android Studio, we started a couple of days ago on both issues).

What happens to us is that, for example, if I cloned the git repository and I try to make a merge, then the button to execute is grayed out and it doesn't let me compile or run it, also if I display the project structure as Android or Packages I see nothing, I can only see the files in Project, Project Files, Recent Changes, etc...

I will explain in detail everything we've done.

First, the repository looks like this (p and c are just the initials).

  x (c)
 /
x (master)
 \
  x (p)

Master has the first initial commit with .gitignore and README.md, nothing more, while we (me who created the branch p, and my friend who created the branc c) have just one commit each one with executable projects, although I'm not interested in joining what I've done with what my friend has done, I just want to start a new project of Android Studio with what my friend has made.

So I start Android Studio, "Check out project from Version Control -> GitHub", I put my key and choose the repository I want to clone, after that AS ask me if I want to create a new project and I click Yes.

enter image description here

enter image description here

I hit next until the new project is created and here I can see all the branches that we have created on GitHub.

enter image description here

After that I make a local branch to try to work with the project of my friend, with the option "Git branches -> New Branch" and calling it p, which moves me to this local branch automatically.

After that, I choose the Merge option of the remote branch origin/c, and I get a merge failure, that says "Some untracked working tree files would be overwritten by merge. Please move or remove them before you can merge.", I choose the option to view the files and it shows me these.

enter image description here

Since my project is completely new, and the project that my friend uploaded worked fine for him, I just deleted these files with the red bar that my mouse is pointing and after that a message appears that says there is no difference now.

Finally, after that, I go again to the merge option of the remote branch c, and a conflict message appears, which is on the .gitignore file, in my case I put to "Accept Theirs", and I see the message that the merge was correctly.

enter image description here

And now it is when I see that the button to execute is grayed and if I display the project structure as Android I see nothing, I can only see the files in Project, Project Files, etc...

enter image description here

I think it should be something super basic what I'm asking, but we (me and my friend) had never worked with git or android studio and now we are asked to make a project using them.

2条回答
小情绪 Triste *
2楼-- · 2019-03-03 14:58

Followed by @Akhil's answer, click "Make Project" icon to awake your Run button. Sometimes this button makes Android Studio recognize your project runnable again.

enter image description here

查看更多
淡お忘
3楼-- · 2019-03-03 14:59

This is because you have added .idea folder in your git repository.Sample .gitignore file can be like this

build/

.gradle/

*.iml
.idea/
src/main/gen/*

*~
*.swp

local.properties

*.keystore
*.keystore.password

Also you need to delete this folder from git repo. You can use below command

git rm -rf .idea/
git commit -m "deleting .idea, updated .gitignore"

Then try to merge

查看更多
登录 后发表回答