android – 错误:找不到Gradle DSL方法:compile()

enter image description here

您好,我们为我们的网站创建了一个Android应用程序,但现在您想将其转换为APK,但我遇到了以下错误,并且不让我继续编译.

Error:(60, 0) Gradle DSL method not found: 'compile()'
    Possible causes:<ul><li>The project 'Template' 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).
    <a href="fixGradleElements">Upgrade plugin to version 2.3.3 and sync project</a></li><li>The project 'Template' may be using a version of Gradle that does not contain the method.
    <a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
    <a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

这是build.gradle(项目:模板)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        maven {
            url 'https://jitpack.io'
        }
    }
}

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

ext {
    supportlib_version = '26.0.2'
    gps_version = '11.2.0'
}

//Ensure that all dependencies use the same version of the Android Support library
subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex')) {
                details.useVersion "$supportlib_version"
            }
            if (details.requested.group == 'com.google.android.gms'
                    && !details.requested.name.contains('multidex')) {
                details.useVersion "$gps_version"
            }
        }
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

和第二个build.gradle(模块:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsversion '26.0.1'
    defaultConfig {
        applicationId 'com.mayermayer.transport'
        minSdkVersion 16
        targetSdkVersion 26
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }

        //Optionally configure your Onesignal IDs below
        manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                onesignal_app_id               : "",
                                onesignal_google_project_number: ""]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    dexOptions {
        jumboMode true
    }
    productFlavors {
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
    maven {
        url "https://jitpack.io"
    }
    jcenter();
}

dependencies {
    compile 'com.devbrackets.android:exomedia:4.0.3'
    //TV
    compile 'com.cLeveroad:audiovisualization:1.0.0'
    //Radio
    compile 'com.squareup.okhttp3:okhttp:3.3.1'
    //WC
    compile 'org.jsoup:jsoup:1.8.3'
    compile 'com.onesignal:Onesignal:[3.6.0,4.0.0)'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.booking:rtlviewpager:1.0.1'
    compile 'com.github.apg-mobile:android-round-textview:v0.0.3'
    compile 'com.github.chrisbanes:PhotoView:1.3.0'
    compile 'com.google.code.gson:gson:2.8.0'
    //WC
    compile 'com.google.android.exoplayer:exoplayer:r2.4.3'
    //TV & Radio
    compile "com.android.support:cardview-v7:$supportlib_version" compile "com.android.support:appcompat-v7:$supportlib_version" compile "com.android.support:recyclerview-v7:$supportlib_version" compile "com.android.support:design:$supportlib_version" compile "com.android.support:support-v4:$supportlib_version" compile "com.android.support:support-core-utils:$supportlib_version" compile "com.android.support:support-media-compat:$supportlib_version" compile "com.google.android.gms:play-services-gcm:$gps_version" compile "com.google.android.gms:play-services-ads:$gps_version" compile "com.google.android.gms:play-services-maps:$gps_version" compile 'com.google.maps.android:android-maps-utils:0.5+'
    compile files('libs/YouTubeAndroidplayerApi.jar')
}

我错了吗?我使用Android Studio 2.3.3最新版本.

你能帮我么?你遇到过这个错误吗?祝你美好的一天.

解决方法:

将此行移动到不同的行:

    //TV & Radio
   compile "com.android.support:cardview-v7:$supportlib_version" compile "com.android.support:appcompat-v7:$supportlib_version" compile "com.android.support:recyclerview-v7:$supportlib_version" compile "com.android.support:design:$supportlib_version" compile "com.android.support:support-v4:$supportlib_version" compile "com.android.support:support-core-utils:$supportlib_version" compile "com.android.support:support-media-compat:$supportlib_version" compile "com.google.android.gms:play-services-gcm:$gps_version" compile "com.google.android.gms:play-services-ads:$gps_version" compile "com.google.android.gms:play-services-maps:$gps_version" compile 'com.google.maps.android:android-maps-utils:0.5+'

你不能以这种方式使用编译.
用这个:

compile "com.android.support:cardview-v7:$supportlib_version" 
compile "com.android.support:appcompat-v7:$supportlib_version" 
compile "com.android.support:recyclerview-v7:$supportlib_version" 
compile "com.android.support:design:$supportlib_version" 
compile "com.android.support:support-v4:$supportlib_version" 
compile "com.android.support:support-core-utils:$supportlib_version" 
compile "com.android.support:support-media-compat:$supportlib_version" 
compile "com.google.android.gms:play-services-gcm:$gps_version" 
compile "com.google.android.gms:play-services-ads:$gps_version" 
compile "com.google.android.gms:play-services-maps:$gps_version" 
compile 'com.google.maps.android:android-maps-utils:0.5+'

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...