0

So I'm having difficulty setting up an Android Studio project on GitHub.

Here's my issue:

I can't find a way to push the project on GitHub, then clone it and have it maintain it's project structure.

I've tried a few different things but In every step I simply created a new android project with a simple empty activity to test how GitHub/AndroidStudio would work.

  1. I tried using a .gitignore file from a old StackOverflow post : What should be in my .gitignore for an Android Studio project?

But then I noticed that when I clone my project, and select import existing project in android studio, it changes the entire project structure to the point that it won't even recognize that it's an app. It won't even run let alone see the manifest.

So now I tried another solution:

  1. I simply tried pushing the entire project directory to Github.
  2. I did git init inside the project directory, and tried to do a git remote add
  3. However when I do a git remote -v I can see my repo but a git branch -a or git branch won't show any branches other than my master branch.... EDIT: It seems in order to see the branches I NEED to use git clone. I wasn't encountering this problem earlier...

I can't seem to get anything to work XD

I've been trying to find an introductory guide, but it seems that appart from "Enter your GitHub info and push/pull away via the GUI!" is as far as it goes.

Any help would be great.

cicero866
  • 75
  • 5

1 Answers1

1

To copy a previously answered question:

Open the project you want to push in Android Studio.

Click VCS -> Enable version Control Integration -> Git

There doesn't seem to be a way to add a remote through the GUI. So open Git Bash in the root of the project and do git remote add

Now when you do VCS -> Commit changes -> Commit & Push you should see your remote and everything should work through the GUI.

  • That's where my problem starts. I can get it to push and pull, but when someone else clones my repo, and they select the import an existing android studio project option, it won't recreate my project with the same structure. What it does is create a project with the same name, with multiple modules and no option to run it. It dosent recognize that it's an android application inside the IDE, nor does it maintain its project structure. I could not find another post with that issue! – cicero866 Nov 06 '17 at 02:14
  • Do the instructions from [here](https://stackoverflow.com/a/34583232/6412243) help? Close the project, delete the project folder which is being created by the studio, re-open the IDE and create the project from the root folder again. – Trent Milton Nov 06 '17 at 02:41
  • choose: new project. import will look for the .project folder – Trent Milton Nov 06 '17 at 02:42
  • so how do I get the same project? Do other people have to drag and drop my .java files and manually create every module? what about the layout .xml files? Are those manually put it in to a folder? There's something I don't understand : How does someone clone a repo and not have to do all this manual work? – cicero866 Nov 06 '17 at 03:36
  • The issue is the project itself. Anyone that wants to use your code will need to setup a new project and choose the checkout directory as the root folder. This will then automatically have the project good to go. It's a bug in the IDE causing this. – Trent Milton Nov 06 '17 at 03:38
  • Sorry, I'm really new at this , so my other teammates need to create a blank project and then select the checkout directly as the root folder. What do you mean by selecting the checkout directly as the root folder? Do you mean to use the GitHub clone repo directory as the root folder for the project? and to create the new blank project inside that GitHub cloned directory? Do I then simply copy paste the folders over or? – cicero866 Nov 06 '17 at 03:48
  • From your friends perspective: (1) clone project to folder 'sample' (2) ensure android studio is closed (3) delete .project folder, (4) open android studio and create a new project in folder 'sample' (5) the project should work now. You can test this yourself just clone the project somewhere and try the previous steps – Trent Milton Nov 06 '17 at 03:54
  • Where would this .project folder be located? is it possible that it's not inside the project folder? I'm searching inside the project and see .gradle files as well as .java and .xml but no .project file(s). So I tried cloning the project, and cannot manage to locate the .project folder as it does not seem to exist. My .gitignore file contains : *.iml .gradle /local.properties /.idea/workspace.xml /.idea/libraries .DS_Store /build /captures .externalNativeBuild – cicero866 Nov 06 '17 at 04:20
  • I'll try something tonight and see if I can get a blank project pushed/pulled – Trent Milton Nov 06 '17 at 04:26
  • What version of android studio and type of project are you working on? – Trent Milton Nov 06 '17 at 04:28
  • I'm using : Android Studio 2.3.3 Build #AI-162.4069837, built on June 6, 2017 JRE: 1.8.0_112-release-b06 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o --- I've managed to get it to work! I created a new test branch, added a a phone or tablet project to it with an empty activity. I then cloned that branch in another location and opened it and it worked first try. I selected the "Use an existing project" option. It then recognized that the project was from Github and asked to set the VCS root. I did it all via command line since it just would not work with android studios. – cicero866 Nov 06 '17 at 04:55
  • Awesome, glad it worked in the end. So you're all sorted now? I guess you can answer your own question. – Trent Milton Nov 06 '17 at 04:57
  • I am sorted out, until the next challenge that is haha. I greatly appreciate the help though! It definitely helped me. It's weird that I don't seem to have a .project folder though. Anyways, Thank you again for the help Trent! – cicero866 Nov 06 '17 at 05:01