Android Studio无法解析导入的AAR模块中的符号

Ozz*_*zzy 12 android gradle showcaseview android-studio aar

类似问题中的所有答案都谈论了manderally编辑gradle文件.但我已经使用Android Studio导入AAR文件并检查了build.gradle文件,它们看起来都是正确的.

我的问题是:

进口失败

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

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

PS请忽略丢失的XML文件,就像我将它们复制到项目之前一样.

Gradle文件

ShowCaseView-5.0.0> build.gradle:

configurations.create("default")
artifacts.add("default", file('ShowCaseView-5.0.0.aar'))
Run Code Online (Sandbox Code Playgroud)

我的应用程序的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')
}
Run Code Online (Sandbox Code Playgroud)

Android Studio项目的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()
    }
}
Run Code Online (Sandbox Code Playgroud)

gradle设置文件settings.gradle:

include ':app', ':ShowCaseView-5.0.0'
Run Code Online (Sandbox Code Playgroud)

小智 2

您需要在项目的 build.gradle 文件中指定“ShowCaseView-5.0.0.aar”的位置。EG,ShowCaseView-5.0.0.aar 文件位于项目根目录下名为“libs”的文件夹中,更新 build.gradle 文件以添加以下内容

allprojects {
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)