将项目移植到Android Studio时出错?

时间:2015-03-28 16:09:40

标签: android eclipse

我是Android Studio新手,我已经使用Eclipse大约两年了。我尝试了解这些解决方案。

Android gradle build Error:(9, 0) Gradle DSL method not found: 'compile()'.

Gradle DSL method not found: 'compile()'

我无法让它发挥作用。

这就是它所说的......

错误:(17,0)未找到Gradle DSL方法:' compile()' 可能的原因:

  • 项目' clxxxii - PMv5'可能正在使用不包含该方法的Gradle版本。 打开Gradle包装器文件
  • 构建文件可能缺少Gradle插件。 申请Gradle插件
  • '依赖性'不能应用于'(groovy.lang.Closure)'少...(⌘F1) 此检查报告具有不兼容类型的分配

    以下是发出错误的文件

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.1.0'    }
    }
    
    allprojects {
        repositories {
            mavenCentral()
        }
    }
    dependencies {
        apply plugin: 'announce'
        compile 'com.android.support:appcompat-v7:21.0.0'
        compile 'com.android.support:cardview-v7:21.0.+'
    }
    

    根据其他问题,你可能也需要这个。

    apply plugin: 'android'
    
    android {
        compileSdkVersion 17
        buildToolsVersion "19.0.3"
    
        defaultConfig {
            minSdkVersion 8
            targetSdkVersion 19
        }
    
        buildTypes {
            release {
                runProguard false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
    }
    
    dependencies {
        compile 'com.android.support:support-v4:+'
        compile files('libs/FlurryAnalytics_3.3.0.jar')
        compile files('libs/heyzap-ads-sdk.jar')
        compile files('libs/HomeBaseSDK2.2.jar')
        compile files('libs/placed-persistent-sdk-1.10.jar')
        compile files('libs/revmob-6.7.0.jar')
    }
    

    有人可以帮我理解问题是什么,以及它为什么会发生?

    1 个答案:

    答案 0 :(得分:1)

    这可能无法完全回答您的问题,但也许您可以让您的项目正常运行。 这些依赖项不属于您的第一个build.gradle文件:

    dependencies {
    apply plugin: 'announce'
    compile 'com.android.support:appcompat-v7:21.0.0'
    compile 'com.android.support:cardview-v7:21.0.+'
    }
    

    您的Project build.gradle中的依赖项应如下所示,注释由IDE生成,并告诉您不要将应用程序依赖项放在此处:

     dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
    

    将它们移动到/app/build.gradle文件,我将文件稍微修改一下,以便更新到当前最新版本的buildTools等。如果你有可能必须从SDK Manager中下载一些文件还没有:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 22
        buildToolsVersion "22.0.1"
    
    defaultConfig {
        applicationId "your.package.name"
        minSdkVersion 8
        targetSdkVersion 22
    }
    
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
       }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:22.0.0'
        compile 'com.android.support:support-v4:+'
        compile files('libs/FlurryAnalytics_3.3.0.jar')
        compile files('libs/heyzap-ads-sdk.jar')
        compile files('libs/HomeBaseSDK2.2.jar')
        compile files('libs/placed-persistent-sdk-1.10.jar')
        compile files('libs/revmob-6.7.0.jar')
     }
    
    相关问题