0

Android Studio Version: 1.0.2 Gradle Version: 2.2.1

I am moving to android studio and I am currently trying to get a grip on gradle in order to migrate my ant build.xml to gradle or at least set up the build.gradle in a way, that I can use my old ant tasks from gradle.

Details on the current issues can be found in my other question.

Now according to the gradle documentation, chapter 6.5 here I should be able to do something like this:

task intro(dependsOn: hello) << {
    println "I'm Gradle"
}

Hence I added the following to my build.gradle file:

//noinspection GroovyAssignabilityCheck
task all(dependsOn: 'release-all') << {

}

If I don't add

//noinspection GroovyAssignabilityCheck

gradle will give me a different error instead: "Cannot infer argument types".

"release-all" is an ant-task defined in my build.xml the problem is, that the gradle editor in the IDE (Android Studio) marks my task name "all" as faulty and claims: Cannot resolve symbol "all". I also tried adding above snippet within the braces of the "android" section in below build.gradle file, same error message though.

Here is my complete gradle.build file from my specific project, i.e. not the top-level build.gradle:

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 19
        buildToolsVersion "21.1.2"

        signingConfigs {

            release {
                storeFile file('android.keystore')
                storePassword "pwd"
                keyAlias "alias"
                keyPassword "pwd"
            }
        }

        defaultConfig {
            applicationId "myapp"
            minSdkVersion 14
            targetSdkVersion 14

            testApplicationId "myapp.test"
            testInstrumentationRunner "android.test.InstrumentationTestRunner"
        }

        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
                signingConfig signingConfigs.release
            }

        }
    }

    //noinspection GroovyAssignabilityCheck
    task all(dependsOn: 'release-all') << {

    }

    dependencies {
        compile project(':myapplibrary')
        compile 'com.android.support:support-v4:19.1.0'
        compile 'com.android.support:appcompat-v7:19.1.0'
        compile files('libs/android-support-v13.jar')
        compile files('libs/ormlite-android-4.38.jar')
        compile files('libs/ormlite-core-4.38.jar')
        compile files('libs/osmdroid-android-3.0.10-javadoc.jar')
        compile files('libs/osmdroid-android-3.0.10.jar')
        compile files('libs/slf4j-android-1.5.8.jar')
        compile files('libs/xmltask.jar')
    }

The odd thing is: When I run gradlew from the command line it doesn't actually throw any errors. Should it not technically fail while parsing the build.gradle because of above error the IDE shows me in the editor?

On an additional note - the following line is processed just fine by the editor:

//noinspection GroovyAssignabilityCheck
task all << {

}

But that's unfortunately not what I need.

Community
  • 1
  • 1
AgentKnopf
  • 4,295
  • 7
  • 45
  • 81

1 Answers1

3

IDE support for Gradle is still evolving. It is not uncommon to have your IDE report errors and warnings while still having a syntactically correct script. This is due to several factors, to include the dynamic nature of Groovy, as well as AST transforms and metaprogramming extensions of Gradle. Specifically, the task declaration syntax used in Gradle scripts is made possible by an AST transformation which the IDE is not aware of. For the most part you can ignore most "Cannot resolve symbol x" messages.

Mark Vieira
  • 13,198
  • 4
  • 46
  • 39
  • Thanks a ton for pointing this out, it is always a bit disconcerting if the IDE shows errors, makes me a bit unsure about what I am doing, especially being all new to groovy/gradle. I'll accept this answer, since the problem is apparently with the IDE - thanks! – AgentKnopf Jan 13 '15 at 07:49