Upload the code to Github

Android Studio has built in the ability to upload code to Github, so it’s easy to use. Add your account in Settings and test it out. Then you can easily upload your code to Github

Copy the code

However, if your project was imported from Eclipse before, you should be aware of this. After you create a new project on Github, in the following sync option, you will see that all the files in the project will be uploaded, including apK, IML, IDEA folder, gradle folder, etc.

  1. Remove an existing version control:

  2. Close Android Studio, go to the project folder and delete the.git folder (if you don’t see it turn on the show hidden files option).

  3. Make a copy of the.gitignore file to the project root directory (you can create a new project using AS, which has the file in its root directory, or use the plugin. Gitignore, which has the file when searching in AS) and attach the ignore rule I used:

# Gradle files
# Intellij project files
# Built application files
# Files for the Dalvik VM
# Java class files
# Eclipse project files
# Generated files
# generated files
# Local configuration file (sdk path, etc)
# Log Files
Copy the code
  1. Start AS and add the project to version control

Again, import into Version Control–share Project onGithub to upload code to Github using the ignore rule.

After each commit, just right-click the project, click Add to add the version, and then click Commit to upload

If the. Ignore file has no effect, clear the cache (commit is recommended before the operation)

Git rm -r --cached. Git add. Git commit -m'update git.ignore'/ / submitCopy the code

## Import the project on Github

In addition to uploading our own code to Github for easy version control, we often need to import other people’s excellent projects on Github for learning. When creating a new project in Android Studio, we can easily import the project directly from Github

But it is of no damn use Ideal is beautiful, reality is cruel. Gradle versions of your github project are not compatible with gradle versions. This is a quick and enjoyable way to import a github project offline.

  1. Download the project from Github, for example, called Test

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

Change the area shown in the red box to your Gradle version. If you don’t know your Gradle version, simply create a new project and see what the Gradle version is. If you do not know your current gradle version, create a new project and go to gradle\wrapper\gradle-wrapper.properties to check the version number

  1. Modify the second file in a directoryTest\gradle\wrapper\gradle-wrapper.properties

Change the area shown in the red box to your Gradle version

  1. Modify the third file, located in the directory Test\app\build.gradle, and change the buildToolsVersion version number of the project. (Cliche: If you don’t know the native buildToosVersion, create a new project.)

  2. If you have a Module in your project, buildToolsVersion in build.gradle under Module should also be changed

In my case, these files are usually modified and the project can be imported normally. No more gradle problems.

Download Gradle offline

What if, for some reason, you must use the specified gradle version? Gradle download is very slow in China. It is easy to get stuck in Gradle Build Running. Here is how to install gradle version offline:

  1. Look at the project \gradle\wrapper\gradle-wrapper.properties file to get the gradle version number you want to download.

  2. Go to Gradle Review to download the Gradle version and get a zip package. For example, download gradle-4.0-milestone-1-all.zip

  3. Enter the folder, Mac is: user/gradle/wrapper/dists. On Windows it is: C:\Users\Administrator\.gradle\wrapper\dists. This folder stores all gradle versions locally. Gradle-4.0-milestone -1-all, gradle-4.0-milestone-1-all, gradle-4.0-milestone-1-all Name is a string of similar to 6 r4uqcc6ovnq6ac6s0txzcpc0 string.

  4. Close the card in the Gradle Build Running Android Studio, and copy the downloaded zip not unpack directly to the 6 r4uqcc6ovnq6ac6s0txzcpc0 folder. When you restart Android Studio, Gradle will still be prompted to Build Running, but you can see that the zip package you just copied into has been automatically decompressed. After a while, Gradle will be installed.

The above.