最好在 Android Studio 项目的新模块或 libs 文件夹中添加 jar
It's better to add jar in new module or in libs folder in Android Studio project
在 Android Studio 上的项目应用程序中添加 jar 文件的最佳做法是什么?
例如我们将使用gson-2.3.1.jar
.
1) 含模块
并在您的主模块中添加 build.gradle :
dependencies {
...
compile project(":gson-2.3.1")
}
2) 带有 Libs 文件夹
- 将 Gson jar(在我的例子中,
gson-2.3.1.jar
)放入 libs
文件夹
- 并在您的主模块中添加 build.gradle :
compile files('libs/gson-2.3.1.jar')
或 compile fileTree(dir: 'libs', include: ['*.jar'])
我认为最好的方法是使用 maven 依赖
将此行添加到您的 build.gradle
dependencies {
compile 'com.google.code.gson:gson:2.3.1'
}
如果您想使用 jar,请将 jar 文件添加到 libs 文件夹中并使用:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
在 Android Studio 上的项目应用程序中添加 jar 文件的最佳做法是什么?
例如我们将使用gson-2.3.1.jar
.
1) 含模块
并在您的主模块中添加 build.gradle :
dependencies {
...
compile project(":gson-2.3.1")
}
2) 带有 Libs 文件夹
- 将 Gson jar(在我的例子中,
gson-2.3.1.jar
)放入libs
文件夹 - 并在您的主模块中添加 build.gradle :
compile files('libs/gson-2.3.1.jar')
或compile fileTree(dir: 'libs', include: ['*.jar'])
我认为最好的方法是使用 maven 依赖
将此行添加到您的 build.gradle
dependencies {
compile 'com.google.code.gson:gson:2.3.1'
}
如果您想使用 jar,请将 jar 文件添加到 libs 文件夹中并使用:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}