2
votes

today i got a source project and i get this error when i'm tyring to sync

All flavors must now belong to a named flavor dimension

My productflavors on module grade


    productFlavors {
            armv7 {
                ndk {
                    abiFilter "armeabi-v7a"
                }
                versionCode = 1
            }
        }

I tried putting these codes above it

flavorDimensions "default"

flavorDimensions "versionCode"

My build.gradle code:


        apply plugin: 'com.android.application'
    repositories {
    mavenCentral()
    jcenter()
    maven { url "https://jitpack.io" }
    }
    configurations {
    implementation.exclude module: 'support-v4'
    }
    dependencies {
    implementation 'com.google.android.gms:play-services-gcm:10.2.0'
    implementation 'com.google.android.gms:play-services-maps:10.2.0'
    implementation 'com.google.android.gms:play-services-vision:10.2.0'
    implementation 'com.android.support:support-core-ui:25.3.1'
    implementation 'com.android.support:support-compat:25.3.1'
    implementation 'com.android.support:support-core-utils:25.3.1'
    implementation 'com.android.support:support-v13:25.3.1'
    implementation 'com.android.support:palette-v7:25.3.1'
    implementation 'net.hockeyapp.android:HockeySDK:4.1.2'
    implementation 'com.googlecode.mp4parser:isoparser:1.0.6'
    implementation 'com.stripe:stripe-android:2.0.2'
    // telegraf
    implementation 'com.android.support:multidex:1.0.1'
    implementation 'com.android.support:design:25.3.1'
    implementation 'com.android.support:cardview-v7:25.3.1'
    implementation files('libs/android-viewbadger.jar')
    implementation files('libs/ksoap2-android-assembly-3.1.1-jar-with-dependencies.jar')
    // implementation 'co.ronash.android:pushe-base:1.2.0'
    implementation 'com.onesignal:OneSignal:3.+@aar'
    implementation 'com.github.QuadFlask:colorpicker:0.0.12'
    // Download, Catch, Etc... Images
    implementation 'com.squareup.picasso:picasso:2.5.2'
    }
    android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    useLibrary 'org.apache.http.legacy'
    defaultConfig.applicationId = "ir.imodares.telegraf"
    defaultConfig.manifestPlaceholders = [onesignal_app_id : "639e4454-4b40-4b07-a35d-eb24786b14bf",
    // Project number pulled from dashboard, local value is ignored.
    onesignal_google_project_number: "1039318212221"]
    sourceSets.main.jniLibs.srcDirs = ['./jni/']
    externalNativeBuild {
    ndkBuild {
    path "jni/Android.mk"
    }
    }
    dexOptions {
    jumboMode = true
    }
    lintOptions {
    checkReleaseBuilds false
    // Or, if you prefer, you can continue to check for errors in release builds,
    // but continue the build even when errors are found:
    abortOnError false
    }
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
    }
    signingConfigs {
    debug {
    storeFile file("config/release.keystore")
    storePassword "PASS"
    keyAlias "KEY"
    keyPassword "PASS"
    v2SigningEnabled false
    }
    release {
    storeFile file("config/release.keystore")
    storePassword "PASS"
    keyAlias "KEY"
    keyPassword "PASS"
    v2SigningEnabled false
    }
    }
    buildTypes {
    debug {
    debuggable true
    jniDebuggable true
    signingConfig signingConfigs.debug
    }
    release {
    debuggable false
    jniDebuggable false
    signingConfig signingConfigs.release
    minifyEnabled true
    shrinkResources false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    foss {
    debuggable false
    jniDebuggable false
    signingConfig signingConfigs.release
    }
    }
    defaultConfig.versionCode = 2000
    sourceSets.debug {
    manifest.srcFile 'config/debug/AndroidManifest.xml'
    }
    sourceSets.release {
    manifest.srcFile 'config/release/AndroidManifest.xml'
    }
    sourceSets.foss {
    manifest.srcFile 'config/foss/AndroidManifest.xml'
    }
    productFlavors {
    armv7 {
    ndk {
    abiFilter "armeabi-v7a"
    }
    versionCode = 1
    }
    }
    applicationVariants.all { variant ->
    def abiVersion = variant.productFlavors.get(0).versionCode
    variant.mergedFlavor.versionCode = defaultConfig.versionCode * 10 + abiVersion
    }
    defaultConfig {
    minSdkVersion 16
    targetSdkVersion 27
    versionName "3.18.0"
    multiDexEnabled true
    externalNativeBuild {
    ndkBuild {
    arguments "NDK_APPLICATION_MK:=jni/Application.mk", "APP_PLATFORM:=android-16"
    abiFilters "armeabi-v7a", "x86"
    }
    }
    }
    }
    apply plugin: 'com.google.gms.google-services'

My Project structure

My Project structure

My Project structure

My Project structure

1

1 Answers

1
votes

See https://developer.android.com/studio/build/build-variants#product-flavors.

You must explicitly name the flavor for armv7 dimension if you declare more than one flavor. But here you don't need more than one:

flavorDimensions "single-dimension-name-does-not-matter"
productFlavors {
  armv7 {
    ndk {
      abiFilter "armeabi-v7a"
    }
    versionCode = 1 + defaultConfig.versionCode * 10
  }
  all {
    versionCode = defaultConfig.versionCode * 10
  }
}

Now you will get 6 APKs:

  • telegraf-armv7-debug,
  • telegraf-armv7-release,
  • telegraf-armv7-foss,
  • telegraf-all-debug,
  • telegraf-all-release,
  • telegraf-all-foss

with appropriate versionCodes. You don't need to work with applicationVariants manually.

On the face of it, you actually don't need flavors at all to accomplish your task. You can use splits. And in this case you need the applicationVariants to set versionCode correctly ;)