Gradle模块和git子模块

 陈凤湖南 发布于 2022-12-29 12:46

我有一个名为工具包,两个模块库项目coredatabase与此配置:

settings.gradle

include ':core'
include ':database' 

核心build.gradle

dependencies {
    compile 'com.android.support:support-v4:20.+'
    compile 'com.jakewharton:butterknife:5.1.+'
    compile 'com.google.code.gson:gson:2.2.+'
    compile 'uk.co.chrisjenx:calligraphy:0.7.+'
    compile files('libs/flurry-3.4.0.jar')
}

数据库build.gradle

dependencies {
    compile project(':core')
}

在这个库项目中运行我的测试时没问题,但是我想在其他项目中添加这个库作为git子模块,这个项目有以下配置:

settings.gradle

include ':app-tablet'
include 'libraries:float-hint'
include 'libraries:toolkit:core'
include 'libraries:toolkit:database'
include 'libraries:twoway-view:TwoWayView'

app build.gradle

dependencies {
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'com.jayway.android.robotium:robotium-solo:5.2.1@jar'
    compile 'com.squareup.dagger:dagger:1.2.+'
    compile 'com.squareup.picasso:picasso:2.1.1@jar'
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    compile project(':libraries:float-hint')
    compile project(':libraries:porquenao-toolkit:core')
    compile project(':libraries:porquenao-toolkit:database')
    compile project(':libraries:twoway-view:TwoWayView')
}

当我尝试编译时,我得到以下内容:

$  gradlew assembleDebug -d

12:10:46.283 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
12:10:46.285 [ERROR] [org.gradle.BuildExceptionReporter] 
12:10:46.285 [ERROR] [org.gradle.BuildExceptionReporter] * Where:
12:10:46.285 [ERROR] [org.gradle.BuildExceptionReporter] Build file '/path/libraries/toolkit/database/build.gradle' line: 16
12:10:46.286 [ERROR] [org.gradle.BuildExceptionReporter] 
12:10:46.286 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
12:10:46.286 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred evaluating project ':libraries:toolkit:database'.
12:10:46.287 [ERROR] [org.gradle.BuildExceptionReporter] > Project with path ':core' could not be found in project ':libraries:toolkit:database'.
12:10:46.308 [ERROR] [org.gradle.BuildExceptionReporter]    ... more
12:10:46.308 [LIFECYCLE] [org.gradle.BuildResultLogger] 
12:10:46.308 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED

我知道问题是关于路径:core,libraries:toolkit:core但是如何恰当地解决这个问题?

1 个回答
  • 您的应用程序gradle文件存在命名问题.

    settings.gradle具有:

    include 'libraries:toolkit:core'

    build.gradle有:

    compile project(':libraries:porquenao-toolkit:core')
    

    假设你解决了这个问题,你仍然会有错误.

    数据库模块将尝试编译":core",但在应用程序中使用时,核心模块有不同的路径:":libraries:porquenao-toolkit:core"

    解决此问题的一种方法是在两个项目中将核心库包含为":core",但为其提供不同的项目路径.

    您的settings.gradle文件如下所示:

    工具包:

    include ':core'
    project(':core').projectDir = new File(rootDir, 'core')
    

    应用程序:

    include ':core'
    project(':core').projectDir = new File(rootDir, 'libraries/porquenao-toolkit/core')
    

    2022-12-29 13:35 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有