Android studio novice tutorial (III) illustration of GitHub (ignore ignore rules)

Android studio integrates the function of uploading code to GitHub, so it is still very simple to use. Add an account in the settings and test, and then you can easily upload code to GitHub

If your project is created using Android studio, there is basically no problem with GitHub. The new project of Android studio comes with its own. Ignore file, which means that the ignore rule is used for uploading by default. The default is ignored

However, if your project was imported from eclipse before, you should pay attention here. According to the above operations, after creating a new project on GitHub, in the next synchronization options, you will see that all files in the project will be uploaded, including APK, IML, idea folder, gradle folder, etc.

Obviously, I don't need to upload files that change every time I compile (such as the APK file of debug). I need to upload files that I ignore. This is the role of the. Ignore file. In order to use the ignore rule, I copied the. Ignore file into the project, and then repeated the upload operation. The file did not work. Later, I explored it and found that this should be done:

1. Remove existing version control:

2. Close Android studio, enter the project folder and delete the. Git folder (if you don't see the folder, open the show hidden files option)

3. Copy a. Gitignore file to the root directory of the project (you can use as to create a new project, and the file will exist in the root directory, or use the plug-in. Gitignore to generate, and the plug-in will search in as). Attach the ignore rules I use:

4. Start as and add the project to version control

Repeat the previous operation, import into version control -- share project ongithub, and upload the code to GitHub using the ignore rule.

After each commit, you only need to right-click the project, click Add to add the version, and then click commit to upload

If there is no effect after changing the. Ignore file, clear the cache (it is recommended to commit and save before the operation)

##Import projects on GitHub

In addition to uploading our own code to GitHub for version control, we often need to import other people's excellent projects on GitHub for learning. When we create a new project in Android studio, we can easily import the project directly from GitHub

However, it doesn't make any difference.. The ideal is beautiful and the reality is cruel. Due to the problems of domestic network environment, projects importing GitHub in this way are likely to suffer from various gradle errors due to different gradle versions. Here are some quick and pleasant methods to import GitHub projects offline:

1. Download the project from GitHub, for example, chestnuts. The project name is test

2. Modify the first file in the root directory, test \ build.gradle

Change the place shown in the red box to your gradle version. If you don't know your gradle version, it's very simple to create a new project to see what its gradle version is. If you don't know what your current gradle version is, create a new project and view the version number in the gradle \ wrapper \ gradle-wrapper.properties folder under the project, just like the solution in 1

3. Modify the second file in the directory test \ gradle \ wrapper \ gradle-wrapper.properties

Change the red box to your gradle version

4. Modify the third file, located in the directory test \ app \ build.gradle, and modify the buildtoolsversion version number of the project. (it's an old saying. If you don't know the local buildtoosversion, create a new project to see.)

5. If there is a module in the project, remember to change the buildtoolsversion in build.gradle under module

In my case, you can normally import the project after modifying these files. Will never be bothered by gradle's problems again.

Download gradle offline

What if you have to use the specified gradle version because of some circumstances? The download of gradle in China is particularly slow, and it is easy to get stuck in gradle build running all the time. Here's how to install the gradle version offline:

1. Check the project \ gradle \ wrapper \ gradle-wrapper.properties file to get the version number of the gradle to be downloaded.

2. Go to gradle distributions to download the corresponding gradle version. After downloading, you will get a zip package. For example, the downloaded version is gradle-4.0-milestone-1-all.zip

3. Enter the folder, which is: user /. Gradle / wrapper / dists on Mac. On Windows: C: \ users \ administrator \. Gradle \ wrapper \ dists. This folder stores all the local gradle versions. Not surprisingly, you will see the gradle version folder being downloaded in the folder, that is, the gradle-4.0-milestone-1-all folder. After entering the folder, you will see another folder named a string similar to 6r4uqcc6ovnq6ac6s0txzcpc0.

4. Close the Android studio stuck in gradle build running, and copy the downloaded zip package directly to 6r4uqcc6ovnq6ac6s0txzcpc0 folder without extracting it. Restart Android studio and still prompt gradle build running, but we can see that the zip package just copied has been automatically decompressed. Wait a moment and gradle will be installed.

summary

The above is the introduction to Android studio for beginners (III) the tutorial diagram of GitHub (ignore ignore rules) introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>