Android Studio:找不到“:app”的变体

Git*_*ita 5 android variant gradle android-studio android-gradle-plugin

我正在做我的最终项目,我想用 android studio 做项目,我对 android studio 真的很陌生,我遇到了一个错误,说没有找到“:app”的变体, 我尝试更改或下载另一个版本SDK,但它没有解决任何问题

这是 build.gradle 代码:

buildscript {

   repositories {

   google()  // Google's Maven repository

   mavenCentral()  // Maven Central repository

  }

   dependencies {
   
   classpath 'com.android.tools.build:gradle:4.2.1'

   classpath 'com.google.gms:google-services:4.3.15'

  }

}


allprojects {

   repositories {

   google()  // Google's Maven repository

   mavenCentral()  // Maven Central repository

 }

}
Run Code Online (Sandbox Code Playgroud)

这是 app/build.gradle 的代码:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}

android {
    namespace 'com.example.chatapp'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.chatapp"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildFeatures{
        viewBinding true
        compose true
    }
//    kotlinOptions {
//        jvmTarget = '1.8'
//    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.3.2'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.5.1'
    implementation platform('androidx.compose:compose-bom:2022.10.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material3:material3'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation 'com.intuit.sdp:sdp-android:1.0.6'
    implementation 'com.intuit.ssp:ssp-android:1.0.6'
    implementation 'com.makeramen:roundedimageview:2.3.0'
    androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
    androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
    debugImplementation 'androidx.compose.ui:ui-tooling'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'
}
Run Code Online (Sandbox Code Playgroud)

这是 Settings.gradle 的代码:

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
//    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
//    repositories {
//        google()
//        mavenCentral()
//    }
}
rootProject.name = "ChatApp"
include ':app'
Run Code Online (Sandbox Code Playgroud)

小智 0

解决方案:添加配置以解决“No Variants Found for ':app'”错误

第1步:打开Android Studio

启动 Android Studio 并打开您的项目。

第 2 步:访问运行/调试配置

单击顶部菜单中的“运行”。从下拉列表中选择“编辑配置”。

步骤 3:添加新配置

在“运行/调试配置”窗口中,找到现有配置。由于错误与应用程序执行有关,因此请重点关注“应用程序”模块配置。单击左上角的“+”(添加配置)。从下拉列表中选择“Android 应用程序”。

步骤 4:配置新配置

在“常规”选项卡中:从“模块”下拉列表中选择正确的“应用程序”模块。根据需要配置“部署”和“启动”选项。

第 5 步:申请并保存

点击右下角的“应用”进行保存。单击“确定”关闭窗口。

第 6 步:运行或调试

现在,运行或调试您的应用程序。使用绿色的“运行”按钮(或热键)和新添加的配置。此过程应该可以解决 Android Studio 中的“No Variants Found for ':app'”错误。