Dagger throwing errors after Kotlin integration in a java code - android

Android project Code base is full java and dagger 2 is implemented in java as well. I am integrating kotlin in the code and each time I rebuild, Dagger gives errors. (Added below)
code:
build.gradle (project)
buildscript {
ext {
kotlin_version = "1.7.10"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (app)
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 32
defaultConfig {
applicationId "co.xyz.abc"
minSdkVersion 21
targetSdkVersion 32
versionCode 15
versionName "1.1.1"
multiDexEnabled true
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
vectorDrawables.useSupportLibrary = true
}
buildTypes {
// ...
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
// AndroidX
// ....
//kotlin
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10'
implementation 'androidx.core:core-ktx:1.9.0'
// ViewModel
def lifecycle_version = "2.4.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// Dagger2
def daggerVersion = "2.35.1"
api "com.google.dagger:dagger:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
// Dagger Android
api "com.google.dagger:dagger-android-support:$daggerVersion"
api "com.google.dagger:dagger-android:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVersion"
// AssistedInject
def assistedInject = '0.6.0'
compileOnly "com.squareup.inject:assisted-inject-annotations-dagger2:$assistedInject"
annotationProcessor "com.squareup.inject:assisted-inject-processor-dagger2:$assistedInject"
androidTestImplementation 'junit:junit:4.13.2'
}
gradle.properties
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
kotlin.code.style=official
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
Errors after Rebuild:
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:checkStagingLocalDevAarMetadata'. A failure occurred while
executing
com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
3 issues were found when checking AAR metadata:
Dependency 'androidx.core:core-ktx:1.9.0' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Also, the maximum recommended compile SDK version for Android Gradle
plugin 7.2.1 is 32.
Recommended action: Update this project's version of the Android Gradle
plugin to one that supports 33, then update this project to use
compileSdkVerion of at least 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
Dependency 'androidx.core:core:1.9.0' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Also, the maximum recommended compile SDK version for Android Gradle
plugin 7.2.1 is 32.
Recommended action: Update this project's version of the Android Gradle
plugin to one that supports 33, then update this project to use
compileSdkVerion of at least 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
Dependency 'androidx.annotation:annotation-experimental:1.3.0' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Also, the maximum recommended compile SDK version for Android Gradle
plugin 7.2.1 is 32.
Recommended action: Update this project's version of the Android Gradle
plugin to one that supports 33, then update this project to use
compileSdkVerion of at least 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
When I change compileSdk to 33 :
Task :app:compileStagingLocalDevJavaWithJavac
error: cannot find symbol import
co.abc.client.di.components.DaggerABCApplicationComponent;
^ symbol: class DaggerABCApplicationComponent location: package
co.abc.client.di.components
Now, if I downgrade the core-ktx version to 1.8.0 and change annotationProcessor to kapt :
Task :app:kaptStagingLocalDevKotlin
/StudioProjects/project/app/src/main/java/co/abc/client/di/modules/account/AssistedModule.java:8:
error: cannot find symbol #Module(includes =
AssistedInject_AssistedModule.class)
^ symbol: class AssistedInject_AssistedModule /StudioProjects/project/app/src/main/java/co/abc/client/di/modules/account/AssistedModule.java:9:
error: [ComponentProcessor:MiscError]
dagger.internal.codegen.ComponentProcessor was unable to process this
interface because not all of its dependencies could be resolved. Check
for compilation errors or a circular dependency with generated code.
public interface AssistedModule {}
^ /StudioProjects/project/app/src/main/java/co/abc/client/di/components/ABCApplicationComponent.java:40:
error: [ComponentProcessor:MiscError]
dagger.internal.codegen.ComponentProcessor was unable to process this
interface because not all of its dependencies could be resolved. Check
for compilation errors or a circular dependency with generated code.
public interface ABCApplicationComponent extends
AndroidInjector {
^
Task :app:kaptStagingLocalDevKotlin FAILED
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:kaptStagingLocalDevKotlin'. A failure occurred while executing
org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
java.lang.reflect.InvocationTargetException (no error message)
What could be the issue here? Should the Dagger-related code be written in Kotlin? Is there a source I could refer to for kotlin integration in java code base for android when dagger is there?
So far, I have tried these which didn't work:
upgrading and downgrading versions for kotlin and dagger.
changing all annotationProcessors to kapt
adding this to gradle - -Pandroid.incrementalJavaCompile=false
android {
compileOptions.incremental = false
}
restart ide
Also, I have another project(java code base and kotlin integration setup) which is working with these versions so the issue doesn't seem to be with that. only difference is, dagger is not in my other project and everything runs fine there.

try using the latest version of the dagger in both Gradle
//Hilt
implementation 'com.google.dagger:hilt-android:2.42'
kapt 'com.google.dagger:hilt-android-compiler:2.42'
kapt "androidx.hilt:hilt-compiler:1.0.0"
in App level
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42'

Maybe it is a version issue
downgrade your kotlin version and then check it
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.30'
implementation 'androidx.core:core-ktx:1.8.0'

Related

Dagger-hilt error while compiling project

Getting error below while using dagger-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
Please note that I already followed some topics from stackoverflow and other documentation
Hilt Unsupported metadata version in Kotlin
Unsupported metadata version. Check that your Kotlin version is >= 1.0: java.lang.IllegalStateException
https://github.com/google/dagger/issues/2379
Using below app gradle configuration
compileSdk 32
defaultConfig {
applicationId "com.test.plantdemo"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
}
Android plugin
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
App level dependency
dependencies {
implementation "androidx.work:work-runtime-ktx:2.5.0"
kapt 'androidx.hilt:hilt-compiler:1.0.0'
implementation 'androidx.hilt:hilt-work:1.0.0'
kapt "com.google.dagger:hilt-android-compiler:2.35.1"
kapt "com.google.dagger:hilt-compiler:2.35.1"
implementation "com.google.dagger:hilt-android:2.35.1"
}
Top level dependency I used
dependencies {
// other plugins...
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40'
}
Top level gradle Plugin
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.7.0' apply false
id 'com.google.dagger.hilt.android' version '2.41' apply false
}
Error window shows below error
[Hilt] Processing did not complete.
See error above for details.
Execution failed for task ':app:kaptDebugKotlin'.
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
java.lang.reflect.InvocationTargetException (no error message)
step I followed after adding library
Step1: Android application class
#HiltAndroidApp
class PlantApplication: Application() {
}
Step2: Module calss
#Module
#InstallIn(SingletonComponent::class)
object MainModule {
}
Step3: View Model
#HiltViewModel
class PlantListBaseViewModel #Inject constructor(): ViewModel() {
}
Step4: fragment
#AndroidEntryPoint
class PlantListBaseFragment : Fragment() {
}
I recommend using the latest stable version of Dagger. Mine is working with these versions:
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
implementation "com.google.dagger:dagger-android-support:2.42"
implementation "com.google.dagger:hilt-android:2.42"
I hope it'll work
Update:
If you are curious about the reason, here:
Looks like Dagger needs to update the kotlin-metadata-jvm library to 0.4.0 which supports reading metadata from Kotlin 1.7, current version is 0.3.0, you might be able to work around the issue by forcing an update on the transitive dep, likely depending on it directly, something like this:
dependencies {
//Not a processor, but forces Dagger to use newer metadata lib
kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.4.2"
}
you can follow that here: https://github.com/google/dagger/issues/3383

