How to get dependencies right for WorkManager and LocationServices? - android

I've been unable to get the dependencies right for an app that uses a worker for obtaining device locations. I suspect that I'm using the wrong location service with androidx, but I haven't found anything else. Here's my build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.exelor.laytrax"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1'
implementation 'androidx.work:work-runtime:2.1.0-alpha02'
implementation 'com.google.android.material:material:1.1.0-alpha06'
implementation ('com.google.android.gms:play-services-location:16.0.0') {
exclude group: 'com.android.support'
}
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
I'm excluding com.android.support to avoid build exceptions, such as
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.1.0-beta01) and classes.jar (com.android.support:support-compat:26.1.0)
At runtime in worker doWork():
fusedLocationClient = LocationServices.getFusedLocationProviderClient(context.applicationContext)
throws this exception:
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArraySet;
at com.google.android.gms.common.api.internal.GoogleApiManager.<init>(Unknown Source:29)

My problem was not having a gradle.properties file containing
android.enableJetifier=true
android.useAndroidX=true

Related

Failed to resolve com.androidAffected Modules and com.loopjAffected Modules in android

Failed to resolve com.androidAffected Modules and com.loopjAffected Modules in android.
I have checked with different links but I am confused.
Below is my App build file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.XXX.XXXX"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:25.3.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:cardview v7:25.3.1'
implementation 'com.github.bumptech.glide:glide:3.6.1'
implementation 'me.dm7.barcodescanner:zxing:1.8.4'
implementation 'com.loopj.android:androidasync http:1.4.9'
implementation 'com.google.code.gson:gson:2.6.2'
implementation project(':merchantsdk')
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'
}
MerchantSDK is the aar file which is imported into this project and then I build giving below exceptions
Failed to resolve com.androidAffected Modules and
Failed to resolve com.loopjAffected Modules
Please help me on this.Thanks in advance.
If it is an AAR file you can keep it "lib" folder. You can add dependancy for this AAR in build.gradle as follows: -
implementation "packagename of aar:aar filename:#aar"
Replace package name and filename of AAR.
In build.gradle file of main project add this: -
allprojects {
repositories {
flatDir { dirs 'libs' }
}
}

e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:

supertypes of the following classes cannot be resolved. please make sure you have the required dependency in the classpath : class com.google.firebase.auth.internal.internalAuthProvider , unresolved supertypes
com.google.firebase.internal.internalTokenProvider
Here is the code:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.firebaseuiexample"
minSdkVersion 29
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation 'com.firebaseui:firebase-ui-auth:4.3.2'
}
apply plugin: 'com.google.gms.google-services'
implementation 'com.google.firebase:firebase-database:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.5'
change to these implementations.

Shows Please make sure you have the required dependencies in the classpath: class com.google.android.gms.vision.barcode.Barcode

Everything was working fine until I added implementation 'com.google.android.gms:play-services-ads:18.2.0' this dependency for showing ads in-app.
I am getting below error message while building the application. error gets removed if I remove ad library.
Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class com.google.android.gms.vision.barcode.Barcode, unresolved supertypes: com.google.android.gms.internal.zzbck
App level build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.creatorisone.chargingtheftsecurityalarm"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.04"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), "proguard-rules.pro"
}
}
configurations {
cleanedAnnotations
compile.exclude group: 'org.jetbrains', module: 'annotations'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'org.jetbrains:annotations-java5:17.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50"
implementation 'xyz.belvi.mobilevision:barcodescanner:2.0.3'
implementation 'androidx.fragment:fragment:1.2.0-alpha02'
implementation 'com.google.zxing:core:3.3.3'
implementation 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
implementation 'com.google.android.gms:play-services-ads:18.2.0'
}
repositories {
mavenCentral()
}
I have tried multiple solutions provided on StackOverflow but nothing is working in my case
"Error: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath"
error in Location Request class in android with kotlin
error: supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath
"Supertypes of the following classes cannot be resolved.” in Task:app:buildInfoGeneratorDebug
I have faced same problem and its resolve by adding
implementation 'com.google.android.gms:play-services-vision:15.0.2'

Failed to resolve: androidx.lifecycle:lifecycle-viewmodel-ktx:1.1.1

I'm trying to use the new Navigation Architecture Component for android and I'm getting the error
Failed to resolve: androidx.lifecycle:lifecycle-viewmodel-ktx:1.1.1
when I'm defining the lifecycle_version to "1.1.1"
I'm basically just copying and pasting what is in the documentation so I'm running out of ideas of what is wrong in here :(
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.mobile.codgin.newnavigation"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
def lifecycle_version = "1.1.1"
// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
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'
}
try replace
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
with this
//https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel-ktx
implementation group: 'androidx.lifecycle', name:'lifecycle-viewmodel-ktx', version: '2.0.0-alpha1'
then sync again.
You can have a look here :
https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel-ktx/2.0.0-alpha1
it seems to be that the repository was emptied somehow. Hence, you can not download it from the repository.
When it shows you this error add this code to section build.gradle
configurations {
all {
exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
}
}

Error in using ArthurHub image crop library with kotlin

I am using ArthurHub image crop library in my project. but this error occurs
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
i have tried many solutions that were provided in other questions, but none of them works for me.
my build.gradle(module) file is here
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.lenovo.chatapp"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-auth:12.0.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.google.firebase:firebase-database:12.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
implementation 'com.google.firebase:firebase-core:12.0.0'
}
repositories {
mavenCentral()
}
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

Categories

Resources