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

lyr7nygr  于 2022-12-02  发布在  Android
关注(0)|答案(1)|浏览(155)

我已经将reflections框架添加到我的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唯一建议的是手动添加Reflections框架。

在我手动将它添加到类路径后,我可以导入该类。但是,当我试图启动它时,我得到了以下错误:

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()
    }
}
epggiuax

epggiuax1#

您的工件位于哪个资源库中?是根项目还是模块项目?根/模块项目中是否有 buildscript 部分?

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
    }
    dependencies {
       // some external dependencies to be loaded (with needed one)
       classpath 'org.reflections:reflections:0.9.10'
    }
}

相关问题