2

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 Answers1

1

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 ;)

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • thanks . i replaced the codes but now i get some other errors , my libraries can't load ... Failed to resolve: com.android.support:multidex:1.0.2 and etc ... – Danial RiCaRoS Nov 26 '18 at 11:25
  • Most likely, this is a different problem. The **build.gradle** you posted refers to **multidex:1.0.1**. You probably upgraded to **1.0.2** because some dependency got upgraded, too. I hope https://stackoverflow.com/a/50794342/192373 will help you. – Alex Cohn Nov 26 '18 at 11:49
  • It's not only multi dex , all my dependecies have errors , i think 20 libraries – Danial RiCaRoS Nov 26 '18 at 12:02
  • Do you think it's related to the flavors? If not, please open a separate question, and provide more info, e.g. which components require **com.android.support:multidex:1.0.2** (remind you, your project imports **com.android.support:multidex:1.0.1**) – Alex Cohn Nov 26 '18 at 13:46
  • worth noting that all flavors don't get built at the same time as of Android Studio v3.5. You will need to select the one you want to have build by going to `Build > Select Build Variant` and selecting the `Active Build Variant` drop-down in the popup. – lasec0203 Sep 10 '19 at 13:00
  • @lasec0203 no, they are not built, and never were AFAICR. Today, AS does perform some optimization and doesn't waste time 'preparing' to build inactive flavors. – Alex Cohn Sep 10 '19 at 14:36