Android Studio, Git, Bitbucket, and SourceTree 使用

来源:互联网 发布:vm mac os补丁 编辑:程序博客网 时间:2024/04/29 19:01

I’m currently working on developing my skills as an Android programmer, and certainly have quite a bit to learn. I’ve start going through courses on Udemy to gain a foundation that I can build upon. During these courses I have developed some working applications for my Android devices and am progressing fairly well, but I’ll soon be starting my own projects and developing my own applications from scratch.

我正在致力于开发我的技能作为一个Android程序员,学习,当然也有不少。我开始通过Udemy获得基础课程,我可以建立。在这些课程我已经开发出一些申请我的Android设备和工作进展相当不错,但我很快就会开始自己的项目,从头开始开发自己的应用程序。

I realized that I needed a system that will allow me to develop my application across my desktop PC as well as my laptop. My first instinct was to use an application I was already familiar with, Dropbox, and create a shared project workspace that I could access from anywhere. I found out quickly that this was not going to work. The Dropbox system is great, but it just isn’t that great for code development. There seem to be problems with how the reading/writing work with the syncing functionality, and at one point I ran into a severely corrupted project file. Now, because Dropbox tracks file change history, I simply went back and restored a working version of the file.

A quick search confirmed my suspicion about using Dropbox, and directed me toward the use of Git and a remote repository system. Git is a revision control system that keeps track of the changes made to all project files that are included in the repository. With Git, branches can be made from the primary development files, and merged back in once complete. This allows for multiple users to work on the same project with ease. More importantly for me, however, is the ability to push and pull the project information from repositories hosted on-line; allowing me to functionally work across multiple systems.

Android Studio has, in my opinion, great Git integration, and most specifically integration with Github. I created a Github account and found that I have to pay to use their private repository feature. I’m not particularly worried about people finding/stealing my code, but for me I wanted the peace of mind of having the ability to work privately within my repository.

Instead, I turned to Bitbucket for my repository needs. After doing some experimentation, and quite a bit of reading, I have learned how to set up and use Android Studio with Bitbucket, SourceTree, and Git. Following is a quick overview of what it takes to get started using Android Studio with Bitbucket, and getting VCS off the ground for your Android development projects.

 Step 1: Android Studio, Git, Bitbucket, SourceTree.

Under the assumption that you’ve already got Android Studio installed, check to ensure you have Git installed on your computer and linked to Android Studio.

Look in Settings –> Version Control –> Git. Direct the Path to Git executable toward your Git installation git.exe file.

Android Studio Git Settings

You can find the installation instruction for Git here.

Next we need a Bitbucket account. Head here for the sign up page!

In the tutorial repository provided by Bitbucket it will direct you to download SourceTree, which you can download here.

Once you have everything downloaded, installed, and signed up for move on to creation of a new repository.

Step 2: Creating a repository.

After logging in to the Bitbucket website, at the top of the page click on create, and click on Create repository.

Bitbucket Create Repository

Next, type in the name and a quick description of your project, and hit the Create repository button.

Bitbucket Create New Repository

You’ll see a screen that says Repository setup, but just hold tight, we’ll get to that in a moment. Move on to creating a new project in Android Studio.

Step 3: Creating a new project in Android Studio.

Now we are going to create the project we want to work on in Android Studio. If you already have a project you want to use with Git, you can skip the creation step.

Set up your project in Android Studio, I’m just going to run through the setup using the defaults provided.

Android Studio New Project

Once you have your project created, in the top menu click on VCS and then click on Enable Version Control Integration

Android Studio Enable VCS

Select Git for VCS option.

Android Studio Select Git

At the bottom you will now have access to the Version Control menu, opening that you will notice that it is telling you that you’ve got unversioned files.

Android Studio Unversioned Files

Open up the project level navigation viewer (default will likely be Android) right click your project files, drop down to the Git sub menu and click Add. This will add all of the relevant project files to your Git system.

Android Studio Add Files

Upon completion your files will go from red to green.

Android Studio Red To Green

Now you’re ready to link your project into SourceTree!

Step 4: Linking the project to SourceTree.

Open SourceTree and click on Clone / New

SourceTree Clone/New

And then click on Add Working Copy. This will allow you to add the project/repository you just made to SourceTree for tracking. Locate your project path, and click add.

SourceTree Add Working Copy

You now have a connection between your project file and SourceTree.

Next, we will do our initial commit, and connect our project to Bitbucket.

Step 5: Initial commit, and pushing to Bitbucket repository.

Back in Android Studio hit the VCS menu again and go down to Commit Changes, or press ctrl + k

Android Studio Initial Commit

This will bring up the Commit Menu for our initial commit and push.

Android Studio Commit Menu

At the bottom, hover over the Commit button to get the drop down, what we are looking for right now is Commit and Push.

Android Studio Commit and Push

Click that button and Studio will perform the commit, and bring up the Push menu.

Android Studio Define Remote

Click on Define remote, it will bring up the menu allowing you to specify the URL of the remote repository.

Android Studio Define Remote

Going back to Bitbucket, we can grab the URL from the setup page…

Bitbucket Repository URL

Copy your link into the URL prompt in Android Studio. Then click OK.

Android Studio Bitbucket Remote

You should now be able to click Push and push your initial commit to the remote repository.

Android Studio Push Menu

Check the Event Log in Android Studio to ensure the push was successful…

Android Studio Push Success

Refresh your Bitbucket page to ensure the push showed up correctly in the repository.

Bitbucket Push Success

And look at your SourceTree to confirm that a remote master branch has been created and we are tracking our history.

SourceTree Push Success

Now you can track new commits, control checkouts, branches, mergers etc. graphically using SourceTree. You can also control the fetches from the repository, pulls, and commits.

SourceTree Track Flow

Using both Android Studio and SourceTree is a good way to keep track of the project status and flow, and utilize the powerful tools Git allows you to use.

Android Studio Merge Menu

SourceTree Merge Flow

 

Step 6: Linking to another computer.

Of course, my ultimate goal was to develop across multiple systems, and so if that is your goal as well the next step is to start up Android Studio on your second computer.

From the startup screen you want to start a new project by checking out from version control.

Checkout From VCS

And select Git to bring up the following screen.

Import From URL

Here you must take the URL from your Bitbucket Repository and past it into the URL section. Ensure that the parent directory is where you want your project to land. For the Directory Name, I find it helps to ensure you type the same name as the Directory Name on your original PC. Once everything is in place, click the clone button. The next menu will ask if you want to open the project. Click ‘yes’.

I now suggest adding your project folder to the SourceTree list on this computer.

I’ve made my first Laptop commit, and pushed it to the repository. Everything is synced up in SourceTree and working in Android Studio!

Laptop Commit

That’s about it. There is a lot more that can be done using these systems. There are other ways to do all of this, but this is how I do it right now, and I hope this guide can help someone else set up Android Studio across multiple systems!

CategoriesDaily DriftTagsAndroid Programming, Android Studio, Bitbucket, Daily Drift, Git, SourceTree, Tutorial
Post navigation
0 0
原创粉丝点击