Skim through the screen shot that contains yellow exclamation mark. If one of them apply to you, hopefully this blog helps. The following is the sequence of error I was getting, and how i fixed it. Make sure you only follow the part mark as Solution.
1.
Problem: The project at <folder> is an Android ADT project. To Import this project into Android Studio, you first need to *export* it as Gradle project from ADT.
Solution: Fire up your ADT(Eclipse), import the project into ADT, and Export it to a Gradle export.
To import the file into eclipse and ex, click the following:
- File > Import >Existing Android Code
- select your project folder
- Don’t worry about any error warning in the code for now. Fix that when you successfully import the project into Android Studio
- To export, Click File, Export, and select “Generate gradle build files”
- Select the project you want to export
- for simplicity sake, just store it back to the same location prior to the import
- Finish
- Check to see if you have build.gradle file in the project directory. If you do, continue to the next step. If you don’t, try exporting again to the same directory
Now, keep in mind that some project require certain version of gradle. But you might be able to get by without upgrading. At the time of this writing I have upgraded my gradle version to 1.8. I don’t quire remember how I did it anymore. If you decide to upgrade, you also need to make sure that Android Studio know the location of the Gradle files you updated. Again, do some research. This is very annoying. To check your gradle version:
- If you are on a Mac: find an executable called gradle under a subfolder called bin. (This is the command line for mac: sudo find / -name gradle).
- If you are on a PC: find an executable called gradle.bat under a subfolder called bin.
- Run the executable, it should tell you what version it is
To check what Gradle version Android Studio is using, try importing the Android Project you just exported above. In android studio, click on File, Import, select the project you just exported above. You should see, the Gradle version.
2. You now have the build.gradle file, and you try importing again using the recommended option(Use default Gradle Wrapper). This is recommended by Google. You might have the following error:
Resolve Error: You are using an old unsupported version of Gradle. Please use version 1.8 or greater. Please point to a supported Gradle Version in the project’s Gradle Settings or in the project’s gradle wrapper(if applicable).
You might get different version of Gradle, depending on what is recognized by Android Studio.
your reaction: hmmm… okay??
So, maybe you try to use the local gradle distribution. and you get this error:
Resolve Error II: Project is using and old version of the Android Gradle Plug-in. The minimum supported version is 0.6.3. Please update the version of the dependency “com.android.tools.build:gradle” in your build. gradle files.
Again, you might get a different version number.
your reaction: What the…..??
Solution:
before you try and upgrade your gradle, try to see if the existing installation work first. Upgrading to the latest version is not a bad idea because from what I read all future android development will be gradle based.
- Open your project folder
- locate and open a file called “build.gradle”. If you can’t find it, scroll up and do step 1 above.
- Locate the following line in the file:
classpath ‘com.android.tools.build:gradle:0.5.+’
-
Resolve error II above indicate that the minimum supported version is 0.6.3. So, you have two options:
- Change the line I mention above to:
- classpath ‘com.android.tools.build:gradle:0.6.+
- Change the line I mentioned above to the gradle version your Android Studio is using:
-
classpath ‘com.android.tools.build:gradle:1.8.+
-
- Change the line I mention above to:
- Try importing your perject again using the recommended option(use default-gradle wrapper). If you get the similar Resolve Error (like the first one above), yell at your screen
- If that doesn’t work…. keep going
- If you have build.gradle file in your project, you should also have a folder called gradle at the same folder level as the build.gradle file
- Open the file located at ‘<your project folder>/gradle/wrapper/gradle-wrapper.properties‘
- locate the following line: distributionUrl=http\://services.gradle.org/distributions/gradle-1.6-bin.zip
- make sure the version number matches the gradle version recognized by Android Studio. In my case, i changed the bolded part to gradle-1.8-bin.zip
- Try importing again using the recommended version. If you get the following error:
- Resolve Error III:
Could not find any version that matches ‘com.android.tools.build:gradle:1.8.+. Required by:
:<your project>: unspecified
Your response: What are you…. freakin’ DIE HARD?? (like the movie Die Hard 1,2,3. remember?)
scream a bit louder at your screen, and throw in a hint of curse perhaps.
- If screaming still doesn’t work(if it does though, let me know):
- Do you know what other dependency that might be required? In my case, I was using Google Play Services and Google Location API. If you are using the same dependency make sure to include that in your build.gradle file, per Google’s instruction. You also need to remember to install the appropriate component in your SDK, which are(see the component mark installed on the right):
- I added the following compile statement to my dependency section in my build.gradle file(fonts in bold:
- buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath ‘com.android.tools.build:gradle:0.6.+’
}
}
apply plugin: ‘android’
dependencies {
compile fileTree(dir: ‘libs’, include: ‘*.jar’)
compile ‘com.android.support:appcompat-v7:+’
compile ‘com.google.android.gms:play-services:4.0.30’
}
- Try importing again using the recommended version. It should now import successfully
- Sync your project with your gradle
Things seems to compile fine after this. It’s a bit cumbersome. If you know a better way, please drop a comment.