1

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. 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". To fix this, I modified my app's build.gradle with new classpaths:

// 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". I've tried using version 1.0.1 of gradle but nothing changed. I'm not sure where to go from here, so any help would be greatly appreciated.

Community
  • 1
  • 1
Pancake
  • 143
  • 5
  • 12
  • `com.android.tools.build:gradle:0.12.2`? That is at least 1.5+ years old. Please use `1.3.0` and that Robolectric plugin is deprecated. – Jared Burrows Aug 05 '15 at 17:05

2 Answers2

0

Read the comment in that build.gradle file.

From this answer https://stackoverflow.com/a/23241888/2278598

<PROJECT_ROOT>\app\build.gradle is specific for app module.

<PROJECT_ROOT>\build.gradle is a "Top-level build file" where you can add configuration options common to all sub-projects/modules.

You need to put the dependencies you are adding in the <PROJECT_ROOT>\app\build.gradle

Community
  • 1
  • 1
Andrew Brooke
  • 12,073
  • 8
  • 39
  • 55
  • Thank you for the answer, but unfortunately, it hasn't resolved the issue. I tried placing the classpath dependencies in the module-specific build.gradles, but nothing changed. I placed them in the top-level build file based on [this](https://twittercommunity.com/t/mopub-sdk-does-not-build/46397/4) help article. – Pancake Aug 01 '15 at 21:02
  • I was able to get gradle to sync by putting classpath 'org.robolectric:robolectric-gradle-plugin:1.1.0' in the top level and compile 'org.codehaus.groovy:groovy-backports-compat23:2.3.5' in the app module – Andrew Brooke Aug 01 '15 at 21:13
  • That's very strange. I added "classpath 'org.robolectric:robolectric-gradle-plugin:1.1.0'" to the top level gradle file and "compile 'org.codehaus.groovy:groovy-backports-compat23:2.3.5'" to the app/build.gradle file, and I get the error "Error:Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'.". Is there something else I could be missing? – Pancake Aug 01 '15 at 22:50
  • Also, the error says it was "an unexpected error" and contains a log file. I've posted the log file [here](https://gist.github.com/jpbrabec/ec28b11095f949ecb851). – Pancake Aug 01 '15 at 22:58
  • Hey Jman117, You have configured Robolectric correctly in the top level gradle file. Per [this](https://github.com/kt3k/coveralls-gradle-plugin/issues/23) gitHub link, you need to use a later version of gradle to build using the Groovy plugin. I would use `classpath 'com.android.tools.build:gradle:1.2.3' ` – Edward Aug 03 '15 at 13:06
  • I appreciate the advice, but unfortunately changing the gradle version like you mentioned had no effect, and I get the same exact error. This is really strange. I've even tried redownloading the mopub sdk from github instead of their website, and it hasn't changed anything. Is there more I need to do in order to change the gradle version besides changing the classpath in the main build.gradle file? – Pancake Aug 03 '15 at 22:12
0

You have configured Robolectric correctly in the top level gradle file.

You need to use a later version of gradle to build using the Groovy plugin. I would use classpath 'com.android.tools.build:gradle:1.2.3'

Edward
  • 251
  • 1
  • 4