Gradle 返回包不存在 [英] Gradle returns package does not exists
问题描述
我正在尝试将 gson 库添加到我的 android 项目中(我正在使用 Andrdoid-studio 进行开发).
I'm trying to add the gson library to my android project (I'm devloping using the Andrdoid-studio).
为了添加库,我以这种方式更改了 AppProject/AppName/build.gradle 文件:
To add the library, I changed the AppProject/AppName/build.gradle file in this way:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile files('libs/android-support-v4.jar')
compile 'com.google.code.gson:gson:2.2.4'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 4
targetSdkVersion 16
}
}
在我尝试使用它之前它似乎有效.
It seems to work until I try to use it.
当我尝试包含它时:
import com.google.code.gson;
Gradle 抱怨肯定:
Gradle complains affirming:
Gradle: error: package com.google does not exist
推荐答案
接受的答案对我不起作用,但这样做了:
The accepted answer did not work for me, but this did:
- 下载 GSON JAR 文件并将其复制到应用程序项目中的/libs/文件夹中.
在项目的根级别打开 build.gradle 文件并编辑您的依赖项以包含新的 .jar 文件:
- Download the GSON JAR file and copy it to your /libs/ folder inside your application project.
Open the build.gradle file at the root level of your project and edit your dependencies to include the new .jar file:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
或者,您可以使用文件而不是文件树来指定一个或多个特定的 JAR 文件,例如:编译文件('libs/google-gson-1.7.1/gson-1.7.1.jar')
Optionally, you can specify one or more specific JAR files with files rather than fileTree, such as:
compile files('libs/google-gson-1.7.1/gson-1.7.1.jar')
这篇关于Gradle 返回包不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!