1

I have got this sample project that, with app module and a lib(mylibrary) module, working properly before with the older version gradle. Here are the working gradle code copies:

app/build.grale

apply plugin: 'com.android.application'
android {
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "xyz.sahildave.flavoredlibrary"
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
        app1521 {
            minSdkVersion 15
            targetSdkVersion 21
            compileSdkVersion 21
            applicationId "xyz.sahildave.flavoredlibrary.app1521"
        }
        app1524 {
            minSdkVersion 15
            targetSdkVersion 24
            compileSdkVersion 24
            applicationId "xyz.sahildave.flavoredlibrary.app1524"
        }
    }
}

configurations {
    app1521DebugCompile
    app1524DebugCompile
}

dependencies {
    app1521DebugCompile project(path: ':mylibrary', configuration: 'sdk1521Debug')
    app1524DebugCompile project(path: ':mylibrary', configuration: 'sdk1524Debug')
    app1521DebugCompile 'com.android.support:appcompat-v7:21.0.3'
    app1524DebugCompile 'com.android.support:appcompat-v7:24.2.0'
}

mylibrary/build.gradle

apply plugin: 'com.android.library'

android {
    buildToolsVersion "24.0.2"

    publishNonDefault true

    defaultConfig {
        versionCode 1
        versionName "1.0"
    }
    productFlavors {
        sdk1521 {
            minSdkVersion 15
            targetSdkVersion 21
            compileSdkVersion 21
        }
        sdk1524 {
            minSdkVersion 15
            targetSdkVersion 24
            compileSdkVersion 24
        }
    }
}

dependencies {
    sdk1524Compile 'com.android.support:appcompat-v7:24.2.1'
    sdk1521Compile 'com.android.support:appcompat-v7:21.0.3'
}

gradle/wrapper/gradle-wrapper.properties

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

project/build.gradle

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
    }
}

However, the happiness ends here when I try to upgrade them to the latest gradle version, it is reporting below issue

ERROR: Unable to resolve dependency for ':app@app1521DebugAndroidTest/compileClasspath': Could not resolve project :mylibrary.
Show Details
Affected Modules: app

Here are my upgraded code, all I did was

  1. upgrade all compile/target SDKVersion to 29, minSdkVersion to 21
  2. add flavorDimensions('main)
  3. upgrade build tool version to "29.0.2"
  4. upgrade gradle to gradle-5.6.4-all.zip
  5. upgrade gradle script to "classpath 'com.android.tools.build:gradle:3.6.1'"

Really appreciate if you can help me to solve the issue.

app/build.grale

apply plugin: 'com.android.application'

android {
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "xyz.sahildave.flavoredlibrary"
        versionCode 1
        versionName "1.0"
        minSdkVersion 21
        targetSdkVersion 28
        compileSdkVersion 28
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions("main")
    productFlavors {
        app1521 {
            dimension "main"
            applicationId "xyz.sahildave.flavoredlibrary.app1521"
        }
        app1524 {
            dimension "main"
            applicationId "xyz.sahildave.flavoredlibrary.app1524"
        }
    }
}

configurations {
    app1521DebugImplementation
    app1524DebugImplementation
}

dependencies {
    app1521DebugImplementation project(path: ':mylibrary', configuration: 'sdk1521Debug')
    app1524DebugImplementation project(path: ':mylibrary', configuration: 'sdk1524Debug')
    app1521DebugImplementation 'com.android.support:appcompat-v7:21.0.3'
    app1524DebugImplementation 'com.android.support:appcompat-v7:24.2.0'
}

mylibrary/build.gradle

apply plugin: 'com.android.library'

android {
    buildToolsVersion "29.0.2"

    publishNonDefault true

    defaultConfig {
        versionCode 1
        versionName "1.0"
        minSdkVersion 21
        targetSdkVersion 28
        compileSdkVersion 28
    }
    flavorDimensions("main")
    productFlavors {
        sdk1521 {
            dimension "main"
        }
        sdk1524 {
            dimension "main"
        }
    }
}

dependencies {
    sdk1524Implementation 'com.android.support:appcompat-v7:24.2.1'
    sdk1521Implementation 'com.android.support:appcompat-v7:21.0.3'
}

gradle/wrapper/gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Panda World
  • 1,704
  • 1
  • 20
  • 28

1 Answers1

1

Today I met a similar problem as you posted, so let's try if this can help you. I carefully check your gradle file and find these two section.

In your library gradle file, the product flavors name are: sdk1521 and sdk1524. In your app gradle file, the product flavors name are: app1521 and app1524.

I guess this caused the gradle sync error.

There are two solutions for this.

The simple one this uniform the product flavor nameof app and library. Call them version1521 and version1524 , whatever. Just remember to keep'em the same.

The second one is a more standard and general solution. For most of the cases, we cannot name the product flavor as our wish, especially when we need to use some company's sdk. In this situation, you can add this

matchingFallbacks = ["sdk1521"]

For more details, you can look at this problem:Include library with flavors android

I wish my experience can help you.

Good luck!

rookieze
  • 11
  • 1