简体   繁体   English

Android Studio - 未指定错误模块

[英]Android Studio - Error Module not specified

i'm a newbie to Android/Java development and purchased a book Java Programming for Android Developers For Dummies, 2nd Edition.我是 Android/Java 开发的新手,购买了一本书 Java Programming for Android Developers For Dummies,第 2 版。

This comes with a code samples section http://users.drew.edu/bburd/Java4Android/ (chapter 02_01) I understand the book is a few years old hence so the code samples will be.这带有一个代码示例部分http://users.drew.edu/bburd/Java4Android/ (第 02_01 章)我知道这本书已经有几年历史了,因此代码示例将是。 However, i'm having massive problems getting the code samples to run on Android Studio 4.1.2.但是,我在让代码示例在 Android Studio 4.1.2 上运行时遇到了很多问题。

I can import the project and sync the Gradle files.我可以导入项目并同步 Gradle 文件。 When I do it appears with a green tick at the bottom.当我这样做时,它会在底部出现一个绿色勾号。 Oddly it says failed next to that with the following message.奇怪的是,它旁边显示失败并显示以下消息。

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)

My build.gradle file is as follows我的 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
}

Also if I try and run the project I see this screen另外,如果我尝试运行该项目,我会看到此屏幕错误信息

主屏幕

I've read many posts with similar issues and worked through various fixes.我已经阅读了许多具有类似问题的帖子,并进行了各种修复。 None seemed to work so can anyone shed any light on what's happening please?似乎没有任何工作,所以任何人都可以阐明发生了什么吗? I've also downloaded android studio on 3 different PC's incase its a bug of some sort.我还在 3 台不同的 PC 上下载了 android 工作室,以防它出现某种错误。

Thank you谢谢

I should say the files in there are very outdated, and you will have very hard time, with every project.我应该说那里的文件非常过时,每个项目都很难。 But if you still want to build the project here are a few things you can do.但是,如果您仍然想在这里构建项目,您可以做一些事情。

look for the file gradle-wrapper.properties and update it with this查找文件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

Then move to project level build.gradle file (there are two one inside app directory and one on the root directory, use the root directory)然后移动到项目级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
}

Then move to app level build.gradle and update it with this然后移动到应用程序级别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'
}

And then sync the project and let Android studio do its magic.然后同步项目,让 Android 工作室发挥它的魔力。

As the stack traces say, you should upgrade your Gradle version.正如堆栈跟踪所说,您应该升级您的 Gradle 版本。 You are using an "old" book where the samples have been build with an old version of Android Studio that supports well that old version of Gradle.您正在使用“旧”书,其中示例是使用旧版本的 Android Studio 构建的,该版本很好地支持旧版本的 Gradle。 But 4.1 is a recent version and does not support well many old Gradle features.但是 4.1 是最新版本,不能很好地支持许多旧的 Gradle 功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM