在Android Studio项目中添加外部项目作为依赖项导致错误找不到文件

时间:2016-06-16 14:22:46

标签: android android-studio gradle firebaseui

我目前正在尝试在我的项目中添加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还是我的问题?

2 个答案:

答案 0 :(得分:1)

通过mavenLocal() repo:

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

    1. 对库进行更改
    2. 通过gradlew publishToMavenLocal
    3. 再次发布
    4. 重新编译您的申请

答案 1 :(得分:0)

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

现在,当您将firebase添加为项目的子项目时,$ rootDir现在是您的根目录,$rootDir/common/constants.gradle不再是有效路径。您可以通过以下方式取消路径:

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

但是,除非您对firebase代码进行本地更改,否则我会建议Jared建议使用maven repo中的二进制依赖项。