Android Studio 无法启用预置:“No variants found for ':app'"错误

pgvzfuti  于 2023-08-07  发布在  Android
关注(0)|答案(1)|浏览(410)

我在看这个Google官方文档:https://developer.android.com/games/sdk/oboe/update-build-settings
它说:“在buildFeatures部分启用prefab选项”。我的build.gradle看起来像这样:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '30.0.3'
    ndkVersion "23.1.7779620"

    buildFeatures {
        prefab true
    }

    defaultConfig {
        applicationId "com.myapp.test"
        minSdkVersion 28
        targetSdkVersion 28

        externalNativeBuild {
            cmake {
                ...
            }
        }
    }

    buildTypes {
        release {
            ...
        }

        debug {
            ...
        }
    }

    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

字符串
问题:添加buildFeatures { prefab true }部分后,运行Gradle同步时出现以下错误。我没有做更多的修改,只是删除了这个部分,然后重新构建,但是我需要为使用这个特性的特定AAR依赖项启用预制件。
未找到“:app”的变体
问题是什么以及如何在Android Gradle项目中启用prefab功能?
Android Studio Flamingo| 2022.2.1补丁2,Gradle 7.4,Android Gradle插件4.2.2

shyt4zoc

shyt4zoc1#

您的问题可能只是gradle版本问题。您似乎正在使用旧版本的AGP(Android Gradle插件)。尝试将其从4.2.2升级到7.2.2。
如果您要集成到应用程序中的AAR是双簧管,我遵循相同的步骤you mentioned将其添加到项目中。我能够成功地构建项目并在我的.cpp文件中使用双簧管。
我的环境配置:

Android Studio Chipmunk | 2021.2.1 Patch 2
Gradle version : 7.3.3
AGP : 7.2.2
kotlin : 1.7.10

字符串
以下是我的应用程序的build.gradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    compileSdk 33

    buildFeatures {
        prefab true
    }

    defaultConfig {
        applicationId "com.test.oboetester"
        minSdk 23
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags '-std=c++17'
                arguments "-DANDROID_STL=c++_shared"
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    externalNativeBuild {
        cmake {
            path file('src/main/cpp/CMakeLists.txt')
            version '3.18.1'
        }
    }
    buildFeatures {
        viewBinding true
    }

    sourceSets {
        main {
            assets.srcDirs = ['src/main/assets/']
        }
    }

}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

    implementation 'commons-io:commons-io:2.13.0'

    implementation 'com.google.oboe:oboe:1.5.0'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}


项目级别build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME


您也可以通过Google查询this sample project

相关问题