Needing to work in a collaborative android project would require some version control and project sharing. Most of the time this happens within a local network at the office. Git offers various methods to do this, being using github the most common one, but if you feel like you don’t want to share your work with the wold, or you don’t want to be paying for a private membership, or simply the online thing is not the right approach, or you like instant pulling and pushing, or you don’t want a headache messing with SSH and windows services, you could do this within your already working network, skipping the need of any service setup or online service registration.
- On the windows “server” machine, start a new android project using Android Studio (AS).
- Share the folder of the created project.
- Activate version control on your server machine created project by selecting on the menu VCS > Enable Version Control Integration
- On the dialog select Git
- Right click on the root folder inside the “Project” tree view pane and select Git > Add
- Right click again and select Git > Commit directory
- Enter a commit message.. something like “New Project” and by hovering the Commit button, select “Commit and Push”. (if you just select Commit then you neet to then push by going to VCS > Git > Push
- AS will ask you to define a remote:
- Name: Origin
- URL: file:////<your ip or network name>/<shared folder>/.git
- Create a new branch on server by clicking on Git: Master at the lower right corner of AS and selecting origin/master>Checkout as new local branch. Name this something like “server-branch”.
- Now for the Clients. If your client is a Mac, connect to the shared folder.
- Open AS and choose Check out project from Version Control >Git
- For the URL enter one of the options below.
- For windows: file:////<your ip or network name>/<shared folder>/.git
- For Mac: /Volumes/<shared folder>/.git
- Fill in the directory and the folder name and click clone. After this youll get a dialog asking to open… DO NOT OPEN IT!.. CLICK NO!. If you clicked yes by mistake, AS will mess up your project. Close AS, erase the folder and repeat the step 11.
- Now choose Open an existing Android Studio project in AS and browse for the project created on step 12.
- Click on Add root if prompted about an unregistered VCS root.
- Click on “Git: <some name>” on the lower right corner of AS and choose Origin-Master > Check out as new branch. Set a name like client1-branch
- Everything should be working now.. lets test the server commits.
- On the server, using server-branch, make some change like adding a comment somewhere and save.
- Still on server, now you have to commit and then push. To do both click on the green up arrow on icon menu, enter a commit message, and use the button commit> Commit and Push…
- Now sync the client by clicking the down blue arrow. choose Branch Defaut and Stash. The comment should appear.
- Lets test out the client:
- On client, write another comment somewhere and save.
- Still on client, now you have to commit and push. User the green up arrow, enter comment and choose commit and push.
- On server click blue down arrow.. Branch Defaut and Stash. The client change should appear.
- Final test, conflict resolving:
- enter a comment on client on some file and then and another on server, on the same file.
- On any machine, commit and push the change.
- On the other machine, commit and push the change.
- You’ll get a Push rejected message because of the conflict, click on the Merge button.
- On the the next dialog you can merge both files by clicking merge, and then inserting into the middle code pane, codes from left (local) and right (remote).
- You’ll probably get again the message of push rejected. You cant commit and push by using the green up arrow since nothing has changed but …
- If no changes has being made since the last commit, and you need to push again, youll need to go to VCS > Git > Push… (this skips commiting to the repo).
Leave a Reply