1

I'm trying to migrate an Android project developed with Eclipse ADT to Android Studio. I've already read the instructions mentioned here http://developer.android.com/sdk/installing/migrate.html and it works fine!

Gradle builds a new android project but I need to "hardcode"(modify manually) the gradle.build file in order to make the libraries work properly. All the other stuffs work fine.

This is the ADT project

MyApplication/

-->assets/

-->libs/

---->android-support-v7-appcompat.jar

---->android-support-design.jar

-->res/

-->src/

-->AndroidManifest.xml

-->project.properties

The first library is automatically recognized by Gradle, and it is substituted with

compile 'com.android.support:appcompat-v7:23.2.1'

in the grandle.build file. Instead the "android-support-design.jar" is not recognized and it is added to the gradle.build as

compile file('libs/android-support-design.jar')

but it is not working at all.

At the moment, I need to manually substitute the

compile file('libs/android-support-design.jar')

with

compile 'com.android.support:design:23.2.1'

In order to make the build work effectively.

Is there any way to force Gradle to recognize that library and automatically import it? Can I download a version of that library that is recognized, anywhere? At the moment I'm taking both libraries from

<sdk>/extras/android/support/

Thank you all.

1 Answers1

0

I need to "hardcode" the gradle.build file in order to make the libraries work properly

I'm not sure what you mean by "recognize" and "hardcode", but if you just have jar files that you can't use the compile line like for the support libraries, then you can use this line, which will take any jar file in the libs/ folder and compile it. You don't need to hard-code any of those.

compile fileTree(dir: 'libs', include: ['*.jar'])

Otherwise, you should already have these.

compile "com.android.support:appcompat-v7:23.2.1"
compile "com.android.support:design:23.2.1"

But, if you want to get fancy with Gradle, you can do something like this to keep all the support libraries the same version.

ext {
    supportLibVersion = '23.2.1'  // variable that can be referenced to keep support libs consistent
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • When I import the ADT project into Android Studio, Gradle automatically recognize that the libs folder contains a library (android-support-v7-appcompat.jar) that can be replaced with an import in the gradle build file (compile "com.android.support:appcompat-v7:23.2.1") and this is exactly what I want to happen. The problem is that Gradle does not automatically recognize the library "android-support-design.jar" and i need to put in the gradle build file "compile "com.android.support:design:23.2.1" by my self. It is important for me that this library is imported automatically as the previous one – Aldo Pintus Mar 29 '16 at 07:44
  • Then I would submit a feature request to the Android Studio people. There isn't just some setting in Android Studio that'll magically find all possible JAR dependencies and convert them to Gradle. – OneCricketeer Mar 29 '16 at 11:39