Android Studio 无法解析导入的 AAR 模块中的符号 [英] Android Studio cannot resolve symbols from imported AAR module

查看:35
本文介绍了Android Studio 无法解析导入的 AAR 模块中的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似问题中的所有答案都涉及手动编辑 gradle 文件.但是我已经使用 Android Studio 导入了 AAR 文件并检查了 build.gradle 文件,它们似乎都是正确的.

All of the answers in similar questions talk about manunally editting gradle files. But I've used Android Studio to import the AAR file and checked the build.gradle files and they all seem correct.

我的问题是:

我已导入 ShowCaseView v5.0.0 AAR,但是当我尝试导入 Tutorial.java 文件中的类时(您可以看到红色),Android Studio 无法识别这些类.Android Studio 识别的唯一导入是 com.github.amlcurran.showcaseview.R.

I've imported ShowCaseView v5.0.0 AAR but when I try to import the classes in my Tutorial.java file (you can see in red) Android Studio doesn't recognise the classes. The only import that Android Studio recognises is com.github.amlcurran.showcaseview.R.

我也尝试清理 &重建项目,并关闭 &重新打开 Android Studio 但它没有帮助.

I've also tried to clean & rebuild the project, and close & reopen Android Studio but it doesn't help.

附言请忽略我将它们复制到项目之前丢失的 XML 文件.

P.S. please ignore the missing XML files as that was before I copied them into the project.

ShowCaseView-5.0.0 >build.gradle:

ShowCaseView-5.0.0 > build.gradle:

configurations.create("default")
artifacts.add("default", file('ShowCaseView-5.0.0.aar'))

我的应用的 build.gradle:

My app's build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.giraffeweather"
        minSdkVersion 19
        targetSdkVersion 21
        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 'com.android.support:appcompat-v7:21.0.3'
    compile project(':ShowCaseView-5.0.0')
}

Android Studio 项目的 build.gradle:

The Android Studio project's build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

gradle 设置文件 settings.gradle:

The gradle settings file settings.gradle:

include ':app', ':ShowCaseView-5.0.0'

推荐答案

最近,我遇到了同样的问题.我有一个 AAR 可以导入到我的项目中.该库作为 AAR 分发.我通过将我的 AAR 文件放在 libs/ 文件夹中解决了它,并在我的应用程序模块的 gradle 中添加了以下行:

Recently, I encountered this very same issue. I had an AAR to import into my project. The library was distributed only as AAR. I resolved it by putting my AAR file inside libs/ folder and added the following line in my app module's gradle:

dependencies {
    ...
    compile files('libs/theFirstLib.aar')
}

您也可以像这样添加多个 AAR:

You can also add multiple AARs like so:

dependencies {
    ...
    compile files('libs/theFirstLib.aar', 'libs/theSecondLib.aar')
}

如果您使用的是 Gradle 3.0.0 或更高版本,您可能需要将 compile 替换为 implementation:

If you are using Gradle 3.0.0 or higher, you may need to substitue compile with implementation:

implementation files('libs/theFirstLib.aar')

工作就像一个魅力!

注意:导入 AAR 有时会导致另一个无法解析符号"错误,我已解决该错误 此处 当 Android Studio 和 Gradle 不同意时.

NOTE: Importing an AAR sometimes results to another "cannot resolve symbol" error, which I resolved here when Android Studio and Gradle don't agree.

这篇关于Android Studio 无法解析导入的 AAR 模块中的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