I have the following problem. When I want to use a local jar in my Gradle dependencies.
If I just add:
compile files('libs/PushLinkAndroid-5.3.0.jar')
It doesn't work.
C:\Users\Kai\AndroidStudioProjects\ProjectA\app\src\main\java\de\xyz\xxx\projecta\BaseActivity.java:21: error: package com.pushlink.android does not exist import com.pushlink.android.PushLink;
Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. 4 errors
FAILED
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.
Try: Run with --stacktrace option to get the stack trace. Run with --info or >--debug option to get more log output.
BUILD FAILED
Total time: 6.543 secs
If i add the absolute path to the Jar, the project compiles and everything works finde:
compile files('C:/Users/Kai/AndroidStudioProjects/ProjectA/libs/PushLinkAndroid-5.3.0.jar')
Looks like there is something wrong with the Path but how could this be when the absolute Path works fine?
EDIT: Build.gradle
apply plugin: 'com.android.application'
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "de.xyz.kai.migraenebook"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    //compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile project(':volley')
    debugCompile 'im.dino:dbinspector:3.2.1@aar'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.android.support:recyclerview-v7:+'
    //compile files('C:/Users/Kai/AndroidStudioProjects/MigraeneBook/libs/PushLinkAndroid-5.3.0.jar')
    compile files('libs/PushLinkAndroid-5.3.0.jar')
    //compile files('libraries/PushLinkAndroid-5.3.0.jar')
    //compile files('C:/Users/Kai/AndroidStudioProjects/MigraeneBook/libraries/PushLinkAndroid-5.3.0.jar')
}
NOTE: I tried different folders, the PushLink.jar is in "libs" and "libraries". It doesn't make a difference which command I use or comment out - absolute path is working, relative not.
Try this, it would include all JARs in the local repository, so you wouldn't have to specify it every time:
dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
}
Also, you should know that when referencing a file via
files("relative/path/to/a.jar")
path is evaluated relative to the buildscript this snippet is in. So when your build.gradle file is located in /a/project/build.gradle, then the jar should be in /a/project/relative/path/to/a.jar. 
In a multiproject gradle build you can put the the jar in a folder relative to the root - project and reference it in all subprojects via
rootProject.files("relative/to/root/a.jar")
So take this to account and re-check if your gradle settings are correct.
If you call URL scheme path, you can use this example:
def path = "file://${projectDir}/ojdbc6.jar"
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With