美文网首页安卓开发
疑难杂症(一)集成优酷sdk[aar] library Modu

疑难杂症(一)集成优酷sdk[aar] library Modu

作者: yexue | 来源:发表于2017-09-08 14:18 被阅读1118次

集成优酷视频播放sdk时,遇到了一个很蛋疼的问题
sdk提供了一个aar,正常套路都是直接copy代码
把arr copy到自己library Module libs下,然后
build.gradle

android {
    ......
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs'];
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    //系统库
    compile 'com.android.support:support-v4:25.0.1'
    //公共库
    compile 'com.alibaba:fastjson:1.1.56.android'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    //sdk
    compile(name: 'YoukuPlayerOpenSDK-release', ext: 'aar')

代码的套路总是让我无法自拔


Error:svn: E155010: Path 'E:\...\GFishing\other\youkuplayer\libs\YoukuPlayerOpenSDK-release.aar' does not exist
> Could not resolve all dependencies for configuration ':app:_debugApk'.
   > A problem occurred configuring project ':library'.
      > Could not resolve all dependencies for configuration ':library:_debugPublishCopy'.
         > Could not find :YoukuPlayerOpenSDK-release:.
           Required by:
               project :library > project :youkuPlayer

what?
找不到aar...
折腾了半天才搞定

原因:

@aar 本身就是一种library Module,直接作用在
apply plugin:'com.android.application'

我上面写在了apply plugin: 'com.android.library',所以找不到
解决办法Android Studio多Module使用 aar 依赖包 丢包解决,我采用了如下两种

1、 在Project 下的 build.gradle 中的 repositories 中添加相应的引用如下:


allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
        /**子模块含有aar:添加全局引用*/
        flatDir {
            // 由于Library module中引用了 youkuplayer 库的 aar,在多 module 的情况下,
            // 其他的module编译会报错,所以需要在所有工程的repositories
            // 下把Library module中的libs目录添加到依赖关系中
            dirs project(':youkuPlayer').file('libs')
        }
    }
}

2、在app 的build.gradle文件中加入如下一段:

/**子模块含有aar*/
    repositories {
        flatDir {
            dirs 'libs','../youkuPlayer/libs' //我的aar在youkuPlayer Module下
        }
    }

相关文章

网友评论

    本文标题:疑难杂症(一)集成优酷sdk[aar] library Modu

    本文链接:https://www.haomeiwen.com/subject/xbugjxtx.html