android - 在Android Studio中将Gradle依赖关系解析为本地JAR

标签 android android-studio gradle jar dependency-management

目前,我的Android应用程序项目是针对本地库项目进行编译的,如下所示:

// build.gradle

dependencies {
    compile project(':Library-Project')
    compile files('libs/library.jar') // Resolve into this if Library-Project is not available
}

本地库项目内置在library.jar中,并放置在libs文件夹中。

如果不存在本地项目而不用注释library.jar代替对jar进行编译,是否有办法回退compile project(':Library-Project') Artifact ?

最佳答案

使用了一种更动态的方法,应针对其实际编译依赖项。

dependencies {
    // Check if the local project exists, and compile against that if it does
    if ( new File("/Library-Project").exists() )
    {
        compile project(':Library-Project')
    }
    // Local project DNE, compile against JAR file
    else
    {
        compile files('libs/library.jar')
    }
}

自动编译/libs文件夹中所有JAR文件的另一种方法是在dependencies块中添加以下行:
compile fileTree(include: ['*.jar'], dir: 'libs')

关于android - 在Android Studio中将Gradle依赖关系解析为本地JAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41028430/

相关文章:

android - android 中的 sso 使用 microsoft azure sdk -ADAL

c# - 缺少 Xamarin sider.dll

android - 如何在Gradle项目Android Studio中导入库

R8 的 Android 构建失败

android - 带 Lint 的StackOverflowError

android - 显示是/否对话框而不是确定/取消

android - 如何在 Google Maps API V2 中锁定相机

java - 安卓工作室 : Unboxing of 'xxx' may produce 'java.lang.NullPointerException'

android - Robolectric & Gradle : error: cannot access BufferedImage class file for java. 找不到 awt.image.BufferedImage

Spring MVC 映射-未找到 404 错误-使用 Gradle 和 Jetty