![](/img/trans.png)
[英]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.