在android studio中使用gradle参数的方法

时间:2016-10-10 19:25:51

标签: android android-studio gradle android-gradle

将项目文件与android studio中的gradle文件同步会导致以下错误

Error:(14, 0) Could not find method applicationId() for arguments [com.amazon.mysampleapp] on project ':app' of type org.gradle.api.Project.

gradle文件读取的位置

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    applicationId "com.amazon.mysampleapp"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled = true
}

这里发生了什么?删除applicationID会将错误移至minSdkVersion

1 个答案:

答案 0 :(得分:2)

applicationId不会进入android块,而是你的buildConfig块:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 19
    buildToolsVersion "19.1"

    defaultConfig {
        applicationId "com.example.my.app"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
}

从此页面中提取有关applicationId:http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename

的信息