从子模块添加依赖项

时间:2018-12-19 14:37:42

标签: android android-studio gradle dependencies exoplayer

在我的项目中,我有一个exoplayer的子模块。在我的settings.gradle中,添加exoplayer的lib路径

def modulePrefix = ":exoplayer:"
def rootDir = new File('').toPath().toString()

include ':exoplayer:library'
include ':exoplayer:library'
include ':exoplayer:library-core'
include ':exoplayer:library-dash'
include ':exoplayer:library-hls'
include ':exoplayer:library-smoothstreaming'
include ':exoplayer:library-ui'
include ':exoplayer:extension-okhttp'

project(modulePrefix + 'library').projectDir = new File(rootDir, 
'library/all')
project(modulePrefix + 'library-core').projectDir = new File(rootDir, 
'library/core')
project(modulePrefix + 'library-dash').projectDir = new File(rootDir, 
'library/dash')
project(modulePrefix + 'library-hls').projectDir = new File(rootDir, 
'library/hls')
project(modulePrefix + 'library-smoothstreaming').projectDir = new 
File(rootDir, 'library/smoothstreaming')
project(modulePrefix + 'library-ui').projectDir = new File(rootDir, 
'library/ui')
project(modulePrefix + 'extension-okhttp').projectDir = new 
File(rootDir, 'extensions/okhttp')

现在,我像这样在build.gradle中添加exoplayer库的依赖项

implementation project(':exoplayer-library-core')
implementation project(':exoplayer-library-dash')
implementation project(':exoplayer-library-hls')
implementation project(':exoplayer-library-smoothstreaming')
implementation project(':exoplayer-library-ui')
implementation project(':exoplayer-extension-okhttp')

我得到这个错误

Project with path ':exoplayer-library-core' could not be found in root 
project 'myProject'

1 个答案:

答案 0 :(得分:0)

这就是我的做法:

settings.gradle:

rootProject.name = 'main'

include 'changelogs'
include 'common'

project(':changelogs').projectDir = new File(settingsDir, '../changelogs')
project(':common').projectDir = new File(settingsDir, '../common')

和Build.gradle

implementation project(':changelogs')