简体   繁体   中英

Add AAR file as dependency to Intellj project

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?

PS Intellij can't process raw aar s, 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'
}

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 :)

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM