Correct way to import a Google sample Android project to Android Studio-ThrowExceptions

Exception or error:

I want to play with the sample project at http://developer.android.com/training/location/receive-location-updates.html, LocationUpdates.zip, in Android Studio.

I have tried to use File > Import Project but end up with a load of errors:
enter image description here

There are many questions about importing an Eclipse project to Android Studio but following those didn’t help me.

How to solve:

Android Studio v1.0+ now offers easy importing of the sample projects via File->Import Sample.

Update: Since v1.3 (roughly), the option can now be found at File->New->Import sample. (Thanks to @johanvs)

###

None of the samples have instructions for working in Android Studio yet because it’s still in early-access preview, and we’re waiting until it’s more stable before we start reworking a lot of the documentation. You can use the project in Eclipse if you’d like to follow the directions closely.

If you want to use Android Studio, your best bet might be to create a new empty project from scratch in Android Studio and then move the code in by hand; there isn’t an import function that works well yet with the Gradle-based projects that Android Studio creates by default. If you do that, make sure you have Google Play Services and Goole Repository and Android Support Repository installed via your SDK manager, and include a dependency to Google Play Services not by adding it via a jar library in your libs folder, but by adding a Maven-style dependency to 'com.google.android.gms:play-services:3.1.36'. There are plenty of other questions on Stack Overflow that will get you going in the right direction; Gradle build fails looking for Google Play Services in Android Studio is a place to start.

###

Android Studio 1.5 now has it under:

File > New > Import Sample

Credit: @johanvs

Leave a Reply

Your email address will not be published. Required fields are marked *