Android app won't build -- The minCompileSdk (31) specified in a dependency's androidx.work:work-runtime:2.7.0-beta01

I'm trying to build a project in my M1,
but I got this error when I run npx react-native run-android
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.work:work-runtime:2.7.0-beta01.
AAR metadata file: /Users/macpro/.gradle/caches/transforms-3/999e9d813832e06d8f1b7de52647a502/transformed/work-runtime-2.7.0-beta01/META-INF/com/android/build/gradle/aar-metadata.properties.
Android/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.0"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath('com.android.tools.build:gradle:4.1.2')
classpath('com.google.gms:google-services:4.3.0')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
The error is being caused because one of your dependencies is internally using WorkManager 2.7.0-beta01 that was released today (which needs API 31). In my case it was CheckAarMetadata.kt.
You can fix it by forcing Gradle to use an older version of Work Manager for the transitive dependency that works with API 30. In your build.gradle file add:
dependencies {
def work_version = "2.6.0"
// Force WorkManager 2.6.0 for transitive dependency
implementation("androidx.work:work-runtime-ktx:$work_version") {
force = true
}
}
This should fix it.
This is because in work-runtime:2.7.0-beta01 the compileSdkVersion was updated to 31
you could either update your compileSdkVersion to 31
or use an older version of work-runtime that doesn't include this change
It is mentioned in the release notes of Version 2.7.0-beta01
Note: WorkManager Version 2.7.0 is required for apps targeting Android 12 (S).
for example, adding this to your build.gradle should fix it
api(group: "androidx.work", name: "work-runtime") {
version {
strictly "2.7.0-alpha04"
}
}
I had the same problem and I was able to solve it by changing the version of appcompat in the dependencies
What I had:
implementation 'androidx.appcompat:appcompat:1.4.0'
I changed it to:
implementation 'androidx.appcompat:appcompat:1.3.1'
Note that I am using java.
I experienced the same thing but was actually caused by work manager dependency that I upgraded to version 2.7.0
I simply downgraded it back to 2.6.0
dependencies{
implementation 'androidx.work:work-runtime-ktx:2.6.0'
}
I was also having the same issue in my project and now that issue is being resolved. The issue was because of the dependency androidx.work:work-runtime
But I would like to first mention that I was not using that dependency in my project directly (not added in my app level gradle), probably some other dependency was using that internally.
So what I did is forcefully downgraded its version by adding this
configurations.all {
resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
}
inside
android {
defaultConfig {
//here
}
}
and it resolved my issue.
In my flutter application, changed the compileSdkVersion and targetSdkVersion in android\app\build.gradle
android {
compileSdkVersion 31 // Changed to 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "com.example.blah_blah"
minSdkVersion 16
targetSdkVersion 31 //Changed to 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
And also, changed the kotlin version to '1.6.10' in android\build.gradle
buildscript {
ext.kotlin_version = '1.6.10' //change here
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
For those others facing the below error from last 36hrs (due to an update on androidx-core):
Error:
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.core:core-ktx:1.7.0-alpha02.
you can try to force use androidx to older version:
place it under android/app/build.gradle (under dependencies {} preferably or outside android {})
configurations.all {
resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
}
Check the message
you can see the module used that has minCompileSdk (31) specified
Dependency: androidx.appcompat:appcompat:1.4.0.
To fix this issue momentarily you have to downgrade the dependency defined into your build.gradle, for example from appcompat:1.4.0 to appcompat:1.3.0 :
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
...
...
...
/* The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.appcompat:appcompat:1.4.0. */
}
I have changed this
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
to this
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
and it worked for me, also i was using Kotlin
In my case what worked for me was to change compileSdk version to 31
A similar issue on 4Nov, 2022. If someone is stuck due to this build issue please checkout
https://github.com/facebook/react-native/issues/35210
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
configurations.all {
resolutionStrategy {
// Remove this override in 0.66, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
}
Something in my project auto-updated causing a cascading effect. After first it was giving errors that I had intent-filters missing android:export="true/false" when targeting SDK 31. But my targets were set for SDK 30. I then setting targets to SDK 31 causing more issues. So I backed them out...but as a result of setting to SDK 31, other dependencies were trying to use BETA releases versus the stable version.
In my case, after rolling back to SDK 30, I then started getting an error similar to the OPs minCompileSdk (31) specified in a dependency's androidx.appcompat:appcompat-resources:1.4.0-beta01 - the stable version for appcompat is 1.3.1.
In my /<project>/platforms/android/project.properties file my appcompat dependency was set to:
cordova.system.library.19=androidx.appcompat:appcompat:1+
This was causing version 1.4.0-Beta01 to be updated/loaded. So I had to pin it back to:
cordova.system.library.19=androidx.appcompat:appcompat:1.3.1
I had similar problem and I updated one of the Gradle Script and it fix the problem;
// build.gradle (Module:testApp)
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "myproject.name.testApp"
minSdkVersion 16 // <--- must be same as under dependencies section
targetSdkVersion 30
versionCode 1
versionName "1.0"
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0' // <--- Was showing 1.7, it fix problem
implementation 'androidx.appcompat:appcompat:1.3.1'
To solve this issu follow these steps
Go to SDK manager in android studio and install 'Android api 31'
Go to build.gradle file and change complie SDK version 'x' to compile SDK
version 31 and change target SDK version also to 31
Now synk
go to manifest.xml and write this line to inside your activity which is linked with intent filter
'android: export="true"
Now build the project. It will definitely solve this problem
Note also that the latest Google Ads SDK dependencies (currently v20.5.0) may lead to the minCompileSDK (31) error in the following circumstance:
your project is setup to use a compileSDK and targetSDK of 29/30
The Google Ads (or any) dependency version included in the implementation section of your build.gradle is intended for use with Apps compiling against API 31 / Android 12
For example your build.gradle may contain:
compileSdkVersion 29
targetSdkVersion 29
implementation 'com.google.android.gms:play-services-ads-lite:20.5.0'
As mentioned in other answers the way to resolve this is that you need to apply a force resolutionStrategy to ensure that the latest versions of the androidx.work:work-runtime and androidx.core:core-ktx are not picked up as required build dependencies.
The following works for me
configurations.all {
resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
}
NOTE: Once you have migrated to compiling against API 31, the resolutionStrategy lines should be removed to ensure that you are using the latest versions of the core Android platform dependencies
I had this problem and was getting no solutions from any of the Stack Overflow threads. Disabling Hyper V and running basic diagnostics were still not helpful. I was getting stop codes each time I tried to run my VM.
I fixed this issue by going into the SDK manager and updating the SDK Platform and SDK tools. Start by opening the SDK Manager from the Tools menu, and each option with a hyphen in the Platform/Tools panes click to change into a check mark, hit apply and accept the changes. The stop codes went away for me.
BROTHER MY ERROR HAS BEEN RESOLVED BY DOWNLOADING THE SDK TOOL OF 31 FROM SETTINGS -> APPERENCE AND BEHAVIOUR-> ANDROID SDK - AND THE 2ND ONE IN THE LIST
as in the image instead of 28 in the second column there will be 31 So u need to download that and then rebuild your project
That's it !
I solved the issue by adding this piece of code at the end of dependencies inside android/app/build.gradle :
android/app/build.gradle
dependencies {
....
....
api(group: "androidx.work", name: "work-runtime") {
version {
strictly "2.7.0-alpha04"
}
}
}
And this is android/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"
androidXCore = "1.7.0" // <-- Add this. Check versions here: https://developer.android.com/jetpack/androidx/releases/core
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
maven { url 'https://www.jitpack.io' }
}
}
I had to update from RN 0.66.4 to 0.66.5.
https://github.com/facebook/react-native/releases/tag/v0.66.5
The description:
🚨 IMPORTANT: This is an exceptional release on an unsupported version. We recommend you upgrade to one of the supported versions, listed here.
Hotfix
This version is a patch release addressing the Android build issue that has been ongoing since Nov 4th 2022. If you are on 0.66.x, update to this version to fix it.
If you are on an older version of React Native, refer to this issue for details and the workaround you can apply in your project.
After bumping it worked for me.
In my case, on of the module's version has + on its versioning, specifying the version which suits to your sdk version will solve it
I have the following dependency in one module -
implementation "androidx.core:core-ktx:+"
but others module including app module has following dependency
implementation "androidx.core:core-ktx:1.6.0"
You need change + to version
implementation "androidx.core:core-ktx:+" ->
implementation "androidx.core:core-ktx:1.6.0"
I had the same error and it worked when I modified the following:
implementation 'androidx.core:core-ktx:1.7.0' and `api 'com.google.android.material:material:1.4.0-alpha07'`
to
implementation 'androidx.core:core-ktx:1.6.0' and api 'com.google.android.material:material:1.4.0-alpha06'
I was having the same problem the minCompileSdk (31) specified in a dependency's AAR metadata when I created an activity from the templates with ViewModel and LiveData it add the latest versioned dependencies like
then I downgraded the version to 1.6.0 as
I also had this probem in a jetpack compose project.
I was using paging and the problem was because of both paging and some other dependencies.
I could solve the problem by using the following version of paging instead :
implementation "androidx.paging:paging-compose:1.0.0-alpha10"
and I replaced the old dependencies with the following :
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
Changing
implementation 'androidx.core:core-ktx:1.7.0'
to
implementation 'androidx.core:core-ktx:1.6.0'
worked for me.
Because you use gradle>7.0, you can chan gradle-6.7.1-all and com.android.tools.build:gradle:4.0.0. :3
I was facing same issue for the last few weeks, now in Dec 2021 first week the official sdk of 31 is released,
Now change the compilesdk to 31 and targetsdk to 30
Download the latest sdk from android studio,
Click Tools > SDK Manager.
In the SDK Platforms tab, select Android 12.
In the SDK Tools tab, select Android SDK Build-Tools 31.
Click OK to install the SDK.
The latest lib wants the compilesdk of 31,
Once you do this all issues resolved.
#Kishan Solanki answer worked for me. I am using Flutter.
So what I did is forcefully downgraded its version by adding this
configurations.all {
resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
}
inside
android {
defaultConfig {
//here
}
}
I got this error when trying to target API 30 in a Java project. It was caused by appcompat version 1.4.1 requiring a target API of 31 or higher. If you downgrade to version 1.3.1 it will support a target API of 30 or higher.
To target API 30, you need to downgrade both androidx.appcompat:appcompat and com.google.android.material:material to older versions.
Change the versions from:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
To:
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
Ionic user with Cordova
I would have loved to give an answer to the following question, but since it have been closed..
This is a pure copy of the following answer but it should make the trick
"This issue is related to androidx.appcompat:appcompat 1.4.0-beta01 released on September 29, 2021.
As plugin.xml defines ANDROIDX_VERSION as major version 1 (1.+), 1.4.0-beta01 was used instead of 1.3.0. Unfortunately you cannot simply use cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.3.+ to overwrite the value, as the same version would be used for androidx.legacy:legacy-support-v4 which exists as version 1.0.0 only.
I successfully used cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION="[1.0, 1.4[" to get my builds fixed." - Vivek Kachhwaha
For me, I had to uninstall the java version which is currently the latest (java 17) and install java 11.
I'm using expo react native. I tried to use expo run:android or eas build --profile development --platform android. The error I got from these two was solved by simply doing the above.

