【问题标题】:Resolve Gradle Dependency into local JAR in Android Studio在 Android Studio 中将 Gradle 依赖解析为本地 JAR
【发布时间】:2016-12-07 22:20:18
【问题描述】:

目前,我的 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 文件夹中。

如果本地项目不存在没有评论 compile project(':Library-Project') 代替对 jar 进行编译,有没有办法回退到 library.jar 工件?

【问题讨论】:

    标签: android android-studio gradle jar dependency-management


    【解决方案1】:

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

    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')
    

    【讨论】:

      猜你喜欢
      • 2015-12-19
      • 2015-02-23
      • 2013-12-12
      • 1970-01-01
      • 2015-03-24
      • 2021-02-10
      • 1970-01-01
      • 2018-10-07
      相关资源
      最近更新 更多