Easing the process of importing external Android Studio projects

Dawit Abraham
3 min readOct 28, 2019

--

Importing Android Projects Can Be Difficult-ish

No, not the importing part!

But have you ever tried to import a project and it took 30 minutes to download the gradle distribution and all the API platforms and libraries specified by the project? Especially for someone in a low internet bandwidth country like Ethiopia with a speed of 125 KBps (which is still very expensive), it could be a very painful experience.

If you don’t find this to be a problem, please stop reading now and proceed to a short prayer of gratitude for all the things you take for granted. Thank you!

And if you are trying to learn by looking at other’s code, you would want to clone repos and get them running on your machine as fast as possible.

If you don’t care much about maintaining the state of the project (and you only care about looking at and running the code), you can take the following steps to reduce the time it takes to import the project and get things going.

Step 1: Open a project that you have run recently.

It can be any project. If you have run it recently, it means you have already downloaded all the API platforms and the gradle distribution it requires to build.

For example, I opened the following the project which I had run recently.

The app module build.gradle file is specifying the following

compileSdkVersion 28defaultConfig {
...
targetSdkVersion 28...
}
  • Take note of the compileSdkVersion and targetSdkVersion
  • It also has androidx dependecies
projectDir/app/build.gradle

The project level build.gradle file is specifying the following

dependencies {
...
classpath 'com.android.tools.build:gradle:3.4.2'
...
}
  • Take note of the version of the gradle build tool (3.4.2)
projectDir/build.gradle

And finally, the gradle-wrapper.properties file

#Thu Oct 10 11:30:18 EAT 2019...distributionUrl=https\://services.gradle.org/distributions/gradle-
5.1.1-all.zip
  • Notice the version of the gradle version in distributionUrl (5.1.1-all.zip)
projectDir/gradle/wrapper/gradle-wrapper.properties

Step 2: Replace the gradle and other library versions of the project you want to import with ones from the previous project

Next, you’ll have to replace some or all of the versions specified in the project you’re about to import by the ones you have already installed on your device.

  • Copy the two files (gradle-wrapper.properties and gradle-wrapper.jar) from the previous project’s /gradle/wrapper directory into the second project’s same /gradle/wrapper directory
  • Open the project level build.gradle file and change the classpath variable for the gradle build tool to match the one you found in the previous project
dependencies {
...
classpath 'com.android.tools.build:gradle:3.4.2'
...
}
  • Then go to the app level build.gradle file and change the compile and target sdk versions to match what you saw in the previous project
compileSdkVersion 28defaultConfig {
...
targetSdkVersion 28...
}
  • You can then go ahead and replace the library dependencies’ versions to match the one you saw in the previous project. (Or you may choose to update to the latest versions)

Downloading these libraries takes less time than downloading the gradle distribution zip file. So do experiment with what works best for you when making the changes to the project you want to import.

I hope this can make it easier to learn from other’s code by reducing the time it takes to import projects and get them running!

--

--

Dawit Abraham

CEO, Android Application Engineer, Game Developer, Pan African, and Black Lion