Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to copy your pattern #4

Closed
RichardGuion opened this issue May 8, 2014 · 4 comments
Closed

Trying to copy your pattern #4

RichardGuion opened this issue May 8, 2014 · 4 comments
Labels

Comments

@RichardGuion
Copy link
Contributor

Hi - trying to follow your pattern of sub directories with an existing project. I have tried to replicate what you have almost exactly. Yet when I build I get this error:

  • What went wrong:
    A problem occurred evaluating project ':UnitTestsRobolectric'.

    The 'android' or 'android-library' plugin is required.

It thinks that the main Android application doesn't have the android plugin applied, yet it does! Any idea what I am doing wrong?

The directory structure looks like:

android
   build.gradle
   settings.gradle
   app/
       build.gradle
   UnitTestsRobolectric
       build.gradle

Settings.gradle:

  include ':app', 'UnitTestsRobolectric'

My build.gradle in the top most folder has the same settings as yours, except I use build tools 19.0.1.

app/build.gradle has this at top:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
    }
}

apply plugin: 'android'
...

UnitTestsRobolectric/build.gradle has this:

buildscript {
    repositories {
      maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
        classpath "com.novoda:gradle-android-test-plugin:0.9.9-SNAPSHOT"
        classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:0.4.0'
    }
}

apply plugin: 'java'

test.reports.html.enabled = false     // just clean up dashboard from not generated reports
test.reports.junitXml.enabled = false // just clean up dashboard from not generated reports

apply plugin: 'android-test'
apply plugin: "jacoco"
apply plugin: 'coveralls'
apply plugin: 'idea'

repositories {
  maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

android {
  projectUnderTest ':app'
}

I see this code in the plugin source so I know it must have found the gradle file for the app, but I can't explain why it doesn't see the android plugin applied!

public void projectUnderTest(String projectName) {

    Project projectUnderTest = project.project(projectName)

    def hasAppPlugin = hasAppPlugin(projectUnderTest)
    def hasLibraryPlugin = hasLibraryPlugin(projectUnderTest)

    if (!hasAppPlugin && !hasLibraryPlugin) {
        throw new IllegalStateException("The 'android' or 'android-library' plugin is required.")
@nenick
Copy link
Owner

nenick commented May 8, 2014

thanks for your simple example and i found the pitfall. In alphabetical order upper case letter comes before of lower case letters. So your UnitTest-module was just in front and not the app-module

I also updated it here with extra tips
https://github.com/nenick/android-gradle-template/wiki/Renaming-project-modules

@RichardGuion
Copy link
Contributor Author

I finally figured this out - thanks to your working example I could compare against the --debug log on gradlew.

Your project mysteriously builds the projects in order:

Included projects: [root project 'android-gradle-template', project ':AndroidSample', project ':ComponentTestsRobolectric', project ':GenerateDatabaseContent', project ':UnitTestsRobolectric']

In other words - it compiles the main AndroidSample first; the order is alphabetical!

@RichardGuion
Copy link
Contributor Author

LOL - you answered me at the same time I found the answer! Thank you for your effort!

I have learned a lot by looking at this code. I even put in some debug statements in the plugin.

@nenick
Copy link
Owner

nenick commented May 8, 2014

good to know that you are searching by self for your issues ;)

(when you feel, your issues are not more present, then please close them)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants