3

I have taken the following steps to migrate to Android Studio but right now I don't know what is wrong.

  1. In Eclipse I exported the gradle file. I did this because importing in Android Studio is not an option since it create a copy of the project and my project is under git.
  2. In Android Studio, I did "Open an existing Android Studio Project" and choose the gradle file.
  3. Since my original project used Maven for Maven dependencies, I add all of these to the gradle file.

Results: Most of the content in the build.gradle file is grayed out, telling me it cannot resolve symbol [name]. When I build, I have more than 100 errors, all of them related to dependencies not present (gradle not doing it's job). Also, I have been using gradle project in the last couple of days and the file is normally always asking to sync and it build the gradle file before building your project. In my case, nothing of that. It's like my project don't know he needs to use gradle or gradle is not configured the right way. Here is my gradle file and some screenshot to help you understand my problem. Any help is appreciated.

build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    }
}
apply plugin: 'com.android.application'

android {
    compileSdkVersion 15
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "XXXXXX"
        minSdkVersion 15
        targetSdkVersion 15

        testApplicationId "XXXXXXX"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }

    packagingOptions {
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            resources.srcDirs = ['src/main/java']
            aidl.srcDirs = ['src/main/java']
            renderscript.srcDirs = ['src/main/java']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}

dependencies {
    compile group: 'com.google.android', name: 'android', version: '4.1.1.4'  //provided
    compile group: 'org.springframework.android', name: 'spring-android-core', version: '1.0.1.RELEASE'
    compile group: 'commons-io', name: 'commons-io', version: '1.4'
    compile group: 'org.springframework.android', name: 'spring-android-rest-template', version: '1.0.1.RELEASE'
    compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'
    compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13'
    compile group: 'com.google.code.gson', name: 'gson', version: '2.3'
    compile group: 'org.java-websocket', name: 'Java-WebSocket', version: '1.3.0'
    compile group: 'joda-time', name: 'joda-time', version: '2.3'
    compile group: 'net.erdfelt.android', name: 'apk-parser', version: '1.0.2'
    compile group: 'org.apache.commons', name: 'commons-compress', version: '1.9'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.8'
    testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '1.6.1'
    testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: '1.6.1'
}

Screenshot of what it looks like in android studio:

androidstudio

No gradle subfolder in Android View? Is it normal?!enter image description here

Thank you!

EDIT I did like suggested in the comment. I seem to be a step further but I'm having the message: "Gradle project sync failed. Basic functionality will not work properly". In the message below, I have this. What can I do?

Error:Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'.
Possible causes for this unexpected error include:<ul><li>You are using JDK version 'java version "1.7.0_75"'. Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause class loading errors in Gradle.
Please update to a newer version (e.g. 1.7.0_67).
<a href="open.project.structure">Open JDK Settings</a></li><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
<a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
Jean-François Côté
  • 4,200
  • 11
  • 52
  • 88
  • 3
    "In Android Studio, I did "Open an existing Android Studio Project" and choose the gradle file" -- it is not an existing Android Studio project. Choose "Import project (Eclipse ADT, Gradle, etc.)" (if you are on Android Studio 1.1) or "Import non-Android Studio project" (if you are on an older Android Studio). It should detect your existing `build.gradle` file and will simply set up the Android Studio metadata, without a project copy. – CommonsWare Feb 24 '15 at 13:35
  • I add an edit to my question, if you can help! – Jean-François Côté Feb 24 '15 at 13:54
  • check this http://stackoverflow.com/questions/22791150/how-do-you-import-an-eclipse-project-into-android-studio-now –  Feb 24 '15 at 14:04
  • Finally, I had to change my gradle version and gradle plugin version. Will write a complete answer later when everything will be finished – Jean-François Côté Feb 24 '15 at 15:42

1 Answers1

2

If this can help anyone out there, here are the steps I followed to do the migration.

Exportation of the build.gradle file

  • Go in the Eclipse ADT project and click on File/Export. Choose the "Android" folder and the option "Generate Gradle build files".
  • Follow the wizard and only select the project you want to export.
  • You should have your original project with a new build.gradle file at the root.

Converting Maven dependencies to gradle

If you are using Maven dependencies, all of your dependencies looks like that:

<dependency>
    <groupId>org.springframework.android</groupId>
    <artifactId>spring-android-core</artifactId>
    <version>1.0.1.RELEASE</version>
</dependency>

You need to convert it to this format:

dependencies {
    compile group: 'com.google.android', name: 'android', version: '4.1.1.4'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

As you can see, if the dependency is needed to compile, put the keyword "compile" in front of it. If it's for the testing, use the keyword "testCompile". Keep that in a temporary file for the moment.

Installing Android Studio and configuring it Install Android Studio from this location: http://developer.android.com/sdk/index.html While it download/install, open your previously generated build.gradle file and change the following things. Replace

apply plugin: 'android'

With

apply plugin: 'com.android.application'

Be sure that your "buildScript" code-block looks like that

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    }
}

Finally, add the repositories and dependencies information outside of the android code block.

repositories {
    mavenCentral()
}
dependencies {
   compile 'com.google.android:android:4.1.1.4'
   ...
}

Now that Android Studio is installed, open it. Choose "Import Project (Eclipse ADT, Gradle, etc)" and navigate to the build.gradle file. Android Studio should now create all the metadata and file needed to run the project. If there is an error regarding the version of the tool on your compute, go back to the intro screen of Android Studio and choose "Configure/SDK Manager". Download whatever is necessary for your project to work. When in the project, Go in "File/Project Structure". In the project tab, be sure that the gradle version is 2.2.1 and that the android plugin is 1.1.0. The next step should be to create a configuration and run it on the USB device available or Emulator.

You are good to go!

Jean-François Côté
  • 4,200
  • 11
  • 52
  • 88