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
- upgrade all compile/target SDKVersion to 29, minSdkVersion to 21
- add flavorDimensions('main)
- upgrade build tool version to "29.0.2"
- upgrade gradle to gradle-5.6.4-all.zip
- 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