1

I use android studio.

I want to run a task ,for java jar file compilation so wanted to execute the "executable" as "java" in the gradle but it says

Gradle DSL method not found: 'executable()' Possible causes:

  • The project 'logcatdemo' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0). Upgrade plugin to version 3.1.3 and sync project
  • The project 'logcatdemo' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • My build.gradle for module is,

        // Top-level build file where you can add configuration options common to all sub-projects/modules.
        buildscript {
    
            repositories {
                google()
                jcenter()
                mavenCentral()
            }
            dependencies {
                classpath 'com.android.tools.build:gradle:3.1.3'
    
    
            }
        }
    
    
        allprojects {
            repositories {
                google()
                jcenter()
                mavenCentral()
            }
        }
        task run (overwrite:true){
             executable 'java'
        }
        task clean(type: Delete) {
            delete rootProject.buildDir
        }
    

    my app's build gradle is

    apply plugin: 'com.android.application'
            android {
    
                compileSdkVersion 27
                defaultConfig {
                    applicationId "com.xxx.yyy.logcatdemo"
                    minSdkVersion 21
                    targetSdkVersion 27
                    versionCode 1
                    versionName "1.0"
                    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
                    multiDexEnabled true
                }
                buildTypes {
                    release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }
            }
    
            dependencies {
    
                implementation fileTree(dir: 'libs', include: ['*.jar'])
                implementation 'com.android.support:support-v4:27.0.2'
                implementation 'com.android.support:appcompat-v7:27.0.2'
                implementation 'com.android.support:recyclerview-v7:27.0.2'
                implementation 'com.android.support.constraint:constraint-layout:1.1.1'
                testImplementation 'junit:junit:4.12'
                androidTestImplementation 'com.android.support.test:runner:1.0.2'
                androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    
            }
    
    
            build.finalizedBy("run")
    
    Srinivas Jayaram
    • 315
    • 5
    • 17

    2 Answers2

    1

    I found the solution:

    in the task add a parameter,

    task run(type:JavaExec){
    
    }
    

    This cleared the error

    Srinivas Jayaram
    • 315
    • 5
    • 17
    0

    Read JavaExec.

    Executes a Java application in a child process.

    task runApp(type: JavaExec) {
    
    }
    
    IntelliJ Amiya
    • 74,896
    • 15
    • 165
    • 198
    • 1
      I Need to include that , as the task is to execute java in a task, If run from the terminal where gradle is installed it works fine, but not in android studio – Srinivas Jayaram Jun 14 '18 at 11:01