如何在 Android Studio 中将 MoPub 集成到共享库中

How to integrate MoPub inside a shared library in Android Studio

我需要将 MoPub 集成到由 3 个不同游戏共享的 android 库中。

我尝试使用 fabric 插件但没有成功...经过一些尝试后我得到了这个错误:

Error:Failed to resolve: com.mopub.volley:mopub-volley:1.1.0

然后我也尝试按照您可以在此处找到的指南进行操作 (https://github.com/mopub/mopub-android-sdk/wiki/Getting-Started),但我总是遇到一些错误(我无法通过终端执行 gradle 命令,或者我得到与上述相同的错误)。

有人可以帮助我吗? 谢谢,

米尔科

更新

感谢@Edward,我能够在我的项目中正确导入 mopub-sdk。

为了修复 mopub-volley 错误,首先清理解决方案,读取控制台中丢失的文件,查看路径,重新创建指示的路径并添加 mopub-volley-1.1。0.jar, mopub-volley-1.1.0.pom 在该文件夹中。 重建,您就可以开始了!

In my case, mopub-sdk was looking for the mopub-volley lib inside an inexistent folder in the same path of the android sdk.

如果您遇到与 millenial sdk 相关的另一个错误,请将此行添加到 mopub-sdk 库内 build.gradle 文件的依赖项部分:

compile fileTree(dir: 'libs', include: ['*.jar'])

你应该得到这样的东西:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:support-v4:22.0.0'
  compile 'com.android.support:support-annotations:22.0.0'
  compile 'com.mopub.volley:mopub-volley:1.1.0'
}

希望对您有所帮助!

  1. 去下载 MoPub SDK。
  2. 解压得到mopub-sdk文件夹
  3. 导航到“项目位置”,进入项目文件夹,然后将解压缩的 mopub-sdk 放入该文件夹。
  4. 导航回 Android Studio 并打开项目的 settings.gradle 文件并将 MoPub SDK 作为模块包含在内,如下所示。您可能需要在 Android Studio 中再次同步 Gradle 才能在左侧项目 window.

    中显示“mopub-sdk”

    包含“:app”、“:mopub-sdk”

  5. 打开项目的 build.gradle 文件并将 jcenter 添加为存储库并将 MoPub SDK 添加为依赖项:

    存储库{ 中心() }

    ...

    依赖项{ 编译项目(':mopub-sdk') ... }

mavencentral 或 jcenter 中似乎没有 mopub-volley 库 所以可以尝试使用

compile 'com.mcxiaoke.volley:library:1.0.18'

而不是

compile 'com.mopub.volley:mopub-volley:1.1.0'

对我有帮助。

派对迟到的人:

repositories {
    jcenter()
}

dependencies {
    compile('com.mopub:mopub-sdk:4.8.0@aar') {
        transitive = true
    }
}

只需确保您已在存储库中添加 jcenter() 即可。由于某些原因,fabric 不会自动执行此操作