【问题标题】:Errors while porting project to Android Studio?将项目移植到 Android Studio 时出错?
【发布时间】:2015-06-01 21:12:44
【问题描述】:

我是 Android Studio 的新手,我使用 Eclipse 大约有 2 年了。我正在尝试理解这些解决方案。

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 插件
  • 'dependencies' 不能应用于'(groovy.lang.Closure)' less... (⌘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')
    }
    

    谁能帮我理解问题出在哪里,为什么会这样?

    【问题讨论】:

    • 从依赖项中移除应用插件。 (我不知道它做了什么,但它不是依赖)
    • 好的...我删除了这个:应用插件:'android'
    • 呃,试试这个:apply plugin: 'announce'
    • apply plugin: 'com.android.application' - 我可能错了,但这可能是应该存在的。它没有修复 compile() 错误所以我不知道..

    标签: android eclipse


    【解决方案1】:

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

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

    您在项目 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 管理器下载其中一些还没有:

    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')
     }
    

    【讨论】:

    • @ 现在我收到此错误.. /Users/clxxxii/Downloads/l'espace de travail/clxxxii - PMv5/app/build/intermediates/exploded-aar/com.android.support /appcompat-v7/22.0.0/res/values-v11/values.xml 缺少很多资源.. 即:错误:(47、21)找不到与给定名称匹配的资源:attr 'android:actionModeShareDrawable' .
    • 或者您可能需要将您的 minSdk 版本设置得更高,我建议您将 setminSdk 设置为 12 甚至 15,以针对大多数设备。
    • 是的,就像 20 秒前一样。但讽刺的是,我导入了错误的项目版本。。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    相关资源
    最近更新 更多