Violet Giraffe
Violet Giraffe

Reputation: 33579

Cannot enable prefab: "No variants found for ':app'" error

I'm following this official Google doc: https://developer.android.com/games/sdk/oboe/update-build-settings

It says: "Enable the prefab option in the buildFeatures section". My build.gradle looks like this:

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"
        }
    }
}

Problem: after adding the buildFeatures { prefab true } section, I get the following error when running Gradle sync. I did not make any more changes, just remove this section and it builds again, but I need to enable prefabs for a specific AAR dependency that uses this feature.

No variants found for ':app'

What's the problem and how to enable the prefab feature in an Android Gradle project?

I use the latest Android Studio Flamingo | 2022.2.1 Patch 2, Gradle 7.4, Android Gradle Plugin 4.2.2

Upvotes: 0

Views: 377

Answers (1)

CLay
CLay

Reputation: 19

Your problem could be just a gradle version issue. You seem to be using an old version of the AGP (Android Gradle Plugin). Try upgrading it from 4.2.2 to 7.2.2.

If the AAR you're integrating into your app is Oboe, I followed the same steps you mentioned to add it into my project. I was able to build the project successfully and use Oboe in my .cpp files.

My environment config:

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

Here's my app's 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'
}

project level 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

You can also refer this sample project by Google

Upvotes: -1

Related Questions