söndag 12 oktober 2014

Android : Importing (older) Android gradle projects in IntelliJ IDEA

This is a simple tutorial, i'll start with an Android sample, download 'SlidingTabsBasic' from http://developer.android.com/downloads/samples/SlidingTabsBasic.zip.

Projects built with an older android gradle plugin and build-tools needs to be updated.


First off, start IntelliJ IDEA and select 'Import Project', select the directory where you've unzipped the project.

IDEA auto-selects it as a 'Gradle' project as in the following screenshot.


We'll go with the default settings, and click 'Finish'. Depending on what packages you've installed from the Android SDK you've might get a first error.




The build tools version specified in SlidingTabsBasicSample\build.gradle isn't installed on my computer, i'm currently using 19.1, but it depends, open up your Android SDK manager and see which one you've installed.

File build.gradle updated with a newer build tools version, click open the 'Gradle' tab and hit refresh. Next error comes along, these samples were created with an older Android plugin for Gradle.

Error: 'The project is using an unsupported version of the Android Gradle plug-in (0.9.2)'

In the same file update the line classpath 'com.android.tools.build:gradle:0.9.+' to a newer plugin version, as of this writing i'll use 'com.android.tools.build:gradle:0.12.2'. Hit refresh again.

Finally the project builds sucessfully, Now we'll create the 'Run/Debug Configurations'.
Select Run -> Edit Configurations


IDEA should pick up and select the default settings, select a emulator image, and run the project!
Hopefully this will help out when trying out samples made with an older version of the build-tools and the android gradle plugin.




5 kommentarer:

  1. I am using Android Studio (0.8.9).
    That is very close to my experience.
    I get the same first error and the same second error.
    But there is nothing in (SlidingTabsBasicSample\build.gradle) <--- that is empty.
    Do you know why?

    Please show a screenshot of your Android SDK Manager.

    Thanks.

    SvaraRadera
    Svar
    1. Sorry, not using Android Studio. download the sample and overwrite the SlidingTabsBasicSample\build.gradle outside the IDE ? Shouldnt be empty, are you sure you're inside the correct module ? The root build.gradle file is empty.

      Radera
    2. Den här kommentaren har tagits bort av skribenten.

      Radera
    3. "Den här kommentaren har tagits bort av skribenten"

      Not intentionally...

      Radera