I'm getting build errors in Android project caused by the following dependency:
implementation "com.algolia:instantsearch-android:2.5.1"
It helps to upgrade to 2.8.0 but I would prefer not since it requires minSdk 21.
Gradle 6.5
Android Gradle Plugin: 4.0.2
Kotlin 1.3.72
Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:releaseCompileClasspath'.
> Could not resolve com.algolia:algoliasearch-client-kotlin-common:1.4.0.
Required by:
project :app > com.algolia:instantsearch-android:2.5.1
> No matching variant of com.algolia:algoliasearch-client-kotlin-common:1.4.0 was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- Variant 'metadata-api' capability com.algolia:algoliasearch-client-kotlin-common:1.4.0:
- Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
- Other compatible attribute:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
I had a somewhat similar situation, but my case was slightly different than yours. I'll explain the difference between my situation and yours along with what I did to correct the situation. This might be a clue to your problem, but I'll leave it to you to see if it's applicable or helpful.
In my case, the error about incompatibility said that that the consumer had an attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and that it found that my dependency had and attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'. Please note that I don't have the exact text and the message talked about other attributes and components. But when I parsed the message the obvious difference was the 'androidJvm' and 'jvm'.
What I did wrong, was that I was trying to add an android library dependency to a java library, and of course, that's not allowed. I had applied the 'java-library' plugin to the dependency instead of applying the 'com.android.plugin' to that library. I corrected that and the problem when away.
In your case, it looks like you have the difference 'common' versus 'androidJvm'. Unfortunately, I don't know what the platform type 'common' is referring to. It's probably due to the type of plugin you've got applied. Hopefully this helps you!
Related
After update Android Studio and create the first project I see:
A problem occurred configuring root project 'Demo Sample'.
Could not resolve all files for configuration ':classpath'.
Could not resolve com.android.tools.build:gradle:7.4.0-rc03.
Required by:
project : com.android.application:com.android.application.gradle.plugin:7.4.0-rc03
project : com.android.library:com.android.library.gradle.plugin:7.4.0-rc03
No matching variant of com.android.tools.build:gradle:7.4.0-rc03 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5' but:
- Variant 'apiElements' capability com.android.tools.build:gradle:7.4.0-rc03 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
- Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.0-rc03 declares a runtime of a component, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
- Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.0-rc03 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
- Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.0-rc03 declares a runtime of a component, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
I fixed:
Step 1, open notifications:
Step 2, click select the Gradle JDK Location
Step 3 Select Embedded JDK
Am unable to get around this error after upgrading flutter version to 3.0.4. from version 2.10
Error
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':qr_code_scanner'.
> Could not resolve all artifacts for configuration ':qr_code_scanner:classpath'.
> Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10.
Required by:
project :qr_code_scanner
> The consumer was configured to find a runtime of a component compatible with Java 11, packaged as a jar, and its dependencies declared externally. However we cannot choose between the following variants of org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10:
- gradle70JavadocElements
- gradle70RuntimeElements
- gradle70SourcesElements
- javadocElements
- runtimeElementsWithFixedAttribute
- sourcesElements
All of them match the consumer attributes:
- Variant 'gradle70JavadocElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10 declares a runtime of a component, and its dependencies declared externally:
- Unmatched attributes:
- Provides documentation but the consumer didn't ask for it
- Provides javadocs but the consumer didn't ask for it
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Provides attribute 'org.gradle.plugin.api-version' with value '7.0' but the consumer didn't ask for it
- Provides release status but the consumer didn't ask for it
- Variant 'gradle70RuntimeElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10 declares a runtime of a component compatible with Java 8, packaged as a jar, and its dependencies declared externally:
- Unmatched attributes:
- Provides a library but the consumer didn't ask for it
- Provides attribute 'org.gradle.jvm.environment' with value 'standard-jvm' but the consumer didn't ask for it
- Provides attribute 'org.gradle.plugin.api-version' with value '7.0' but the consumer didn't ask for it
- Provides release status but the consumer didn't ask for it
- Variant 'gradle70SourcesElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10 declares a runtime of a component, and its dependencies declared externally:
- Unmatched attributes:
- Provides documentation but the consumer didn't ask for it
- Provides sources but the consumer didn't ask for it
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Provides attribute 'org.gradle.plugin.api-version' with value '7.0' but the consumer didn't ask for it
- Provides release status but the consumer didn't ask for it
- Variant 'javadocElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10 declares a runtime of a component, and its dependencies declared externally:
- Unmatched attributes:
- Provides documentation but the consumer didn't ask for it
- Provides javadocs but the consumer didn't ask for it
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Provides release status but the consumer didn't ask for it
- Variant 'runtimeElementsWithFixedAttribute' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10 declares a runtime of a component compatible with Java 8, packaged as a jar, and its dependencies declared externally:
- Unmatched attributes:
- Provides a library but the consumer didn't ask for it
- Provides attribute 'org.gradle.jvm.environment' with value 'standard-jvm' but the consumer didn't ask for it
- Provides release status but the consumer didn't ask for it
- Variant 'sourcesElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10 declares a runtime of a component, and its dependencies declared externally:
- Unmatched attributes:
- Provides documentation but the consumer didn't ask for it
- Provides sources but the consumer didn't ask for it
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Provides release status but the consumer didn't ask for it
The following variants were also considered but didn't match the requested attributes:
- Variant 'apiElementsWithFixedAttribute' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10 declares a component compatible with Java 8, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component and the consumer needed a runtime of a component
- Variant 'gradle70ApiElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10 declares a component compatible with Java 8, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component and the consumer needed a runtime of a component
> Failed to notify project evaluation listener.
> Could not get unknown property 'android' for project ':qr_code_scanner' of type org.gradle.api.Project.
> Could not get unknown property 'android' for project ':qr_code_scanner' of type org.gradle.api.Project.
I dont understand where the issue is. Any assistance will be much appreciated
gradle file
buildscript {
ext.kotlin_version = '1.5.10'
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.4' // Google Services plugin
}
}
allprojects {
repositories {
google()
jcenter()
}
}
Flutter doctor output
[√] Flutter (Channel stable, 3.0.4, on Microsoft Windows [Version 10.0.19044.1889], locale en-us)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[√] Chrome - develop for the web
[√] Android Studio (version 2021.2)
[√] VS Code (version 1.67.0)
[√] Connected device (3 available)
[√] HTTP Host Availability
i have tried changing kotlin versions manually but didn't work, also tried building the app from clean workstation and got the same error, reduced the qr scanner version from 4.0 to 1.0 but no fruits
This will work :)
ext.kotlin_version = '1.7.10'
classpath 'com.android.tools.build:gradle:4.2.0'
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
I am working on a project which I used koin but I had the dependencies added from jcenter and not maven.
Since jcenter is going to get deprecated I want to transfer to maven.
So i removed Jcenter and I added mavenCentral().
The thing is that when i try to sync my project this error occures :
Could not resolve io.insert-koin:koin-androidx-scope:2.2.3.
Possible solution:
Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Firstly, I followed the tutorial of insert-koin.io but nothing helped. When I try to press Run then the error of course still occurs.
Execution failed for task ':domain:compileKotlin'.
Could not resolve all files for configuration ':domain:compileClasspath'.
Could not resolve io.insert-koin:koin-androidx-scope:2.2.3.
Required by:
project :domain
> No matching variant of io.insert-koin:koin-androidx-scope:2.2.3 was found. The consumer was configured to find an API of a library compatible with Java 11, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
- Variant 'releaseApiPublication' capability io.insert-koin:koin-androidx-scope:2.2.3 declares an API of a library, and its dependencies declared externally:
- Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, preferably in the form of class files
- Other compatible attributes:
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')
- Variant 'releaseRuntimePublication' capability io.insert-koin:koin-androidx-scope:2.2.3 declares a runtime of a library, and its dependencies declared externally:
- Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, preferably in the form of class files
- Other compatible attributes:
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Does anybody have any idea what i should do ?
Still you should be able to use jcenter (read only) in gradle file if your artifacts not present in other repositories.
You should check the section in your build.gradle.
You need mavenCentral()
// Add Maven Central to your repositories if needed
repositories {
mavenCentral()
}
Add mavenCentral() if it is not in settings.gradle as below.
pluginManagement {
repositories {
...
mavenCentral()
}
If your impl is like implementation "org.koin:koin-android:$XX", replace it with implementation "io.insert-koin:koin-android:$koin_version" in app build.gradle.
Koin packages are now on maven central.
please refer to the new setup instructions for it
https://insert-koin.io/docs/setup/v3.2
So the gradle group name changed from org.koin to io.insert-koin
And here is an example :
implementation "io.insert-koin:koin-core:$koin_version"
I uploaded a shared module from a Kotlin Multiplatform to JFrogs Artifactory. The goal is to use this shared module in another android app project and share business logic across projects.
I tried to only upload the android variant of the shared module - for the current purpose the iOS variant are not needed to be uploaded to artifactory.
I wrote this code in the build.gradle.kts of the shared module in the Kotlin Multiplatform project:
plugins {
kotlin("multiplatform")
id("com.android.library")
id("kotlin-android-extensions")
kotlin("plugin.serialization")
// plugins required for uploading to artifactory
id("maven-publish")
id("com.jfrog.artifactory") version "4.13.0"
}
.
.
.
artifactory {
setContextUrl("https://rbartifactory.jfrog.io/artifactory/")
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<DoubleDelegateWrapper> {
setProperty("repoKey", "App-Shared-Test-KMP")
setProperty("username", "<MY-USERNAME>")
setProperty("password", "<MY-USER-API-KEY>")
setProperty("maven", true)
})
defaults(delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod("publications", arrayOf(
"androidDebug", "androidRelease", "kotlinMultiplatform", "metadata"
))
})
})
}
In the settings.gradle I also added enableFeaturePreview("GRADLE_METADATA").
To implement that gradle I read this article here: https://medium.com/vmware-end-user-computing/publishing-kotlin-multiplatform-artifacts-to-artifactory-maven-a283ae5912d6
Because I want this shared module to be used in other Android App projects I skip all steps regarding the maven publications of the iOS part.
The upload to artifactory is successful with ./gradlew artifactoryPublish:
I try to consume it in the android app and for this I added the connection to artifactory and to this repo in the android app build.gradle file like suggested in artifactory when using "Set Me Up" button. And I also link finally the framework in the dependencies block of the build.gradle of the Android App:
dependencies {
.
.
.
implementation(group: 'com.rb.kmp_test_shared_lib', name: 'shared', version: '1.0.4', ext: 'jar')
}
In the android app I run in this error here:
Could not determine the dependencies of task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
> Could not resolve com.rb.kmp_test_shared_lib:shared:1.0.4.
Required by:
project :app
> No matching variant of com.rb.kmp_test_shared_lib:shared:1.0.4 was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- Variant 'commonMainMetadataElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
- Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
- Other compatible attribute:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Variant 'iosArm64ApiElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
- Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
- Other compatible attribute:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Variant 'iosArm64MetadataElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
- Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
- Other compatible attribute:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Variant 'iosX64ApiElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
- Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
- Other compatible attribute:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Variant 'iosX64MetadataElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
- Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
- Other compatible attribute:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Variant 'metadataApiElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
- Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
- Other compatible attribute:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Why did I get this error when trying to use that library? How can I exactly consume Kotlin Multiplatform libraries from jfrogs artifactory in other android apps?
It is maybe because of the jars which get uploaded by running ./gradlew artifactoryPublish? There should be aar files uploaded in artifactory?
Maybe this lines here did not work anymore? The article I read to implement that was written in May 2020 and since then there were some major Kotlin Multiplatform releases:
defaults(delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod("publications", arrayOf(
"androidDebug", "androidRelease", "kotlinMultiplatform", "metadata"
))
})
I guess instead of androidDebug and androidRelease I need to put there some other attributes in.
I am really grateful for every help with this - I am looking for hours for an solution.
For android apps aar libraries are necessary - so I need to upload air files to artifactory.
To upload aar files I add a publishing block to the build.gradle.kts of my shared module in the KMP project:
publishing {
publications {
create<MavenPublication>("aar") {
artifact("$buildDir/outputs/aar/${project.name}-release.aar")
}
}
}
I also changed the artifactory block and replace the defaults part to this:
defaults(delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod("publications", "aar")
setProperty("publishArtifacts", true)
})
After this changes I clean the project and build all artifacts:
./gradlew clean
./gradlew :shared:build
When all assets build successful (and aar files are in the outputs folder of the KMP project) I upload the aar's successful with ./gradlew artifactoryPublish and then I can simply use them in another android app.
The answer from Vadim of the question Convert to gradle-kotlin-dsl Jfrog.Artifactory config helped me with writing the code to upload aar's to artifactory.
I am experimenting with Android's Dynamic Feature Modules (a.k.a. on demand modules) on the side of the project I am working on.
In my PoC (proof-of-concept) project, Dynamic Feature Modules (DFM) work fine and gradle builds the project with no issue. After finishing with my PoC, I decided to apply it to an existing project. However, gradle failed building the project with:
Could not determine the dependencies of task ':my-app:checkSomeBuildFlavorDebugLibraries'.
> Could not resolve all task dependencies for configuration ':my-app:someBuildFlavorDebugMetadataValues'.
> Could not resolve project :features:myDynamicFeatureModule.
Required by:
project :my-app
> Cannot choose between the following variants of project :features:myDynamicFeatureModule:
- anotherBuildFlavorDebugAndroidTestCompile
- anotherBuildFlavorDebugAndroidTestRuntime
- ...
All of them match the consumer attributes:
- Variant 'anotherBuildFlavorDebugAndroidTestCompile' capability myproject.features:myDynamicFeatureModule:unspecified:
- Unmatched attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Metadata' but no value provided.
- Required endpoint 'someBuildFlavor' but no value provided.
- Found org.jetbrains.kotlin.localToProject 'local to :features:myDynamicFeatureModule' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.
- Variant ...
Note that this error is quite long, iterating through all possible flavors.
What I have tried, but did not work:
I added exactly the same flavors that base module (my-app) has in my dynamic module
In build.gradle of my DFM, I tried to set configuration explicitly like : implementation project(path: ':my-app', configuration: 'default') and also configuration: 'someFlavor'
In build.gradle of the base module (my-app) I used missingDimensionStrategy 'mydimension', 'myflavor'
Building from Android Studio and also from terminal
Removing dependencies and other code from build.gradle files
What I have tried and it worked:
Removing the dependency of base app (my-app) from DFM (i.e. removing implementation project(':my-app',) ) - but I need it. Just to clarify, the DFM applies the following gradle plugins: com.android.dynamic-feature and kotlin-android
Removing all flavors from the base app and DFM - but I need them in the base app.
The PoC I made works fine and gradle compiles the project even with the same flavors I use in my actual project
Notes:
I use DexGuard (but I disabled it to make sure it isn't interfering)
I don't have any custom build types, only 'debug' and 'release'
Gradle version is 3.5.2
Gradle wrapper is 5.5.1
Both the PoC and my actual project use the same versions of gradle, gradle wrapper, build types and flavors
Unfortunately I could not reproduce the problem in a separate project. I tried removing as much of things as possible from my project but I could not resolve the issue.
Do you have any idea what could be causing this issue and how could I possibly fix it? Thank you!
I had this issue and it was due to not removing the implementation project(':features:myDynamicFeatureModule') line from my app module's gradle file.