I was making an application (API 26) which uses RecyclerView. I use the following line in my build l.gradle
dependencies {
implementation 'com.android.support:recyclerview-v7:28.0.0'
}
But however this doesn't work of API 26. Is there any way that I can use Recyclerview for API 26. Thank you!
Why don't you use androidX?
To know more details about it you can visit https://developer.android.com/jetpack/androidx
dependencies {
implementation 'androidx.recyclerview:recyclerview:1.1.0'
}
Related
How is it possible that I get this message? It does not make any sense.
I'm using com.squareup.retrofit2:retrofit:2.9.0
Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 30
at okhttp3.internal.platform.AndroidPlatform$Companion.buildIfSupported(AndroidPlatform.kt:370)
at okhttp3.internal.platform.Platform$Companion.findPlatform(Platform.kt:204)
at okhttp3.internal.platform.Platform$Companion.access$findPlatform(Platform.kt:178)
2020-09-16 12:37:07.645 6480-6480/lv.ltt.gasogmp.dev_v3 E/AndroidRuntime: at
okhttp3.internal.platform.Platform.<clinit>(Platform.kt:179)
Add an explicit dependency on OkHttp 4.9.0. Or whatever is newest at the time you read this.
This bug is embarrassing but it's been fixed for so long that you shouldn’t be encountering it in new code.
Just Add the Dependency implementation 'com.squareup.okhttp3:okhttp:4.9.2'
PS - Check the latest version here before you add the dependency https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
Add implementation 'com.squareup.okhttp3:okhttp:4.9.2' inside android\app\build.gradle
dependencies {
........
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.squareup.okhttp3:okhttp:4.9.2'
..........
}
Upgrage Okhttp3 or retrofit version
Latest Okhttp3 version is 4.9.2
Latest Retrofit version is 2.9.0
implementation 'com.squareup.okhttp3:okhttp:4.9.2'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
I used Retrofit library in my android application. My project's minSDK is 16. Now I see that my apps not working on SDK < 21 because of retrofit version. My retrofit version:
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
I tested OkHttp 2 but it is not adapted with my retrofit. What should I do?
The problem is that OkHttp3, from version 3.13.0 upped its minimum SDK version to API 21+.
If you just want to do basic HTTP(s) requests and do not care about TLS 1.2, then you can just exclude that specific version and use 3.12.13 which is the last version to support minSDK 9+.
implementation("com.squareup.retrofit2:retrofit:2.9.0") {
exclude group: "com.squareup.okhttp3"
}
implementation "com.squareup.okhttp3:okhttp:3.12.13"
Add this to your build.gradle file and things should start working. However, from the next version, you should ideally be removing this and up your minSDK level to 21+.
Add these lines in build gradle file:
// retrofit, gson
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.2'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
implementation 'com.squareup:otto:1.3.8'
implementation 'com.google.code.gson:gson:2.8.5'
This is complete package of retrofit
I am trying to implement a cardView, where when the user presses the FAB, a cardView is created dynamically. However, when I put the following bit of code in the gradle dependencies, I get an error:
implementation 'com.android.support:cardview-v7:23.0.+'
implementation 'com.android.support:recyclerview-v7:23.0.+'
It says 'This support library should not use a different version (23)
than the compileSdkversion 27.
Currently, my apk level is 16.
What's the problem?
Just replace with this dependency in your Gradle.build:
com.android.support:cardview-v7:27.1.1
com.android.support:recyclerview-v7:27.1.1
Currently, you have used compileSdkversion 27. So you need to update dependency to 27.
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
Don't try to use + sign for integrating dependency.
I am trying to implement ViewModel in a 100% Kotlin app. Every piece of documentation I can find says I want to use this to get the ViewModel instance:
ViewModelProviders.of(this).get(CustomViewModel::class.java)
According to the docs, I should be able to import this with:
import android.arch.lifecycle.ViewModelProviders
This import is unresolved though. I am using the following in my build file:
def androidArchVersion = '1.1.1'
implementation "android.arch.lifecycle:viewmodel:$androidArchVersion"
implementation "android.arch.lifecycle:livedata:$androidArchVersion"
annotationProcessor "android.arch.lifecycler:compiler:$androidArchVersion"
testImplementation "android.arch.core:core-testing:$androidArchVersion"
Why can't I access ViewModelProviders?
Include the following as a dependency:
implementation "android.arch.lifecycle:extensions:1.1.1"
The equivalent AndroidX dependency is:
"androidx.lifecycle:lifecycle-extensions:VERSION"
in where VERSION can be replaced for Current Stable, Beta or Alpha values given in this official link
This dependency is for both ViewModel and LiveData and thus would not require you to give separate dependencies for the same either; i.e. the first two dependencies indicated by you can be replaced by the aforementioned lifecycle extensions dependency.
In my case I was missing :
implementation "androidx.fragment:fragment-ktx:1.1.0"
In addition to what Sup suggested, you'll have to correct lifecycler:compiler to lifecycle:compiler - the Gradle sync shouldn't even complete successfully with this typo.
Secondly, the standard android annotation processing ("annotationProcessor") doesn't really work with Kotlin. Instead, use Kotlin's kapt.
At the top of your build.gradle file, add the following:
apply plugin: 'kotlin-kapt'.
And in your dependencies section, replace occurences of annotationProcessor (like the above one) with kapt, e.g.
kapt "android.arch.lifecycle:compiler:1.1.1"
ViewModelProviders is deprecated in 1.1.0
Check this android docs
https://developer.android.com/topic/libraries/architecture/viewmodel
I am using 2.3.1 and add below dependency in build.gradle
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
Declare ViewModel in your Kotlin code as per below:
private val cartViewModel: CartViewModel by viewModels()
Still, if you facing below error like
Unresolved reference: viewModels
Then need to add below below dependency in build.gradle
implementation 'androidx.lifecycle:lifecycle-extensions-ktx:2.2.0'
implementation 'androidx.activity:activity-ktx:1.4.0'
implementation 'androidx.fragment:fragment-ktx:1.3.6'
OR
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
I solve this by doing like this.
implement this dependency
implementation "android.arch.lifecycle:extensions:1.1.1"
then call my ViewModel class
homeViewModel = ViewModelProvider(this).get(HomeViewModel::class.java)
I faced this kind of problem in AndroidStudio 3.0.1 and solved by adding
following dependencies in the proper build.gradle:
implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
version code may be different as AndroidStudio tells you if it differs.
If the above "adding/updating dependecies" did not resolve your issue then try to restart your android studio. It´s just to root, I do not see any major issue with it. Hope it helps.
Resolved with this dependency for me
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
If someone want androidx, then, first - in build.gradle (app):
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
Second - in file with code:
import androidx.lifecycle.ViewModelProvider
And third - use it:
ViewModelProvider(this).get(CustomViewModel::class.java)
Or use it like this (if needed ViewModelFactory):
ViewModelProvider(this, CustomViewModelFactory).get(CustomViewModel::class.java)
Not really sure why there are soo many solutions to this problem however while none of these worked for me, I did find a solution in my case.
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.1"
This can also be resolved by targeting minSdkVersion to 21.
If you have minSdkVersion 21 or higher, you won't need implementation "android.arch.lifecycle:extensions:1.1.1".
android {
kotlinOptions {
jvmTarget = '1.8'
}
}
project e app level
Situation:
I am trying to add Google SignIn button to my project using the Custom Google SignIn Button library like the one shown above:
Here is my build.gradle file:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
compile 'com.shobhitpuri.custombuttons:google-signin:1.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'
}
Problem:
I get the following error:
Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version 16 declared in library [com.shobhitpuri.custombuttons:google-signin:1.0.0]
C:\Users\durga rao.gradle\caches\transforms-1\files-1.1\google-signin-1.0.0.aar\4fa7da22804ff19ac92142afd0b85e2b\AndroidManifest.xml as the library might be using APIs not available in 15 Suggestion: use a compatible library with a minSdk of at most 15,or increase this project's minSdk version to at least 16, or use tools:overrideLibrary="com.shobhitpuri.custombuttons" to force usage (may lead to runtime failures)
Initial solution:
From the tags on the question, it looks like you are using Android Studio 3.0, which uses Gradle 3.0 and above. One of the breaking changes with Gradle 3.0 plugin based on Use the new dependency configurations
documentation is that the compile keyword has been replaced with implementation. So for adding Custom Google SignIn Button library, instead of compile keyword with the library use:
implementation 'com.shobhitpuri.custombuttons:google-signin:1.0.0'
Update:
Based on the error you mentioned, it seems in your project's build.gradle, your minSdkVersion is set to 15. The Custom Google SignIn Button library supports minSdkVersion of 16 since based on Platform Version Distribution Chart, 99.3% of the Android devices in the world are running API 16 and above. Changing your projects minSdkVersion to 16 should solve the issue. Hope this helps.
Disclaimer: I am the author of the library. Please let me know if you face any issues. Would be happy to help.