![](/img/trans.png)
[英]Could not find method buildTypes() for arguments on project ':app' of type org.gradle.api.Project
[英]Could not find method android() for arguments org.gradle.api.Project
遇到一個錯誤,當我嘗試在 Studio 中編譯我的項目時,我搜索了很多,但沒有真正的解決方案
錯誤:(17, 0) 在 org.gradle.api.Project 類型的根項目“booksStudioDir”上找不到參數 [build_a7zf1o8ge4ow4uolz6kqzw5ov$_run_closure2@19201053] 的方法 android()。
這是我的構建/gradle 文件的示例
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 21
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.peade.time"
minSdkVersion 10
targetSdkVersion 13
}
signingConfigs {
release {
storeFile file("/home/bestman/Desktop/mkey/key")
storePassword "androidkeys"
keyAlias "peade"
keyPassword "yes1234"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
compile 'com.edmodo:cropper:1.0.1'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.itextpdf:itextpdf:5.5.6'
// compile files('libs/commons-lang3-3.3.2.jar')
compile files('libs/dropbox-android-sdk-1.6.1.jar')
// compile files('libs/httpmime-4.0.3.jar')
compile files('libs/json_simple-1.1.jar')
compile files('libs/picasso-2.5.2.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}
compile project(':owncloud')
}
有兩個 build.gradle 文件。 一個在頂層支架中,另一個在模塊支架中。
下面是一個例子。
頂級 build.gradle:
https://github.com/nickbutcher/plaid/blob/master/build.gradle
模塊的 build.gradle:
https://github.com/nickbutcher/plaid/blob/master/app/build.gradle
android
塊應該在模塊的 build.gradle 中。 我猜您一定在頂級 build.gradle 中定義了導致錯誤的android
塊。
如果您的 android 塊在模塊的 build.gradle 中並使用谷歌服務,我會遇到同樣的問題,只需在 android 塊之前添加以下兩行:
apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services'
使緩存無效並重新啟動
轉到:文件/無效緩存/單擊無效並重新啟動這應該可以為您解決問題。
buildscript {
ext.versions = [
'compileSdk' : 27,
'targetSdk' : 27,
'buildTools' : '27.0.3',
'butterknife' : '8.8.1',
'glide' : '4.6.1',
'kotlin' : '1.2.21',
'retrofit' : '2.3.0',
'supportLibrary': '27.0.2'
]
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha01'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.