添加AAR文件作为依赖到Intellj项目



我使用Intellij IDEA 14.1.4制作一个Android项目后,从Android Studio移动了一段时间。我做了一些库(通过Android Studio),并希望在Intellij中使用它们。

但是,Intellij似乎只通过libs文件夹接受.jar文件,而Android Studio只创建.aar文件。

在Android Studio中,可以选择(在创建新模块时)将现有的.jar/.aar包导入到新模块中。这个选项似乎不在情报中。这个用户似乎认为Intellij支持这个,但是这些指令允许我创建一个全新的 Gradle模块。我想做的是使用现有的.aar文件。

我该怎么办呢?我应该搬回工作室这个项目,或者有一种方法让我使用这些.aar文件?

注:Intellij不能处理原始的aar s,句号。我试着把这个添加到我的gradle文件,但得到一个错误:

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

编辑这是我的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'
}

所以我在Intellj中看到了这个名为"Associate file…"的选项,并将aar与存档相关联。在重新编译时,我得到了这个错误

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

我想这只是Intellij的罐子。回到Android Studio,我想:)

首先,你也可以在Android Studio中创建。jar文件,看看这个但是。jar非常棒它能让你做比jar更多的事情

我没有使用过Intellij IDEA,但我假设你有一个gradle。项目中的构建文件?如果您的aar文件的名称是

my_lib_1.0.0.aar

,它在libs目录下,然后在gradle中尝试以下操作。构建文件:

compile(name:'my_lib_1.0.0', ext:'aar')

最新更新