nenick/android-gradle-template

Trying to copy your pattern

Closed this issue · 4 comments

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.")

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

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!

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.

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)