简体   繁体   English

Gradle 编译依赖项未添加到类路径中

[英]Gradle compile dependency is not added to classpath

I've added the reflections framework to my android project.我已将反射框架添加到我的 android 项目中。 However it wasn't added to the classpath.但是它没有添加到类路径中。 Android Studio suggests that I need to add it manually, however I cannot start my app since gradle cannot build it. Android Studio 建议我需要手动添加它,但是我无法启动我的应用程序,因为 gradle 无法构建它。

Here is the build.gradle of my app module:这是我的应用程序模块的 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'
    }
}

When I build the app and try to use it I cannot import the Reflections class automatically.当我构建应用程序并尝试使用它时,我无法自动导入 Reflections 类。 The only thing Android Studio suggests is to add the reflections framework manually. Android Studio 唯一建议的是手动添加反射框架。

Android Studio 建议

After I've added it to the classpath manually I can import the class.在我手动将它添加到类路径后,我可以导入该类。 However when I'm trying to start it I get the following error:但是,当我尝试启动它时,出现以下错误:

tasks:compileReleaseJava
/.../TaskFactory.java:8: error: package org.reflections does not exist
import org.reflections.Reflections;

Does anyone know why this happens?有谁知道为什么会这样?

Edit: My project build.gradle looks like this:编辑:我的项目 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()
    }
}

In which repository your artifact is located?您的工件位于哪个存储库中? Is it root project or module project?它是根项目还是模块项目? Do you have buildscript section(s) in root/module project?您在根/模块项目中有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM