Hilt Unsupported metadata version in Kotlin - android-studio

I was tried to run my code in Kotlin 1.5.10
With plugin as
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
and dependencies as below
dependencies {
...
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.33-beta"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0-beta01"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha01'
implementation 'com.android.support:palette-v7:28.0.0'
When I migrate to kotlin_version = "1.5.10", it just errors out stating
error: [Hilt]
Unsupported metadata version. Check that your Kotlin version is >= 1.0: java.lang.IllegalStateException: Unsupported metadata version. Check that your Kotlin version is >= 1.0
at dagger.internal.codegen.kotlin.KotlinMetadata.metadataOf(KotlinMetadata.java:206)
at dagger.internal.codegen.kotlin.KotlinMetadata.from(KotlinMetadata.java:186)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133)
...
Can anyone help me? I spent a lot of time on it, your answer will help me a lot

Go to https://dagger.dev/hilt/gradle-setup check Hilt currently version
Update: For now, you can use the newest version.
Kotlin:1.7.0 with Hilt:2.42
Update: kotlin:1.6.0 is compatible with hilt:2.40.5, thanks #Nazanin Nasab
Currently, Kotlin 1.5.21 is compatible with Hilt 2.38.
dependencies {
...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
}

I got the same error. I changed two gradle files and It worked for me.
Project Gradle
plugins {
// dependencies for dagger hilt
id 'com.google.dagger.hilt.android' version '2.42' apply false
}
Module Gradle
dependencies {
implementation 'com.google.dagger:hilt-android:2.42'
kapt 'com.google.dagger:hilt-compiler:2.42'
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
}

Adding this line to build.gradle dependencies helped me:
kapt("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0")
https://youtrack.jetbrains.com/issue/KT-45885

Thanks for the answer , i had to do a slight tweak in order to work for me because i'm using Arctic Fox, hopefully this answer will help as well
Build.gradle (project)
buildscript {
ext {
compose_version = '1.0.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-alpha05'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.37"
}
}
Build.gradle (app)
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.34-beta"
kapt "com.google.dagger:hilt-android-compiler:2.34-beta"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha03'

For Kotlin 1.7.10, you just need to make the hilt versions 2.42.

in Project-level build.gradle change hilt version
id 'com.google.dagger.hilt.android' version '2.44' apply false
in App-Level build.gradle
implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"

general solution - in AS build console click link at bottom - build with -stacktrace param and find which annotation processor (KAPT) is causing error - then try to update dependency - if you are lucky new version should be available and supporting your gradle version
message in build output you should lookin for
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.

I got same here. I was using dagger:hilt-android:2.33-beta with Kotlin 1.5.10.Please try this
Project gradle
implementation "com.google.dagger:hilt-android:2.33-beta"
Module gradle
plugins {
...
id 'dagger.hilt.android.plugin'
}
dependencies {
...
//dagger-hilt
implementation "com.google.dagger:hilt-android:2.35.1"
kapt "com.google.dagger:hilt-android-compiler:2.35.1"
}

If any solution solved your problem. Go to https://dagger.dev/hilt/gradle-setup, in Using Hilt with Kotlin section, copy the version mentioned in dependencies and update your build.gradle accordingly

I have an issue when upgrading kotlin-gradle-plugin:1.7.x for fulfill requirement of compose. I revert them to org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21 and kotlinCompilerExtensionVersion value
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
kotlinCompilerExtensionVersion compose_version

in my case, the problem was in the different versions that I specified in the dependencies.
"2.40" in classpath 'com.google.dagger:hilt-android-gradle-plugin'
and
"2.43.2" in implementation 'com.google.dagger:hilt-android'

Firstly check helt dependency versions with below url
https://dagger.dev/hilt/gradle-setup
Check you kotlin versions
Kotlin version 1.6.0
Project level gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.40"
App level gradle
def hilt_version="2.40"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
Kotlin version 1.7.0
Project level gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
App level gradle
def hilt_version="2.42"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"

Related

This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.5.31

I'm using the latest Android Studio and I'm able to build and run my app fine with compose_version set to 1.0.5. However, I'd like to use the latest stable compose version 1.1.1.
I try to simply update the project build.gradle so it contains the following pointing to the desired compose version and the corresponding compatible kotlin version. These values are referenced in the app's build.gradle.
buildscript {
ext {
compose_version = '1.1.1'
kotlin_version = '1.6.10'
}
And in Android Studio, I go to Tools > Kotlin > Configure Kotlin Plugin Updates and download the latest Kotlin plugin (Early Access).
If I open Tools > Kotlin > Kotlin REPL, I see Welcome to Kotlin version 1.7.0-RC2-release-258 (JRE 11.0.12+0-b1504.28-7817840).
Now, I try to Rebuild Project.
I get the error:
This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.5.31 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
I don't wish to suppressKotlinVersionCompatibilityCheck given the warning, but I even tried that option and got other build errors.
Why is Kotlin version 1.5.31 being used? Shouldn't updating the Kotlin plugin have gotten Android Studio to switch to a more recent Kotlin version (as suggested by the Kotlin REPL message)? How can I make it such that Kotlin 1.6.10 is used and I stop getting the error?
Got the same error when using Compose 1.1.1. and Kotlin 1.7.0.
Task :app:compileDebugKotlin FAILED
e: This version (1.1.1) of the Compose Compiler requires
Kotlin version 1.6.10 but you appear to be using Kotlin version 1.7.0
which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
Changed the below block in my build.gradle (app module)
composeOptions {
kotlinCompilerExtensionVersion 1.2.0
}
This is my plugins block in build.gradle (project):
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
}
This Android developers page helped with picking the compatible versions :-
Compose to Kotlin Compatibility Map
Don't forget to sync and rebuild.
Compose uses the kotlin compiler defined in your buildscript block:
buildscript {
ext.kotlin_version = '1.6.10'
//....
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
If you are using the plugins block in settings.gradle or build.gradle:
pluginManagement {
plugins {
id 'org.jetbrains.kotlin.android' version '1.6.10'
}
}
Using this help me.
build.gradle (:app)
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-beta03"
}
There are 3 things you need to ensure are in sync(compatible with the other) for kotlin to work properly.
1)compose_ui_version='1.2.1' of buildscript in build.gradle(project)
2)plugin 'org.jetbrains.kotlin.android' version '1.7.10' in build.gradle(project)
3)kotlinCompilerExtensionVersion '1.3.1' in composeOptions in build.gradle(app)
To get the latest version of compose compiler and its corresponding kotlin version check here.
for me what I had to edit is to locate build graddle(Project):
first load compose_version to see the latest stable compose_version.
buildscript {
ext {
//2. change here to the latest stable (compose_version) that you got in step 1
compose_version = '1.3.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
//when you run you app, The next error will tell you the version of Kotlin that the latest compose_version needs, edit as below to the version required in the error
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
}
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
}
}
plugins {
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
and build.gradle(Module)
composeOptions {
kotlinCompilerExtensionVersion '1.1.1'
}
Go to your project level build.gradle file
There in the plugin section below mentioned 2 libraries has to be in the same version to remove this error:
{
...
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'org.jetbrains.kotlin.jvm' version '1.6.10' apply false
}
If required, change:
compileSdk 33
&
targetSdk to 33
. (inside app level build.gradle file).
Now sync the project & reload the priview. It will work fine.

Plugin with id 'androidx.navigation.safeargs' not found

When I try to add Safe Args (Android Navigation) to my app's as following
( using this guide : https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data ) :
apply plugin: 'com.android.application'
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
android {...
I receive this error :
Plugin with id 'androidx.navigation.safeargs' not found.
To add androidx.navigation.safeargsplugin follow below step's
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha09"
(latest)
Add above to your Project Gradel file inside dependency block
Then add apply plugin: 'androidx.navigation.safeargs' to your app/Module gradle file
You can use dependencies as below in Project level bulild.gradle in Android Studio bumblebee
id 'androidx.navigation.safeargs' version '2.4.2' apply false
Just add this line in your build.gradle project level :
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0-rc02"
In newer version of Android Studio 3.2+, below dependency need to add in both build.gradle file
Project-Level build.gradle
dependencies {
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5'
}
App-Level build.gradle
plugins {
id 'androidx.navigation.safeargs'
}
Add
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha05"
In your project-level dependencies
For eg :
dependencies {
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha05"
}
Don't forget to add the latest version
It appears because you are declaring it in the wrong build.gradle file. You have to place it in the build.gradle that looks like this
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.1.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
This link explain how it is added https://developer.android.com/jetpack/androidx/releases/navigation#safe_args
as per this https://developer.android.com/jetpack/androidx/releases/navigation
Add above to your Project Gradel file inside dependency block
`classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:2.2.1`
then add
apply plugin: androidx.navigation.safeargs
to your app/Module gradle file
Add this line in Project-level build gradle
id 'androidx.navigation.safeargs' version '2.4.2' apply false
Add this in App-level build gradle
plugins {
id 'androidx.navigation.safeargs'
}
I had to add it to the top level build.gradle, not sure if you've just added it to your app level build.gradle instead
FYI: I had to add it in this manner in order for it to work in Android Studio Dolphin | 2021.3.1:
Gradle Scripts > build.gradle (Project: YourProject)
plugins {
id blah
.
.
.
id 'androidx.navigation.safeargs' version '2.4.2' apply false
}
And also here:
Gradle Scripts > build.gradle (Module: YourProject.app)
dependencies {
implementation blah
.
.
implementation 'androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0-alpha02'
testImplementation blah
androidTestImplementation blah
}
I hope this may help others. I followed the directions at developer.android.com and all the instructions here. None of them solved the issue for me.
Mine was a simple order of operation in my modules build.gradle file.
I had:
id 'androidx.navigation.safeargs.kotlin'
listed as the first line in my plugins block.
moving to the end of the block solved my issue

Gradle sync issue in Android Studio 3.2.1

I have updated my Android studio to 3.2.1 since then am getting error as below
Unable to resolve dependency for ':app#debug/compileClasspath': Could
not resolve com.android.support:appcompat-v7:28.0.0.
hence unable to build my application
I have unchecked offline too
my dependencies in gradle file
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
kindly suggest a solution for this
Regards.
Nagendra
I think you are using old version of build tool in project level build.gradle.
Try
classpath 'com.android.tools.build:gradle:3.2.1'
Update your Android Gradle plugin
1- Upade the classpath in top-level build.gradle to:
buildscript {
....
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
2- Update the Gradle version to 4.6 in the gradle-wrapper.properties file by changing the distributionUrl to:
...
distributionUrl = https\://services.gradle.org/distributions/gradle-4.6-all.zip
...
3- Go to ReBuild Project
classpath 'com.android.tools.build:gradle:3.2.1'
add this to the dependencies of buildscript. then Sync the project.
Thanks for the response,
Isuue was with proxy blocking the downloads,i have commented the proxy in gradle.properties then its started working, i was trying in the office network.
Regards.
Nagendra

Android studio 3.0: Unable to resolve dependency for :app#dexOptions/compileClasspath': Could not resolve project :animators

I migrate to Android studio 3.0. So, the project become unable to compile a module named ":animator" and it displays me this error:
Error:Unable to resolve dependency for
':app#dexOptions/compileClasspath': Could not resolve project
:animators. <a
href="openFile:/home/mobilepowered/MobilePowered/MyInnovalee/trunk17-10-2017/app/build.gradle">Open
File</a><br><a href="Unable to resolve dependency for
':app#dexOptions/compileClasspath': Could not resolve project
:animators.">Show Details</a>
and show details gives this log :
Unable to resolve dependency for ':app#dexOptions/compileClasspath':
Could not resolve project :animators.
Could not resolve project :animators. Required by:
project :app
Unable to find a matching configuration of project :animators:
- Configuration 'debugApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'dexOptions' and found incompatible value 'debug'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but
wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
- Configuration 'debugRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'dexOptions' and found incompatible value 'debug'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but
wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
- Configuration 'releaseApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'dexOptions' and found incompatible value 'release'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but
wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
- Configuration 'releaseRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'dexOptions' and found incompatible value 'release'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but
wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
With Android Studio 2.3(AS) the project works fine and i can able to run the App. After updating the AS to Android Studio 3.0. i too got the error as below for libraries and build types.
Unable to resolve dependency for ':app#dexOptions/compileClasspath': Could not resolve project : library_Name.
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve project : library_Name.
To Solve the issue, simply.
What ever the
buildTypes{
debug{ ... }
release{ ... }
}
you have in your (app) build.gradle file, You have to include all the buildTypes{ } with same names as like
buildTypes{
debug{ ... }
release{ ... }
}
in to build.gradle files of All libraries/modules included in project.
clean and rebuild the project, the issue will be fixed.
Still issue not fixed, update the gradle-wrapper.properties to
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
As stated in the official migration guide, this error is encountered when:
Your app includes a build type that a library dependency does not
android {
buildTypes {
release {
...
}
dexOptions {
...
// release & debug is in project animators
matchingFallbacks = ['release', 'debug']
}
debug {
...
}
}
}
Correct place to find the info is now this documentation
Make sure you're in your project
Open the Preferences, by clicking File > Settings (on Mac,
Android Studio > Preferences).
In the left pane, click Build, Execution, Deployment >> Gradle.
Uncheck/disable the Offline work checkbox.
Click Apply or OK.
I spent a lot of time on this issue and none of above solutions work for me. The names and number of build types were also exactly equal in both app and library project.
The only mistake I was making was - In library project's build.gradle, I was using line
apply plugin: 'com.android.application'
While this line should be -
apply plugin: 'com.android.library'
After making this change, this error got resolved.
Modify all
compile project(':library:yourproject')
to
implementation project(path: ':library:yourproject', configuration:'default')
in your app build.gradle. Note the line with configuration.
I tried everything from unchecking offline work to matchingFallbacks. But nothing worked.
Then, in dependencies of app.gradle,
instead of
implementation project(':lib-name')
I used,
implementation project(path:':lib-name', configuration: 'default')
Eg: implementation project(path:':myService', configuration:
'default')
And it worked like a charm. :)
I was adding a dependency module with service and am not making a library as its a part of AOSP project.
Just in case, it helps someone.
Solution:
Dowload the ultimate version of Gradle
http://services.gradle.org/distributions/
gradle-4.x-rc-1-all.zip.sha256 09-Jan-2018 01:15 +0000 64.00B
Unzip the distribution
Go to Android Studio -> File -> Settings -> Gradle -> Use local gradle distribution
Search the file and OK
In the gradle:app write this, implementation(path: ':animators', configuration: 'default')
dependencies {
.
.
.
implementation project(path: ':animators', configuration: 'default')
}
Here is how I solved my problem:
instead of
compile project(':library_name')
compile project(':library_name')
in app gradle I have used
implementation project(':library_name')
implementation project(':library_name')
And in my build types for example
demoTest {
.........
}
I added this line
demoTest {
matchingFallbacks = ['debug', 'release']
}
I had the same issue, and solved it by adding 'mavenCentral()' to build.gradle(Project)
allprojects {
repositories {
...
mavenCentral()
}
}
My problem is below
Unable to resolve dependency for ':app#debug/compileClasspath': Could not download rxjava.jar (io.reactivex.rxjava2:rxjava:2.2.2)
Solved by checking Enable embedded Maven Repository
Even, I have faced the same issue.
I have fixed the issue by referring the above
Solution 2 with the new g‌​radle-4.1 :
I have done the following gradle changes.
It seems downloading resources through maven Amazon helped me to fix the issue, there are issues with appcompat library. Check and ensure that appcompat compatible support libraries downloaded in your system. What I feel, it just simply the resources not downloaded through maven, causing the compile error issue. Ensure the resources are found in your local drive to fix the issue.
Just Played around with
Maven Amazon url
repositories {
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
jcenter()
}
Compatible support libraries downloaded in the drive and referring compatible libraries in gradle.
dependencies {
implementation fileTree(dir: 'libs', include: \['*.jar'\])
implementation 'com.android.support:appcompat-v7:26.0.0-alpha1'
implementation 'com.android.support:support-v4:26.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
Complete file
apply plugin: 'com.android.application'
repositories {
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
jcenter()
}
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.cognizant.interviewquestions.cognizantiqpractice2"
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName "1.0"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: \['*.jar'\])
implementation 'com.android.support:appcompat-v7:26.0.0-alpha1'
implementation 'com.android.support:support-v4:26.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
---------------------------------------------------------------------------
Change this code in gradle:
compile project(':yourLibrary')
to
implementation project(path: ': yourLibrary', configuration:'default')
I found two type of solutions :
Solution with the old g‌​radle-3.3 :
As first and temporary solution to make the project run with android studio 3.0 , I maintain the old config of my previous of Android Studio 2.3
distributionUrl=https://services.gradle.org/distributions/g‌​radle-3.3-all.zip , compileSdkVersion 25** and **buildToolsVersion "25.0.3" and classpath 'com.android.tools.build:gradle:2.3.3
Solution with the new g‌​radle-4.1 :
To work with the new features of gradle 4.1 and the classpath com.android.tools.build:gradle:3.0.0' , I followed this link https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html . So, Those are my implementations :
In the file gradle-wrapper.properties :
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
In the file build.gradle of the project :
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
//classpath 'me.tatarka:gradle-retrolambda:3.3.1' remove this line
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
In the file build.gradle of the app :
apply plugin: 'com.android.application'
//apply plugin: 'me.tatarka.retrolambda' remove this line
repositories {
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.imennmn.myprojectid"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
/**
* Enabling multidex support.
*/
multiDexEnabled true
missingDimensionStrategy 'minApi' , 'minApi24'
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
}
buildTypes {
release {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
/**
* Solve the problem when using multiple free source libs
* NOTICE or LICENSE files cause duplicates
*/
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
//exclude duplicate butterknife and parceler libs
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/rxjava.properties'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/motwin-android-sdk-3.2.0-RELEASE-TLS.jar')
implementation files('libs/notifmanager-android-lib-3.1.0-RELEASE.jar')
implementation files('libs/commons-lang-2.4.jar')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support:support-v4:26.0.2'
implementation 'com.android.support:design:26.0.2'
implementation 'com.android.support:multidex:1.0.2'
api 'com.jakewharton:butterknife:7.0.1'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.android.support:percent:26.0.2'
implementation 'com.google.android.gms:play-services-maps:11.4.2'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.google.code.gson:gson:2.8.1'
testImplementation 'junit:junit:4.12'
implementation 'com.facebook.rebound:rebound:0.3.8'
implementation 'com.google.android.gms:play-services-gcm:11.4.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation project(':animators')
// Retrofit2 & XmlConverter
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
implementation('com.squareup.retrofit2:converter-simplexml:2.3.0') {
exclude group: 'xpp3', module: 'xpp3'
exclude group: 'stax', module: 'stax-api'
exclude group: 'stax', module: 'stax'
}
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
//Library to reports crash
implementation('ch.acra:acra:4.5.0') {
exclude group: 'org.json'
}
implementation 'com.github.kenglxn.QRGen:android:2.3.0'
}
In the build.gradle of the library animator I upgrade targetSdkVersion to 26 :
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
}
dependencies {
implementation "com.android.support:support-compat:26.0.2"
implementation "com.android.support:support-core-ui:26.0.2"
implementation "com.android.support:recyclerview-v7:26.0.2"
}
you just need to reset dependencies in app.gradle file
like old one as
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
to new one as
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
Make sure you have disabled "Offline work" in Gradle settings (Setting->Build, Execution, Deployment->Build Tools->Gradle).
I made this mistake. I followed a guide on speeding up gradle builds and had turned on the Offline work option. If that is enabled, Gradle won't be able to download any new dependencies and hence will result in the "Unable to resolve dependency" error.
I met the same problems and has solved.
Due to my situation, I guess your build.gradle file for app project contains snippets below:
android {
...
buildTypes {
debug {...}
release {...}
dexOptions {...}
}
}
but actually, dexOptions is not a build type, you should move dexOptions section out buildTypes, like this:
android {
...
dexOptions {
...
}
buildTypes {
debug {...}
release {...}
}
}
Hope that can help someone.
Adding productFlavors{} to the app build.gradle solved the issue for me. See below:
buildTypes {
release {
...
}
}
productFlavors {
}
This may also happen when you add a reference to the feature module that uses the incorrect plugin type. Simply change com.android.application to com.android.feature or com.android.library
https://i.stack.imgur.com/NDjnG.png
I think it's from gradle-wrapper.properties file :
make distribution url distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
and do not upgarde to : distributionUrl=https\://services.gradle.org/distributions/gradle-4 ....
It seems like it's a bug on Gradle. This solves the problem for me, but it's not a solution. We have to wait for a new version fixing this problems.
On build.gradle in the project set classpath 'com.android.tools.build:gradle:2.3.3' instead classpath 'com.android.tools.build:gradle:3.0.0'.
On gradle-wrapper.properties set https://services.gradle.org/distributions/gradle-3.3-all.zip instead https://services.gradle.org/distributions/gradle-4.1.2-all.zip
In my case, the problem I had was due to a dependency I was trying to import (BottomNavigationViewEx).
This dependency requires to be downloaded from jitpack.io and maven.google.com, and I was putting this config in buildscript section:
buildscript {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" } // this is incorrect
maven { url "https://maven.google.com" } // this is incorrect
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
which it was incorrect, I need to remove these two maven lines and include them in the right section, 'allprojects':
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
}
Hope it helps somebody as same for me.
I tried all the solutions given above and none of them worked for me, I ensured that I have exact build types and product flavours in my library module and app module.
This thread seems to have wondered a bit, however as relating to the original question, not only do you have to have your buildTypes in both build.gradle files, you need to have your productFlavors (if you are using them of course) in both build.gradle files as well.
I tried running Android studio 3.0.1 with internet connection. Android studio started downloading something from a link automatically which was showing in Gradle build notification. I can't say this is a sure answer but try this out.. maybe you can get your issue resolved.
If using Android Studio on Linux:
go to: Home/Android Studio Projects folder/App name folder
open terminal on that page and type:
./gradlew -Dhttp.proxyHost
check if JAVA_HOME is set on valid directory, if not set valid location finally rebuild your project.
NOTE: if that doesn't work remove gradle cache folder or all of that
and download again with Android Studio.
Add the library from File->Right click->New->Module->Import Eclipse ADT project->brows your library->finish
Now add in the app gradle setting following code:
implementation project(':library')
Finally add in the setting gradle following code:
include ':app', ':library'
After updating android studio to 3.3. I faced this problem when I tried to load Firebase JobDispatcher.
Adding this link on gradle.properties solved my problem
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
I know none of the above solutions is gonna work as I have remained stuck into this sort of issue a long time, finally resolved this issue after watching the issue very carefully, which is pointing that
Unable to resolve dependency for ':app#dexOptions/compileClasspath':
Could not resolve project : library_Name.
You need to make a sure and double check if the class is residing there. This one thing will prove much helpful to many I guess because focusing on this point took me much closer to the solution. Now if nothing exists in that folder path you need to get the whole stuff like src folder build folder etc everything, copy that and paste it over there sync/rebuild project, if needed try invalidate and restart android studio. Hope so this will get you out of trouble as happend in my case.
Thanks
changing implementation 'com.android.support:appcompat-v7:27+' to implementation 'com.android.support:appcompat-v7:+' worked for me
I am using Intellij 2019 CE, with Kotlin
In my case it was so:
Unable to resolve dependency for ':app#debug/compileClasspath': Failed to transform artifact....
I tried ten solutions, no one worked, thus my solution was to remove C:\Users\djdance.gradle\caches and restart AS

running geb test with gradle 2.3 - HashMap$Entry exception

I am trying to run geb tests through gradle. I've these installed
java version "1.8.0_31"
Groovy Version: 2.4.0
Gradle 2.3
But i am getting this error when running the test.
Exception in thread "main" java.lang.NoClassDefFoundError: java/util/HashMap$Ent
ry
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
Running a simple groovy script with above setup and the below Build.gradle is fine.
Build.gradle looks like this:
buildscript {
repositories {
jcenter()
}
}
apply plugin: 'java'
apply plugin: 'groovy'
repositories {
jcenter()
mavenCentral()
}
dependencies {
def seleniumVersion = "2.45.0"
def phantomJsVersion = '1.1.0'
// selenium drivers
compile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
compile("com.github.detro.ghostdriver:phantomjsdriver:$phantomJsVersion") {
transitive = false
}
// geb
compile 'org.codehaus.geb:geb-core:0.7.2'
compile 'org.codehaus.geb:geb-spock:0.7.2'
// spock
compile 'org.spockframework:spock-core:0.6-groovy-1.8'
//junit
testCompile group: 'junit', name: 'junit', version: '4.7'
}
task runGebScript (dependsOn: 'classes', type: JavaExec) {
main = 'test'
classpath = sourceSets.main.runtimeClasspath
}
Can someone please help.
According to Gradle dependency report for the build you included, the Groovy version used for testCompile configuration is 1.8.5. Only groovy 2.x is JDK8 compatible. I would do as ataylor suggests and bump Spock version. If you use 1.0-groovy-2.4 then you'll be using Groovy 2.4.1. Also, I would suggest updating version of Geb while you're at it - the latest is 0.10.0. Your dependency versions are way out of date.
Something is trying to use the inner class HashMap.Entry, which no longer exists in Java 8. It's difficult to tell where without a complete stack trace.
However, you're using this version of spock: org.spockframework:spock-core:0.6-groovy-1.8. That version is not compatible with groovy 2.0+. Try updating the dependency to org.spockframework:spock-core:1.0-groovy-2.4.

Resources