我之前发布过一个问题并在评论中提出这个问题,但没有收到回复。几周来我一直在努力寻找解决方案。
我正在尝试将 .jar 文件添加到我的程序中,以便在 Android 应用程序中上传文档。但是,它说 gradle 不成功,并且找不到属性"file"。
错误如下:
错误:(25, 0) 在 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decolated@41762346 上找不到属性"file"。
这是代码
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'
}
最佳答案
首先,Gradle 无法使用压缩的 jar 文件 - 您必须先解压缩 jar 文件。
当您包含该行时
compile fileTree(dir: 'libs', include: ['*.jar'])
这意味着任何以 .jar
结尾的文件只要位于 libs
目录中,都将作为依赖项包含在内。因此,无需使用最后一行(因为这些库已通过第一行包含在内)。
但是,如果您确实想包含另一个目录中的单个 jar 文件,则在 file
之后缺少括号:
compile file('libs/httpmime-4.0.jar')
关于java - 梯度错误: Could not find property file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29733874/