4

I'm using Intellij IDEA 14.1.4 to make an Android project after moving from Android Studio a while back. I made some libraries (through Android Studio) and would like to use them in Intellij.

However, it seems that Intellij only accepts .jar files through the libs folder, and Android Studio only creates .aar files.

In Android Studio, one has the option (when creating a new module) to import an existing .jar/.aar package to be put into a new module. This option doesn't seem to be in intellij. This user seems to think that Intellij supports that, but those instructions allow me to create a brand new Gradle module. What I want to do is use an existing .aar file.

What should I go about doing? Should I move back to Studio for this project, or is there a way for me to use these .aar files?

P.S. Intellij can't process raw aars, period. I tried adding this to my gradle files, but got an error:

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

Edit Here's my build.gradle:

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

repositories {
    jcenter()
    flatDir() {
        dirs 'libs'
    }
}

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile ':mylib@aar'
    compile 'com.android.support:appcompat-v7:22.2.0'
}
2
  • can you also paste all your gradle.build file ? Aug 13, 2015 at 20:30
  • @2cupsOfTech I've also put in the suggestions from the website you linked, but now I get an error thrown on the preDexDebug phase of the gradle build
    – Jeeter
    Aug 13, 2015 at 20:41

2 Answers 2

2

So I saw this option in Intellj called "Associate file..." and associated the aar with an archive. Upon recompile I got this error

Warning:Project app: Only Jar-type local dependencies are supported. Cannot handle: mylib.aar

I guess it's only jars for Intellij. Back to Android Studio, I suppose :)

0

Well first of all you can create .jar files with Android Studio as well, see this but .aars are awesome and enable you to do more then what you could with a jar

I have not used Intellij IDEA but I assume you have a gradle.build file in your project? If the name of your aar file is

my_lib_1.0.0.aar

and its under the libs directory then try the following in your gradle.build file:

compile(name:'my_lib_1.0.0', ext:'aar')
6
  • I just get a Failed to resolve :my_lib_1.0.0: (I subbed my library name for the placeholder)
    – Jeeter
    Aug 13, 2015 at 20:06
  • when you right-click your .aar file do you have any option like 'add library to project' or 'add to build path' ? Aug 13, 2015 at 20:11
  • any particular reasons you are not using Android Studio ? My answer should give you no problems in Android Studio Aug 13, 2015 at 20:13
  • Nope. In fact, intellij actually spit this out at me just now: Warning:Project app: Only Jar-type local dependencies are supported. Cannot handle: mylib.aar
    – Jeeter
    Aug 13, 2015 at 20:16
  • 2
    I'm not using Android Studio because Intellij gives me a lot of flexibility with what I want to do, and now I've gotten too used to it to go back to AS :)
    – Jeeter
    Aug 13, 2015 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.