Gradle desugaring failed, Hierarchy is incomplete

I am working on this project: https://github.com/muxinc/mux-stats-sdk-exoplayer/tree/min_sdk_version_fix It is Android app called demo that have dependency to a module from a same project called MuxExoPlayer which have a dependency to a MuxCore.jar library.
When I try to compile the project with minSdkVersion 16, I get desugaring issue on jar file, error:
Transform artifact full.jar (project :MuxExoPlayer) with DexingWithClasspathTransform
AGPBI: {"kind":"error","text":"Default method desugaring of `com.mux.stats.sdk.muxstats.MuxStatsExoPlayer` failed because it's hierarchy is incomplete. The class `com.mux.stats.sdk.core.events.EventBus` is missing and it is the declared super class of `com.mux.stats.sdk.muxstats.MuxBaseExoPlayer`","sources":[{}],"tool":"D8"}
When I compile with minSdkVersion 24, I do not get this error and project compile just fine.
MuxCore.jar is also built with gradle, here is the gradle.build:
apply plugin: 'java-library'
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
tasks.withType(JavaCompile) {
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:23.0'
implementation 'org.json:json:20180130'
// Use JUnit test framework
testImplementation 'junit:junit:4.4'
testImplementation 'org.mockito:mockito-core:2.23.4'
}
What am I missing here ?
How do I need to compile MuxCore in order to compile with android minSdkVersion 16 ?
I have the same problem and also create a ticket in Mux github repo but could not make it work... If you update the minSdk to 24 it will work...
https://github.com/muxinc/mux-stats-sdk-exoplayer/issues/19
What is working for me is: instead of adding MuxStatsExoPlayer as a module add directly all the files and classes in your app module into your project and it should work.

Why does android.arch.navigation cause Program type already present: android.support.v4.os.ResultReceiver$1?

I am using Android Studio version
Android Studio 3.2 Canary 14
Build #AI-181.4668.68.32.4763614, built on May 4, 2018
JRE: 1.8.0_152-release-1136-b02 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.11.6
While investigating the new Architectural navigation components android.arch.navigation I have encountered this build failure.
AGPBI: {"kind":"error","text":"Program type already present: android.support.v4.os.ResultReceiver$1","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: ...
...
Program type already present: android.support.v4.os.ResultReceiver$1
My app gradle build resembles:-
apply plugin: 'com.android.application'
apply plugin: "androidx.navigation.safeargs"
android {
compileSdkVersion 'android-P'
defaultConfig {
applicationId "com.research.frager"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
def nav_version = "1.0.0-alpha01"
implementation "android.arch.navigation:navigation-fragment:$nav_version"
implementation "android.arch.navigation:navigation-ui:$nav_version"
// optional - Test helpers
androidTestImplementation "android.arch.navigation:navigation-testing:$nav_version"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha2'
}
and project level gradle build:-
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha01"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have tried refactoring to AndroidX, however I get a message stating No usages found in project, so why is this "v4" class still being mentioned?
I've been looking at this issue and I have sorted the main issue here by excluding the support package when adding the dependency to the library, doing this:
implementation("android.arch.navigation:navigation-fragment:$nav_version") {
exclude group: 'com.android.support'
}
That would allow you to run the application. However, this artifact is using the support artifacts rather than the androidx artifacts. Looking at the documentation, we can see that NavHostFragment is extending support.v4.Fragment
https://developer.android.com/reference/androidx/navigation/fragment/NavHostFragment
So, in short, you are presented with three options, as far as I can see. The first one is to drop the androidx artifacts and use the support ones which eventually depends on how big your app is.
The second option is to drop the navigation library and go back to the classic way of dealing with navigation which, I guess, is probably undesirable for you.
The third option is to implement a navigation host of your own which I don't know how much work it would be.
This response will remain accurate until Google releases the androidx version of the library which I am surprised they haven't already.
Hope that was helpful.

Android Studio Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'

I installed Android Studio and when I try to import a project from gradle this resolve error shows up:
Unable to load class
'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'.
I deleted the files in my Users .gradle folder and tried different gradle versions. I don't know how to fix this.
This page might help solve the problem. What they say is:
So we leveraged this version to add a new artifact, named
groovy-backports-compat23. This artifact shouldn’t be necessary for
most of you, but if you face an error like:
Caused by: java.lang.ClassNotFoundException:
org.codehaus.groovy.runtime.typehandling.ShortTypeHandling at
java.net.URLClassLoader$1.run(URLClassLoader.java:372)
in your project, then it means that a class has been compiled with
Groovy 2.3+ but that you are trying to use it with an older version of
Groovy. By adding this jar on classpath, you give a chance to your
program to run. This may be particularily interesting for Gradle users
that want to use a plugin built on Gradle 2+ on older versions of
Gradle and face this error. Adding the following line to their build
files should help:
buildscript {
// ...
dependencies {
classpath 'some plugin build on gradle 2'
classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5'
} }
Note that for now, this jar only contains the ShortTypeHandlingClass.
Future versions may include more.
- See more at: http://glaforge.appspot.com/article/groovy-2-3-5-out-with-upward-compatibility#sthash.mv7Y8XQv.dpuf
I can fix this error message using these three methods.
use latest gradle version
use latest android SDK and tools.
use proguard-rules.pro
build.gradle (Project:xxxxx)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
mavenCentral()
}
}
build.gradle (Module:app)
apply plugin: 'android'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I had the same problem. I ran gradle from command line and that did work.
After that, I found File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle. There "Use local gradle distribution" was active. Changed it to "Use default gradle wrapper (recommended)" and it worked.
I have had a same problem. And I have found a solution.
Cause
This problem is caused by android gradle plugin does not match for gradle version.
Solution
Edit build.gradle in project. gradle plugin version must be satisfied requirements for android studio.
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
And edit distrubutionUrl in gradle/wrapper/gradle-wrapper.properties. version of gradle must be satisfied requirements for gradle plugin.
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
You can find version compatibilities between android studio, android gradle plugin and gradle in this page
https://stackoverflow.com/a/29695756/3675925

Categories

Resources