[英]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()
}
}
您的工件位於哪個存儲庫中? 它是根項目還是模塊項目? 您在根/模塊項目中有buildscript部分嗎?
buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
// some external dependencies to be loaded (with needed one)
classpath 'org.reflections:reflections:0.9.10'
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.