I had posted a previous question and ask this in the comments, but received no response. I have been struggling with finding a solution to this for a couple weeks now.
I am trying to add .jar files to my program for uploading a document in an android app. However, it says gradle was unsuccessful and it could not find property 'file'.
Here is the error:
Error:(25, 0) Could not find property 'file' on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@41762346.
Here is the code
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.ashleygreen.healthcareapp"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile file 'libs/httpclient-4.2.2.jar.zip'
compile file 'libs/httpmime-4.0.jar.zip'
}
Firstly, Gradle cannot work with zipped jar files - you'll have to unzip the jar files first.
When you include the line
compile fileTree(dir: 'libs', include: ['*.jar'])
This means that any file ending in .jar
will be included as a dependency as long as it is in the libs
directory. Therefore there is no need to use either of the last lines (as those libraries are already included via the first line).
However, if you did want to include a single jar file from another directory, you're missing the parentheses after file
:
compile file('libs/httpmime-4.0.jar')