I am having trouble in generating signed apk. Lint errors displayed on screen
Following error shows
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0, 27.1.0. Examples include 'com.android.support:animated-vector-drawable:28.0.0' and 'com.android.support:exifinterface:27.1.0'
Dependencies in build.gradle file is below:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design: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'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
//picasso libraray
implementation 'com.squareup.picasso:picasso:2.71828'
//retrofit libraries
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.okhttp3:okhttp:4.3.1'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
}
On this line
implementation 'com.android.support:appcompat-v7:28.0.0'
lint error occurred
AndroidX replaces the original support library APIs with packages in
the androidx namespace. Only the package and Maven artifact names
changed; class, method, and field names did not change.
Read official guideline about - Migrating to AndroidX. You should migrate to AndroidX.
With Android Studio 3.2 and higher, you can migrate an existing
project to AndroidX by selecting Refactor > Migrate to AndroidX from
the menu bar.
dependencies will be
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
Then add below in your build.gradle section.
android {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
Related
I am getting error in the whole class that extends BottomSheetDialogFragment
Cannot access 'androidx.lifecycle.HasDefaultViewModelProviderFactory' which is a supertype of 'FavoriteBottomDialogFragment'. Check your module classpath for missing or conflicting dependencies
The class is in app module and this module implements two other modules : core and presentation-core
build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project (':core')
implementation project (':presentation-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
testImplementation 'junit:junit:4.12'
implementation "com.google.android.material:material:1.1.0"
//Rx
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
implementation "io.reactivex.rxjava2:rxjava:2.2.9"
//Architecture component
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.room:room-runtime:2.0.0'
kapt 'androidx.room:room-compiler:2.0.0'
kapt 'androidx.lifecycle:lifecycle-common-java8:2.0.0'
implementation 'androidx.room:room-rxjava2:2.0.0'
implementation 'androidx.room:room-guava:2.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
}
core dependencies
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4"
api 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'
//library to serialize Java Objects between Contexts
implementation 'org.parceler:parceler-api:1.1.11'
kapt 'org.parceler:parceler:1.1.11'
//testing dependencies
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation "org.mockito:mockito-core:2.24.5"
androidTestImplementation "org.mockito:mockito-android:2.24.5"
//architecture component
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
implementation "androidx.lifecycle:lifecycle-livedata:2.0.0"
//RxJava2
implementation "io.reactivex.rxjava2:rxjava:2.2.9"
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
}
presentation-core
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
}
BottomSheetDialogFragment
Even with errors i got, I can run the project in a device
I experienced this exact same problem today, and was able to solve.
Turns out the issue was a version mismatch between the expected version of androidx.lifecycle:lifecycle-viewmodel used by the module where the "failing" class is and a later version in some other dependent code.
So in my case, my module was using version 2.1.0 of this module, but one of the dependencies was using version 2.2.0. The code will compile no problem, because gradle resolves the dependency to the latest version; however Android Studio is somehow confused by this situation (not always, because this doesn't happen all the time, but sometimes – this isn't the first time I've seen this.)
Therefore solution is: figure out what the latest version of this library is in your app and update your build.gradle for this module to point to the same version that gradle is resolving to. Or:
run gradlew app:dependencies
search the result for lifecycle-viewmodel
update build.gradle in your app to depend on lifecycle-viewmodel with the version that gradle says it is resolving to
Sync project with gradle files
in my case (an Android module), Android Studio 4.0.1, I get a number of warnings in the IDE related to androidx.lifecycle.HasDefaultViewModelProviderFactory,
I have solved the issue by adding this line to build.gradle:
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
thus the beginning of build.gradle becomes:
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
...
In my case, the problem was solved adding the lifecycle viewmodel dependency in the module of the troubled class.
Add dependency into you build gradle androidx.fragment:fragment-ktx:x.x.x with actual version. For activity you must add androidx.activity:activity-ktx:x.x.x. I hope this helps you, in my case it solved the problem.
I added the following lines to build.gradle to solve the same issue in a module:
def archLifecycleVersion = '2.2.0'
implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion"
kapt "androidx.lifecycle:lifecycle-compiler:$archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
Your androidx.lifecycle:lifecycle-XXX dependency versions must be the same.
in my case:
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.1"
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0, 27.0.2. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:cardview-v7:27.0.
Whatever API I use gives me the same error.
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'
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
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'
The android team has been working on migrating the support libraries to androidx. This allows you to mix and match better.
Backup your project and in android studio go to
Refractor > Migrate to AndroidX
Add explicitly the library with the old version but with a new version number.
In your case implementation 'com.android.support:cardview-v7:28.0.0' so you need to add:
implementation 'com.android.support:cardview-v7:28.0.0'
ie: Take the library from the second item, and implement it with the version number from the first.
Note: don't forget to press sync now
Now after changes your dependencies will look like this:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation "com.android.support:support-media-compat:28.0.0"
implementation "com.android.support:customtabs:28.0.0"
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
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'
When add firebase in
dependencies
implementation 'com.google.firebase:firebase-core:16.0.6'
Or
implementation 'com.google.firebase:firebase-ads:17.1.2'
Or
implementation 'com.google.android.gms:play-services-ads:17.1.1
It shows error under implementation 'com.android.support:appcompat-v7:28.0.0' that All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes).
When I sync the app no error but when install the app it shows you app has been stopped (Crashing during run time).
When remove the firebase dependencies and run, my app it's working fine.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
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'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-ads:17.1.2'
implementation 'com.google.android.gms:play-services-ads:17.1.1'
}
apply plugin: 'com.google.gms.google-services'
When you include dependencies, they too, will sometimes include dependencies of their own. Some of the firebase libraries happen to include support libraries at a lower version than 28. When you hover over the error message for appcompat-v7 it should tell you what library is lower than 28. You may have to click 'show more' on the error message. Once you figure out which one it is, include that exact same library but version 28. Resync your gradle and you're good to go. Also, you might have to do this multiple times because some firebase libraries include multiple lower version support libraries and the error message will only show you one library at a time.
I have following dependencies in my app-level build.gradle file
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.1.1'
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'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.android.support:cardview-v7:27.0.2'
}
These works fine without any error. But, When I try to put a new third party dependency of CircleImageView implementation 'de.hdodenhof:circleimageview:2.2.0', the gradle build fails and there is error on implementation 'com.android.support:appcompat-v7:27.0.2' line saying All com.android.support libraries must use the exact same version.... I am wondering how this third party library creating problem in support libraries. What is wrong there?
That library is implementing support libraries as well, but different versions. Specifically, it uses the support-annotations 27.1.0 library.
There are two things you can do.
Update your dependencies. 27.0.2 is outdated. 27.1.0 is as well, but less so.
Exclude that library from your implementation and implement it yourself:
implementation ("de.hdodenhof:circleimageview:2.2.0") {
exclude group: "com.android.support" module: "support-annotations"
}
implementation 'com.android.support:support-annotations:27.1.1'
You should update all your support dependencies to 27.1.1.
The third party library internally uses the app compat library and because the version used by project is different from the library version, it gives the error. Updating appcompat, design and cardview dependencies to version 27.1.1 worked fine as follows.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.1.1'
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'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
}
If you want all support libraries including third party libraries internally use the same support library version, then add below code in your project level gradle
ext {
support_library_version = '27.1.1'
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex')) {
details.useVersion "$support_library_version"
}
}
}
}
The support libraries should have the same version as the other dependencies which are related.
Change them to v 27.1.1 (The point is they should have the same version):
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
And then if you saw any errors which points to "should have same version", run :
./gradlew dependencies
To see which library is using old version.
Mostly, it can be fixed by adding the updated version of the library (same as the support library) in your build.gradle dependencies.
I had an Android project with gradle 2.2.0 and android-apt plugin 1.8. I had time to update it to newer tools gradle 3.1.0 and remove apt plugin to use newer proposed solution with implementation/CompileOnly and annotation processor keywords. After that project build/compile correctly and apk file is pushed to device but when I open class that uses: butterknife, tourguide, FancyToast or material-dialogs libraries class not see this dependencies (imports & references are marked in red).
Did anyone had the same issue?
Current dependencies:
dependencies {
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
annotationProcessor "org.projectlombok:lombok:1.16.12"
compileOnly "org.projectlombok:lombok:1.16.12"
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation ('com.github.worker8:tourguide:1.0.14-SNAPSHOT#aar') {
transitive = true;
}
implementation files('libs/greendao-2.1.0.jar')
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
//dagger
compileOnly 'javax.annotation:jsr250-api:1.0'
implementation 'com.google.dagger:dagger:2.0.2'
annotationProcessor 'com.google.dagger:dagger-compiler:2.0.2'
implementation('com.crashlytics.sdk.android:crashlytics:2.6.2#aar') {
transitive = true;
}
//save player objects (protect from removing it)
implementation 'com.google.code.gson:gson:2.7'
//permutation library
implementation 'com.googlecode.combinatoricslib:combinatoricslib:2.1'
//new toasts
implementation 'com.github.Shashank02051997:FancyToast-Android:0.1.3'
//tests
testImplementation 'junit:junit:4.12'
testImplementation "org.mockito:mockito-core:2.+"}
Project compiles/works but it is obstacle to work with this libraries
If your dependencies declared in different module you should use api instead of implementation
eg:
api 'com.google.dagger:dagger:2.0.2'