22

I've added the reflections framework to my android project. 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.

Here is the build.gradle of my app module:

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. The only thing Android Studio suggests is to add the reflections framework manually.

Android Studio Suggestion

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:

// 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()
    }
}
mvieghofer
  • 2,846
  • 4
  • 22
  • 51

1 Answers1

0

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 {
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
    }
    dependencies {
       // some external dependencies to be loaded (with needed one)
       classpath 'org.reflections:reflections:0.9.10'
    }
}
Igor K
  • 470
  • 6
  • 10
  • I've added the root build.gradle to my question. – mvieghofer May 29 '15 at 13:09
  • does this answer your questions? – mvieghofer May 29 '15 at 13:22
  • Yes, root project configuration gives necessary information. I was trying to emulate your situation. Currently look that 'org.reflections:reflections:0.9.10' isn't available in both added repositories, but I need to check it. – Igor K May 29 '15 at 13:43
  • No, it is available in Maven central – Igor K May 29 '15 at 13:45
  • Yes, gradle can download the dependecy. Also I see the library under "External Dependencies". However it is not added to the classpath for some reason. For all other libraries this works fine. – mvieghofer May 29 '15 at 13:49
  • With mentioned *buildscript* section in module build.gradle it is compiling and available for me. – Igor K May 29 '15 at 13:58