2015-10-20 116 views
6

这是错误的全文: -错误:(21,0)未找到摇篮DSL方法:

Error:(21, 0) Gradle DSL method not found: 'buildConfigField()'

可能的原因:

  • The project 'Sunshine2' may be using a version of Gradle that does not contain the method. Gradle settings
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • 我使用gradle这个2.4 Android Studio 1.4。我不知道是什么导致问题或如何解决它。请稍微帮忙。

    +0

    你检查这http://stackoverflow.com/questions/23267365/cannot-add-buildconfigfield-in-productflavors – GMB

    +0

    你要提供你的build.script内容。看起来,你有一些语法问题 – Stanislav

    +0

    专线小巴 - 我错过了一个逗号。谢谢。 – Alex

    回答

    3

    的代码调用BuildConfig的一行丢失了逗号:

    buildTypes.each { 
         it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY' 'MyOpenWeatherAPIKey' 
          } 
    

    现在读起来像这样:

    buildTypes.each { 
         it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', 'MyOpenWeatherAPIKey' 
          } 
    
    0

    您可能忽略了括号,而复制粘贴您的MyOpenWeatherAPIKey

    最初它看起来像

    buildTypes.each { 
        it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherAPIKey 
    } 
    

    您从https://home.openweathermap.org/api_keys复制你的MyOpenWeatherAPIKey它想

    buildTypes.each { 
        it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx' 
    } 
    
    相关问题