"libs" 如何在 gradle android 项目中创建和维护?
How is "libs" created and maintained in a gradle android project?
我目前没有为我的第三方依赖项使用 "libs" folder(它们似乎自动添加到 build/intermediates/pre-dexed/)但注意到它可能有助于静态代码分析,所以我想将其添加到项目中。
注意:我使用的是 maven 依赖项。
我的问题:是否有人使用自定义脚本生成此文件夹?我几乎不认为这是一次生成,然后在有更新版本可用时手动维护。
请赐教!
使用 Android Studio 和 Gradle,不需要 使用 libs 文件夹(旧的 .jar 库除外)。
事实上,您可以 开发 Android 应用程序而无需 Android Studio,因为在您的 build.gradle 中已经有一个 apply plugin: 'com.android.application'
Gralde 通过 gradle 依赖项使用 Maven 或 jCenter 导入库。 Gradle 和 Android Gradle 插件将 自动下载 您在 build/ 文件夹中所说的库。它不是静态的,可以使用 Android Studio 上的 Clean projet
进行清理。此外,Android Studio 会在 build.gradle 中自动提供新的库版本时添加警告。
不要错过用于导入 .jar 库的旧 libs
文件夹
I currently am not using the "libs" folder for my third party dependencies (it seems they are added automatically to build/intermediates/pre-dexed/) but noticed that it may help static code analysis so I would like to add it to the project. Note: I'm using maven dependencies.
不要将 libs
文件夹与 build/intermediates/pre-dexed/
文件夹混淆。
目前,Android 的 gradle 插件管理构建过程并创建这些 "internal" 和中间文件夹。
My question: Are people using custom scripts to generate this folder?
I hardly think that this is generated once
您不必创建此文件夹。 Android 的 Gradle 插件为您管理它。当您使用 运行 一个 gradlew clean
命令时,它也会被删除并重新创建。
and then manually maintained when there is a newer version available.
没有。您的依赖项在 build.gradle
文件中定义。
当您定义新版本时,Gradle 会下载新的依赖项并更新中间文件夹。
您可以通过多种方式定义依赖项:
dependencies{
//You can create a folder and put jar files inside. You can use your favorite name, usually it is libs.
compile fileTree(dir: 'libs', include: ['*.jar'])
//The support libraries dependencies are in a local maven managed by SDK
compile 'com.android.support:appcompat-v7:23.0.0'
// A Maven dependency
compile 'com.squareup.picasso:picasso:2.5.2'
//A local library
compile project(':mylibrary')
//An aar file. It requires to define a repository.
//repositories{
// flatDir{
// dirs 'libs'
// }
//}
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}
我目前没有为我的第三方依赖项使用 "libs" folder(它们似乎自动添加到 build/intermediates/pre-dexed/)但注意到它可能有助于静态代码分析,所以我想将其添加到项目中。 注意:我使用的是 maven 依赖项。
我的问题:是否有人使用自定义脚本生成此文件夹?我几乎不认为这是一次生成,然后在有更新版本可用时手动维护。
请赐教!
使用 Android Studio 和 Gradle,不需要 使用 libs 文件夹(旧的 .jar 库除外)。
事实上,您可以 开发 Android 应用程序而无需 Android Studio,因为在您的 build.gradle 中已经有一个 apply plugin: 'com.android.application'
Gralde 通过 gradle 依赖项使用 Maven 或 jCenter 导入库。 Gradle 和 Android Gradle 插件将 自动下载 您在 build/ 文件夹中所说的库。它不是静态的,可以使用 Android Studio 上的 Clean projet
进行清理。此外,Android Studio 会在 build.gradle 中自动提供新的库版本时添加警告。
不要错过用于导入 .jar 库的旧 libs
文件夹
I currently am not using the "libs" folder for my third party dependencies (it seems they are added automatically to build/intermediates/pre-dexed/) but noticed that it may help static code analysis so I would like to add it to the project. Note: I'm using maven dependencies.
不要将 libs
文件夹与 build/intermediates/pre-dexed/
文件夹混淆。
目前,Android 的 gradle 插件管理构建过程并创建这些 "internal" 和中间文件夹。
My question: Are people using custom scripts to generate this folder? I hardly think that this is generated once
您不必创建此文件夹。 Android 的 Gradle 插件为您管理它。当您使用 运行 一个 gradlew clean
命令时,它也会被删除并重新创建。
and then manually maintained when there is a newer version available.
没有。您的依赖项在 build.gradle
文件中定义。
当您定义新版本时,Gradle 会下载新的依赖项并更新中间文件夹。
您可以通过多种方式定义依赖项:
dependencies{
//You can create a folder and put jar files inside. You can use your favorite name, usually it is libs.
compile fileTree(dir: 'libs', include: ['*.jar'])
//The support libraries dependencies are in a local maven managed by SDK
compile 'com.android.support:appcompat-v7:23.0.0'
// A Maven dependency
compile 'com.squareup.picasso:picasso:2.5.2'
//A local library
compile project(':mylibrary')
//An aar file. It requires to define a repository.
//repositories{
// flatDir{
// dirs 'libs'
// }
//}
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}