【发布时间】:2015-05-18 20:08:16
【问题描述】:
类似问题中的所有答案都涉及手动编辑 gradle 文件。但我使用 Android Studio 导入了 AAR 文件并检查了 build.gradle 文件,它们看起来都是正确的。
我的问题是这样的:
我已经导入 ShowCaseView v5.0.0 AAR,但是当我尝试在我的 Tutorial.java 文件中导入类时(你可以看到红色)Android Studio 无法识别这些类。 Android Studio 识别的唯一导入是com.github.amlcurran.showcaseview.R。
我也尝试清理和重建项目,关闭并重新打开 Android Studio,但没有帮助。
附:请忽略丢失的 XML 文件,因为在我将它们复制到项目之前。
Gradle 文件
ShowCaseView-5.0.0 > build.gradle:
configurations.create("default")
artifacts.add("default", file('ShowCaseView-5.0.0.aar'))
我的应用的 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:
// 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:
include ':app', ':ShowCaseView-5.0.0'
【问题讨论】:
-
“检查了 build.gradle 文件,它们看起来都是正确的”——我们无法帮助您确认这一点,因为您尚未发布
build.gradle(在这种情况下,显然是settings.gradle) 文件。为什么不直接将 AAR 引用为工件,如 the library's documentation 所示? -
我已经针对我的 build.gradle 和 settings.gradle 文件检查了类似问题的答案,并且与这些答案中的答案相同。事实上,由于 Android Studio 为我创建了它们,我认为它不会有任何问题。我不知道 gradle 或如何使用这个
compile 'com.github.amlcurran.showcaseview:library:5.0.0'命令 - 我认为这就是你所指的。我刚刚从 Eclipse ADT 切换到 Android Studio,这是我第一次看到“gradle”这个词。此外,我还想知道为什么如果我导入 AAR,我不能像 JAR 一样引用类文件。 -
“我已经根据我的 build.gradle 和 settings.gradle 文件检查了类似问题的答案,并且与那些答案相同”——这并不意味着我们可以帮助您他们,因为我们看不到他们。 “这是我第一次看到“gradle”这个词”——它在the Android Studio overview 的第一个项目符号中。 including dependencies 上还有文档,例如您要查找的库。
-
是的,关键是我不想要关于 gradle 文件及其内容的答案,因为它们都没有帮助我:-)。感谢您的链接,我会看看。 @CommonsWare
-
所以第一个链接只是告诉我做我所做的,文件>导入模块。我下载了库并从本地文件系统导入它,与从在线资源导入它应该没有什么不同。第二个链接描述了我的 gradle 文件中已有的内容,因为我使用了 File > Import Module 向导。 @CommonsWare
标签: android android-studio gradle showcaseview aar