简体   繁体   English

模块“app”是一个没有构建变体的 Android 项目

[英]The module 'app' is an Android project without build variants

I am getting below error while importing android project.导入android项目时出现以下错误。

Error:The module 'app' is an Android project without build variants, and cannot be built.错误:模块“app”是一个没有构建变体的 Android 项目,无法构建。 Please fix the module's configuration in the build.gradle file and sync the project again.请在 build.gradle 文件中修复模块的配置并再次同步项目。

Gradle file code. Gradle 文件代码。

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"

defaultConfig {
    applicationId "com.djalel.android.bilal"
    minSdkVersion 9
    targetSdkVersion 25
    versionCode 4
    versionName "1.3"
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt')
    }
}

aaptOptions {
    cruncherEnabled = false
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:25.3.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:25.3.1'
implementation 'com.android.support:support-v4:25.3.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
implementation 'com.jakewharton.timber:timber:3.1.0'
}
repositories {
mavenCentral()
}

I checked with working gradle file as well but getting same error in this project.我也检查了工作 gradle 文件,但在这个项目中遇到了同样的错误。

Above gradle file code seems to be perfect.上面的 gradle 文件代码似乎很完美。 Probably its nothing to do with app/build.gradle (Module:app).可能与 app/build.gradle (Module:app) 无关。 Just open other build.gradle (Project:Android) file in Project window and verify your Android Studio version it must be same as yours.只需在项目窗口中打开其他 build.gradle (Project:Android) 文件并验证您的 Android Studio 版本它必须与您的相同。

I replaced from:我从:

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

to my Android Studio v3.0.1 in my case:到我的 Android Studio v3.0.1 就我而言:

dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

Press "Try Again" to Sync gradle file.按“再试一次”以同步 gradle 文件。 This resolved my problem with a successful build.这通过成功构建解决了我的问题。

For me, this issue appeared when I updated Android Studio to version 3.3.对我来说,当我将 Android Studio 更新到 3.3 版时出现了这个问题。
Disabling experimental feature " Only sync the active variant " fixes it:禁用实验功能“仅同步活动变体”修复它:

在此处输入图片说明

Try use command line to run gradlew tasks to see why the build would fail.尝试使用命令行运行gradlew tasks以查看构建失败的原因。

In my case:就我而言:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
 platforms;android-27 Android SDK Platform 27
 build-tools;27.0.3 Android SDK Build-Tools 27.0.3

So I just ran Go to Android\\sdk\\tools\\bin sdkmanager --licenses to accept licenses and then the build passed in command line.所以我只是运行 Go to Android\\sdk\\tools\\bin sdkmanager --licenses来接受许可证,然后构建在命令行中传递。

I think Android Studio is crying for the wrong issue.我认为 Android Studio 正在为错误的问题而哭泣。 So you may check the real output in command line and find what is happening.因此,您可以检查命令行中的真实输出并找出发生了什么。

Just install the Android SDK platform package through SDK Manager in Android Studio, relevant to your Compile SDK version.只需通过 Android Studio 中的 SDK Manager 安装 Android SDK 平台包,与您的编译 SDK 版本相关。 It will prompt you to install the package as well as to accept the license.它会提示您安装软件包并接受许可证。 After that just sync the gradle, it will resolve the issue.之后只需同步gradle,它将解决问题。

You must update your dependencies in build.grade in the buildscript block:您必须在buildscript块中的build.grade中更新您的依赖

classpath 'com.android.tools.build:gradle:3.1.0'

to:到:

classpath 'com.android.tools.build:gradle:3.4.2'

If this error occurs for other module than 'app'如果“app”以外的其他模块发生此错误

Remove gradle variable from that module's build.gradle like从该模块的 build.gradle 中删除 gradle 变量,例如

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

& replace it actual value & 替换它的实际值

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71"

Clean Project -> Rebuild Project清理项目 -> 重建项目

I had this issue in my library project.我在我的图书馆项目中遇到了这个问题。 I solved it by adding我通过添加解决了它

buildscript {
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

To the beginning of build.gradlebuild.gradle的开头

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

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