【问题标题】:Could not find method defaultConfig() - Android Studio找不到方法 defaultConfig() - Android Studio
【发布时间】:2017-09-19 00:20:18
【问题描述】:

我最近(3 天前)开始学习 Android Studio。我买了一个 Eclipse 游戏项目来玩,但我遇到了错误。当我修复该错误时,我得到了一个新错误。

目前我似乎无法修复的是:

错误:(2, 0) 找不到参数的方法 defaultConfig() [build_2ttwbw07u5v666j5nx2ciclk3$_run_closure1@5ac759e5] 在项目上 ':app' 类型为 org.gradle.api.Project。打开 文件

我的build.gradle(模块:App):

defaultConfig {
        applicationId "com.getemplate.catadventure"
        minSdkVersion 14
        targetSdkVersion 26

        sourceSets.main {
            jniLibs.srcDir 'src/main/libs'
            jni.srcDirs = [] //disable automatic ndk-build call
        }

        ndk {
            moduleName "player_shared"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }


android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    dexOptions {
        preDexLibraries = false
    }
}

dependencies {
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/dagger-1.2.2.jar')
    compile files('libs/javax.inject-1.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    compile files('libs/support-v4-19.0.1.jar')
}

有人知道我为什么会收到错误消息吗?

这是一个屏幕截图:

非常感谢您在此问题上的时间和帮助。

【问题讨论】:

  • 我知道尝试将代码位 "android { compileSdkVersion 26 buildToolsVersion "26.0.1" dexOptions { preDexLibraries = false } } 移到顶部,但现在我收到消息“找不到方法 android () 用于 org.gradle.api.Project 类型的项目 ':app' 上的参数 [build_2ttwbw07u5v666j5nx2ciclk3$_run_closure1@6f070f25]。”

标签: android eclipse android-studio


【解决方案1】:

这是因为您没有为apply plugin: 'com.android.application' 的android 应用程序插件添加代码。您还需要像这样在android中移动defaultConfig

apply plugin: 'com.android.application'

android {

  compileSdkVersion 26
  buildToolsVersion "26.0.3"

  defaultConfig {
   ...
  }

}

dependencies {
  ...
}

【讨论】:

  • 非常感谢!我通过重新创建一个新项目解决了这个问题,因为我觉得我的代码在尝试修复其他错误时有点搞砸了。我知道另一个错误:构建命令失败。使用参数 {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\APPS\FamousDex\app\src\main\jni 执行进程 C:\Users\user\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd 时出错\Android.mk 我用谷歌搜索了这个,但我无法弄清楚。
  • 恭喜! ;)
  • 这个错误可能是因为你没有正确的NDK路径
  • 您是否尝试将ndk路径添加到local.properties?像这样的东西:ndk.dir=/opt/android/sdk/ndk-bundle。请注意,这是Linux中ndk的一行,我不知道Windows。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-09
  • 1970-01-01
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多