【问题标题】:Add external project in Android Studio project as dependency results in error not finding a file在 Android Studio 项目中添加外部项目作为依赖项导致错误找不到文件
【发布时间】:2016-06-16 14:22:45
【问题描述】:

我目前正在尝试在我的项目中添加 https://github.com/firebase/FirebaseUI-Android 的本地克隆作为依赖项。我不想通过标准方式导入它,因为我想对 FirebaseUI 进行修改。目前我正在尝试这个:

settings.gradle:

include ':firebaseui'
project(':firebaseui').projectDir = new File(settingsDir, '../FirebaseUI')

我的模块的build.gradle:

dependencies {
    compile project(":firebaseui")
}

但我明白了:

Error:(42, 0) Could not read script 'C:\Users\Gonzalo\AndroidStudioProjects\MyProject\common\constants.gradle' as it does not exist.

在 FirebaseUI\build.gradle 中导入:

allprojects { project ->
    // Get constants, this is where we store things
    // like the list of submodules or the version
    project.apply from: "$rootDir/common/constants.gradle"
...

是 FirebaseUI 的 build.gradle 还是我的问题?

【问题讨论】:

    标签: android android-studio gradle firebaseui


    【解决方案1】:

    通过mavenLocal() repo 使用二进制 deps:

    1. git clone https://github.com/firebase/FirebaseUI-Android
    2. cd FirebaseUI-Android
    3. gradlew tasks // 你会看到 publishToMavenLocal
    4. 将FirebaseUI-Android 打开到单独的 Intellij 实例中
    5. 进行更改
    6. 运行gradlew publishToMavenLocal
    7. 在您自己的项目中,将mavenLocal() 添加到您的repositories
    8. 然后添加compile 'com.firebaseui:firebase-ui:0.4.1' 做你的dependencies

    毕竟,你可以走了。

    1. 对库进行更改
    2. 通过gradlew publishToMavenLocal再次发布
    3. 重新编译您的应用程序

    【讨论】:

    • 要么我的缓存有问题,要么 gradle 正在获取外部(官方)版本,但我不得不在途中将版本更改为 0.4.2 以确保包含本地版本。
    • 是的,通常我通过附加 -SNAPSHOT 来更改版本。
    【解决方案2】:

    问题在于$rootDir 的含义。如果您尝试仅构建 firebase 代码,则其父 $rootDir 将返回其父文件夹。并且constants.gradle的相对位置是有效的。

    现在,当您将 firebase 添加为项目的子项目时,$rootDir 现在是您的根目录,$rootDir/common/constants.gradle 不再是有效路径。您也许可以将路径替换为:

    $rootDir../FirebaseUI/common/constants.gradle
    

    但是,除非您对 firebase 代码进行本地更改,否则我会赞同 Jared 的建议,即使用来自 maven 存储库的二进制依赖项。

    【讨论】:

      猜你喜欢
      • 2016-11-27
      • 2018-08-06
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 2018-01-05
      • 2015-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多