首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android Studio -未指定错误模块

Android Studio -未指定错误模块
EN

Stack Overflow用户
提问于 2021-02-12 07:43:10
回答 2查看 427关注 0票数 0

我是一个Android/Java开发的新手,我买了一本书“Java Programming for Android Developers For Dummies,第二版”。

这本书附带了代码示例部分http://users.drew.edu/bburd/Java4Android/ (02_01章),我知道这本书已经有几年的历史了,因此代码示例将是。然而,我在Android Studio 4.1.2上运行代码示例时遇到了大量问题。

我可以导入项目并同步Gradle文件。当我这样做的时候,它会在底部出现一个绿色的勾号。奇怪的是,它在旁边显示失败,并显示以下消息。

代码语言:javascript
运行
复制
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文件如下所示

代码语言:javascript
运行
复制
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 studio,以防它是某种bug。

谢谢你

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-02-12 08:14:25

我应该说里面的文件已经非常过时了,而且你在每个项目上都会遇到很大的困难。但是,如果你仍然想要构建这个项目,这里有一些你可以做的事情。

查找文件gradle-wrapper.properties并用下面的代码更新它

代码语言:javascript
运行
复制
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目录内,一个在根目录下,使用根目录)

代码语言:javascript
运行
复制
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并使用以下内容进行更新

代码语言:javascript
运行
复制
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 studio施展它的魔力。

票数 2
EN

Stack Overflow用户

发布于 2021-02-12 08:06:03

正如堆栈跟踪所说,您应该升级您的Gradle版本。您正在使用一本“旧”书,其中的示例是使用Android Studio的旧版本构建的,该版本很好地支持旧版本的Gradle。但4.1是一个新版本,并不能很好地支持许多旧的Gradle特性。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66164623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档