如何将库的本地副本添加并编译到Android React Native模块中?

时间:2019-03-15 13:15:52

标签: react-native build.gradle react-native-android exoplayer react-native-video

如何将外部库源代码添加到本机模块中。 在这种情况下,我想将ExoPlayer的本地副本添加到react-native-video模块。 我想“ git clone” ExoPlayer的原始来源 在react-native-video / android-exoplayer内部,对其进行一些修改并进行测试。 当前/react-native-video/android-exoplayer/build.gradle的依赖程度是:

dependencies {
    //noinspection GradleDynamicVersion
    provided "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
    compile 'com.google.android.exoplayer:exoplayer:2.7.3'
    compile('com.google.android.exoplayer:extension-okhttp:2.7.3') {
        exclude group: 'com.squareup.okhttp3', module: 'okhttp'
    }
    compile 'com.squareup.okhttp3:okhttp:3.9.1'
}

当前文件结构:

构建

build.gradle

ExoPlayer

/ src

我通过“ git clone”获得的这个目录“ ExoPlayer”,并希望使用它代替

compile 'com.google.android.exoplayer:exoplayer:2.7.3'

1 个答案:

答案 0 :(得分:0)

我找到了解决方法:

在根项目的settings.gradle中应添加以下内容:

gradle.ext.exoplayerRoot = '../node_modules/react-native-video/android-exoplayer/ExoPlayer-r2.7.3'
gradle.ext.exoplayerModulePrefix = 'exoplayer-'
apply from: new File(gradle.ext.exoplayerRoot, 'core_settings.gradle')

在react-native-video / android-exoplayer / build.gradle 依赖项部分中添加以下内容:

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

并删除所有以“ compile”开头的行