0

Android Studio 3.0

I have 3 build types: "release" and "dev"

project/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

settings.gradle

include ':app', ':common'

app/build.gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:26.1.0'

     kapt "com.github.bumptech.glide:compiler:$GLIDE_VERSION"
    kapt "com.jakewharton:butterknife-compiler:$BUTTER_KNIFE_VERSION"

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    compile project(':common')
}

But when I try to build I get the next error:

Unable to resolve dependency for ':app@dev/compileClasspath': Could not resolve project :common.

Could not resolve project :common.
Required by:
    project :app
 > Unable to find a matching configuration of project :common:
     - Configuration 'debugApiElements':
         - Required com.android.build.api.attributes.BuildTypeAttr 'dev' and found incompatible value 'debug'.
         - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.

P.S. On Android Studio 2.3.3 my project success build and run

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Alexei
  • 14,350
  • 37
  • 121
  • 240

2 Answers2

3

Seems like a bug in the Gradle build process, try to change:

 android {
  buildTypes {
      release {
          ...
      }
      dexOptions {
          ...
        // release & debug is in project animators
      }
      dev {
        matchingFallbacks = ["debug"]
      }
    }
}

dependencies {
'implementation project(':common')
}
Nawrez
  • 3,314
  • 8
  • 28
  • 42
  • Not help: Error:Unable to resolve dependency for ':app@dev/compileClasspath': Failed to transform file 'common-release.aar' to match attributes {artifactType=android-exploded-aar} using transform ExtractAarTransform Open File
    Show Details
    – Alexei Nov 01 '17 at 07:46
  • Not help: Error:Unable to resolve dependency for ':app@dev/compileClasspath': Could not resolve project :common. Open File
    Show Details
    – Alexei Nov 01 '17 at 08:07
  • 1
    Maybe it's because I has not buildType=debug? I have 2 buildType=relase and buildType=dev – Alexei Nov 01 '17 at 08:07
  • Not help: :app:javaPreCompileDev :app:compileDevJavaWithJavac\dev\Myproject\app\src\main\java\com\myproject\android\customer\api\model\CatalogAdapteJsonDeserilizer.java:9: error: package com.myproject.android.customer.common.util does not exist import com.myproject.android.customer.common.util.GsonUtil; – Alexei Nov 01 '17 at 08:22
  • I am investigating on a solution : can you try the last one? – Nawrez Nov 01 '17 at 10:11
  • Not help: Error:Unable to resolve dependency for ':app@dev/compileClasspath': Could not resolve project :common. Open File
    Show Details
    – Alexei Nov 01 '17 at 10:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/157985/discussion-between-hadjkhelil-nawrez-and-alexei). – Nawrez Nov 01 '17 at 11:15
  • I found solution. In buildType=dev I must to add the next: 'matchingFallbacks = ["debug"]'. In dependencies I must add: 'implementation project(':common')' – Alexei Nov 01 '17 at 12:13
  • the last one didn't help you ? – Nawrez Nov 01 '17 at 13:30
  • I have edited it again : is it that the right answer ? – Nawrez Nov 01 '17 at 14:31
  • 1
    Yes, now it help. Thanks. – Alexei Nov 01 '17 at 14:34
1

this problem maybe cause by miss match buildTypes between module build.gradle files

app build.gradle

android {
    ...

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        dev {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

common build.gradle [incorrect]

android {
    ...

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    // miss debug and dev config block (the reason of this problem)

    }
}

common build.gradle [correct]

android {
    ...

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        dev {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
L.C
  • 148
  • 1
  • 7