提问人:mvieghofer 提问时间:5/29/2015 最后编辑:mvieghofer 更新时间:8/2/2023 访问量:18508
Gradle 编译依赖项未添加到类路径中
Gradle compile dependency is not added to classpath
问:
我已将反射框架添加到我的 android 项目中。但是,它没有添加到类路径中。Android Studio 建议我需要手动添加它,但是我无法启动我的应用程序,因为 gradle 无法构建它。
这是我的应用模块的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "my.package"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':offlinetasks')
compile project(':tasks')
compile project(':models')
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
compile 'org.roboguice:roboguice:3.0.1'
provided 'org.roboguice:roboblender:3.0.1'
compile 'com.android.support:support-annotations:22.1.1'
compile('org.reflections:reflections:0.9.10') {
exclude module: 'xml-apis'
exclude module: 'annotations'
}
testCompile 'junit:junit:4.12'
testCompile('com.squareup.assertj:assertj-android:1.0.0') {
exclude module: 'support-annotations'
}
}
当我构建应用程序并尝试使用它时,我无法自动导入 Reflections 类。Android Studio 唯一建议的是手动添加反射框架。
手动将其添加到类路径后,我可以导入该类。但是,当我尝试启动它时,出现以下错误:
tasks:compileReleaseJava
/.../TaskFactory.java:8: error: package org.reflections does not exist
import org.reflections.Reflections;
有谁知道为什么会这样?
编辑:我的项目build.gradle看起来像这样:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
答:
0赞
Igor K
5/29/2015
#1
您的项目位于哪个存储库中?是根项目还是模块项目? 根/模块项目中有buildscript部分吗?
buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
// some external dependencies to be loaded (with needed one)
classpath 'org.reflections:reflections:0.9.10'
}
}
评论
0赞
mvieghofer
5/29/2015
我已将根build.gradle添加到我的问题中。
0赞
mvieghofer
5/29/2015
这回答了你的问题吗?
0赞
Igor K
5/29/2015
是的,根项目配置提供了必要的信息。我试图模仿你的情况。目前看起来“org.reflections:reflections:0.9.10”在两个添加的存储库中都不可用,但我需要检查它。
0赞
Igor K
5/29/2015
不,它在 Maven central 中可用
0赞
mvieghofer
5/29/2015
是的,gradle 可以下载依赖项。我还在“外部依赖项”下看到了该库。但是,由于某种原因,它不会添加到类路径中。对于所有其他库,这工作正常。
评论