简体   繁体   English

将moPub集成到Android Studio中

[英]Integrating moPub into Android Studio

I'm trying to integrate the moPub sdk into my android studio project, but I haven't been able to get the gradle to sync properly. 我正在尝试将moPub sdk集成到我的android studio项目中,但是我无法使gradle正确同步。 This question has been asked here before, but none of those solutions have worked for me. 之前已经在这里提出了这个问题,但是这些解决方案都没有对我有用。 I followed these instructions, but got the error messages "Plugin with id org.roboelectric not found" and "Unable to load class org.codehaus.groovy.runtime.typehandling.ShortTypeHandling". 我按照这些说明进行操作,但收到错误消息“未找到ID为org.roboelectric的插件”和“无法加载org.codehaus.groovy.runtime.typehandling.ShortTypeHandling类”。 To fix this, I modified my app's build.gradle with new classpaths: 为了解决这个问题,我用新的类路径修改了应用程序的build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'
        classpath 'org.robolectric:robolectric-gradle-plugin:1.1.0'
        classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Unfortunately, I still get the error message "Error:(1, 0) Cause: org/codehaus/groovy/runtime/StringGroovyMethods". 不幸的是,我仍然收到错误消息“错误:(1,0)原因:org / codehaus / groovy / runtime / StringGroovyMethods”。 I've tried using version 1.0.1 of gradle but nothing changed. 我尝试使用gradle的1.0.1版本,但没有任何变化。 I'm not sure where to go from here, so any help would be greatly appreciated. 我不确定从这里要去哪里,所以我们将不胜感激。

Read the comment in that build.gradle file. 阅读该build.gradle文件中的注释。

From this answer https://stackoverflow.com/a/23241888/2278598 从这个答案https://stackoverflow.com/a/23241888/2278598

<PROJECT_ROOT>\\app\\build.gradle is specific for app module. <PROJECT_ROOT>\\app\\build.gradle是特定于应用程序模块的。

<PROJECT_ROOT>\\build.gradle is a "Top-level build file" where you can add configuration options common to all sub-projects/modules. <PROJECT_ROOT>\\build.gradle是一个“顶级构建文件”,您可以在其中添加所有子项目/模块共有的配置选项。

You need to put the dependencies you are adding in the <PROJECT_ROOT>\\app\\build.gradle 您需要将要添加的依赖项放在<PROJECT_ROOT>\\app\\build.gradle

You have configured Robolectric correctly in the top level gradle file. 您已在顶级gradle文件中正确配置了Robolectric。

You need to use a later version of gradle to build using the Groovy plugin. 您需要使用更高版本的gradle才能使用Groovy插件进行构建。 I would use classpath 'com.android.tools.build:gradle:1.2.3' 我会使用类路径'com.android.tools.build:gradle:1.2.3'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM