1

I have this in my gradle file for an android studio application...`

apply plugin: 'com.android.application'

def ftcLibLocation = "../../../android/ftc_lib/ftc_app/FtcRobotController/libs"

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "teamXXXX.testbot"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile files('${ftcLibLocation}/FtcRobotController-debug.jar')
    compile files('${ftcLibLocation}/FtcCommon-release.jar')
    compile files('${ftcLibLocation}/ModernRobotics-release.jar')
    compile files('${ftcLibLocation}/RobotCore-release.jar')
    compile files('${ftcLibLocation}/WirelessP2p-release.jar')
    compile files('${ftcLibLocation}/Analytics-release.jar')
    compile files('${ftcLibLocation}/d2xx.jar')
}

and yet when I compile the program gradle/android studio complains that it can't find packages that I know are located in those jars.

Error:(3, 47) error: package com.qualcomm.robotcore.eventloop.opmode does not exist

That package is located in ${ftcLibLocation}/RobotCore-release.jar why isn't the build locating it?

2 Answers2

1

Create a libs folder (adjacent to the src directory) and include all your jars in that directory.

Then in your build.gradle file, use this :

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}

You don't have to compile every dependency separately.

axay
  • 1,657
  • 2
  • 18
  • 22
  • But the whole point is that all of those jars live off in a different git repo and I don't want to be forced into copying them into a libs directory in an artificial manner. I want to have a number of different projects that all reference the same set of jars. Isn't it rather restrictive if I'm forced to copy all of the jars into a libs directory in each project? –  Jun 26 '15 at 03:29
0

There are several reasons that this could happen. Probably the most useful tool for starting is the gradle dependencies command. It will tell you things about your dependencies that may surprise you. More about it here:

What is the Gradle artifact dependency graph command?

  1. Your path variable ftcLibLocation is not set properly in the environment in which gradle is running. Usually gradle will display the full path during the build or you can display or log it:

https://discuss.gradle.org/t/accessing-the-buildscript-classpath/5297

  1. The jar file has been changed, but gradle cache does not know that. I run into this sometimes and I have to go to:

    {userhome}\.gradle\.caches

    and in there you will find a lot of folders that have cached references to libraries. Those libraries are usually remote, but I have seen problems with local libs being cached. You can delete this directory - or find the part that has the problem. Deleting will cause all your dependencies to download again, and may take awhile.

  2. Another potential problem is Android Studio and gradle. Sometimes the plugin does not update properly. Reboot Android Studio and try again.

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36