[英]Add Module from GIT to Android Studio throws “buildToolsVersion is not specified” error
[英]Android Studio - Error Module not specified
我是 Android/Java 開發的新手,購買了一本書 Java Programming for Android Developers For Dummies,第 2 版。
這帶有一個代碼示例部分http://users.drew.edu/bburd/Java4Android/ (第 02_01 章)我知道這本書已經有幾年歷史了,因此代碼示例將是。 但是,我在讓代碼示例在 Android Studio 4.1.2 上運行時遇到了很多問題。
我可以導入項目並同步 Gradle 文件。 當我這樣做時,它會在底部出現一個綠色勾號。 奇怪的是,它旁邊顯示失敗並顯示以下消息。
Gradle sync failed: Unsupported method: SyncIssue.getMultiLineMessage().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
Consult IDE log for more details (Help | Show Log) (1 s 443 ms)
我的 build.gradle 文件如下
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我已經閱讀了許多具有類似問題的帖子,並進行了各種修復。 似乎沒有任何工作,所以任何人都可以闡明發生了什么嗎? 我還在 3 台不同的 PC 上下載了 android 工作室,以防它出現某種錯誤。
謝謝
我應該說那里的文件非常過時,每個項目都很難。 但是,如果您仍然想在這里構建項目,您可以做一些事情。
查找文件gradle-wrapper.properties
並用它更新它
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
然后移動到項目級build.gradle
文件(app 目錄里面有兩個,一個在根目錄下,使用根目錄)
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
然后移動到應用程序級別build.gradle
並使用此更新
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.allyourcode.a02_01"
minSdkVersion 15
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
testImplementation 'junit:junit:4.13.1'
}
然后同步項目,讓 Android 工作室發揮它的魔力。
正如堆棧跟蹤所說,您應該升級您的 Gradle 版本。 您正在使用“舊”書,其中示例是使用舊版本的 Android Studio 構建的,該版本很好地支持舊版本的 Gradle。 但是 4.1 是最新版本,不能很好地支持許多舊的 Gradle 功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.