找不到Gradle DSL方法可执行文件

时间:2018-06-14 10:35:17

标签: android android-studio gradle build.gradle

我使用android studio。

我想运行一个任务,对于java jar文件编译,所以想要执行"可执行文件" as" java"在gradle但它说

找不到Gradle DSL方法:' executable()' 可能的原因:

  • 项目' logcatdemo'可能正在使用不包含该方法的Android Gradle插件版本(例如,在1.1.0中添加了' testCompile')。 将插件升级到3.1.3版并同步项目
  • 项目' logcatdemo'可能正在使用不包含该方法的Gradle版本。 打开Gradle包装器文件
  • 构建文件可能缺少Gradle插件。 申请Gradle插件
  • 我的build.gradle for module是,

        // 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
        }
    

    我的应用程序构建gradle是

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

    2 个答案:

    答案 0 :(得分:1)

    我找到了解决方案:

    在任务中添加一个参数,

    task run(type:JavaExec){
    
    }
    

    这清除了错误

    答案 1 :(得分:0)

    阅读JavaExec

      

    在子进程中执行Java应用程序。

    task runApp(type: JavaExec) {
    
    }