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.
Related
I am developing a project in which I have used Firebase and Google Play service maps and location. Here is my app-level build Gradle file.
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "com.google.android.gms:play-services-location:$playServicesVersion"
implementation "com.google.android.gms:play-services-maps:$playServicesVersion"
implementation 'com.google.android.libraries.places:places:2.0.0'
implementation "com.google.firebase:firebase-core:$firebaseCoreVersion"
implementation "com.google.firebase:firebase-perf:$firebasePerfVersion"
implementation "com.google.firebase:firebase-messaging:$firebaseMessagingVersion"
implementation "com.crashlytics.sdk.android:crashlytics:$crashlyticsVersion"
// Room
implementation 'androidx.room:room-runtime:2.1.0'
annotationProcessor 'androidx.room:room-compiler:2.1.0'
// LiveData and ViewModel
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.0.0'
implementation "net.danlew:android.joda:$jodaTimeVersion"
// Annotations
implementation 'androidx.annotation:annotation:1.1.0'
implementation "com.squareup.picasso:picasso:$picassoVersion"
dependencies {
implementation 'com.github.TouchBoarder:weekdays-buttons-bar:v1.0.2'
}
Now, this all works fine and the application runs normally. But when I tried to add below line:
implementation 'com.google.android.gms:play-services-ads:17.0.0'
then the following error comes
cannot fit requested classes in a single dex file
I have searched that and found out some solutions like multi dex enabled and minifyenabled for debug but the when these solutions applied then the app runs and crash on start always.
I also applied the solution of removing some libraries just to check whether Google Ads gradle library can be added but it shows the same error. Even if I remove 3-4 libraries and add one Google Ad library then the error still the same.
What to do in this case.
Please make sure you are using the same version of all libs of Google Play Services. Also, enable multidex for your application.
implementation "androidx.multidex:multidex:2.0.1"
prior approach:
Instead of implementing entire ads library, you should implement only required one...
Check out this link for further info:
Other Approach.
You can follow this link.
Versions of the platform prior to Android 5.0 (API level 21) use the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file per APK. In order to get around this limitation, you can add the multidex support library to your project:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as shown here:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
...
}
Hope you will have your solution.
I have buildToolVersion '28.0.3', which is the most most recent, and i have
implementation 'com.android.support:appcompat-v7:28.0.3'
// RecyclerView
implementation 'com.android.support:recyclerview-v7:28.0.3'
in my build gradle file, and in an cloned from google codelabs, where recyclerview is used, it doesn't show import option, i can't use recyclerview.
Had to use buildToolVersion 28.0.0, added these lines in build.gradle
implementation 'com.android.support:appcompat-v7:28.0.0'
// RecyclerView
implementation 'com.android.support:recyclerview-v7:28.0.0'
and now in the classes it uses,
import androidx.recyclerview.widget.RecyclerView.
and it works now.
I am new to Android App Development. When I tried to create a new project,Android Project...the following message popped up..
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]
This is the screenshot of my project
click here to see screenshot of the error i got
i also tried adding this code to my dependency..
androidTestCompile 'com.android.support:support-annotations:23.3.0'
this didn't work out. I also tried 27.1.1 and 26.1.0..
that didn't work out either.
Based on your screenshot i found two working solutions:
First solution: add to dependencies of your gradle module this line
compile 'com.android.support:support-annotations:27.1.1'
and sync your project
Note: if you are using Android studio 3+ change compile to implementation
Second solution: Configure project-wide properties found in the documentation https://developer.android.com/studio/build/gradle-tips.html#configure-project-wide-properties
in project gradle add this line:
// This block encapsulates custom properties and makes them available to all
// modules in the project.
ext {
// The following are only a few examples of the types of properties you can define.
compileSdkVersion = 26
// You can also use this to specify versions for dependencies. Having consistent
// versions between modules can avoid behavior conflicts.
supportLibVersion = "27.1.1"
}
Then to access this section change compileSdkVersionline to be
compileSdkVersion rootProject.ext.compileSdkVersion
and at dependencies section change the imported library to be like this:
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
and sync your project
Note: if you are using Android studio 3+ change compile to implementation
For the difference between compile and implementation look at this
What's the difference between implementation and compile in gradle
Add the below line in your app.gradle file before depencencies block.
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:26.1.0'
}
}
There's also screenshot below for a better understanding.
the configurations.all block will only be helpful if you want your target sdk to be 26. If you can change it to 27 the error will be gone without adding the configuration block in app.gradle file.
There is one more way if you would remove all the test implementation from app.gradle file it would resolve the error and in this also you dont need to add the configuration block nor you need to change the targetsdk version.
If you use version 26 then inside dependencies version should be 1.0.1 and 3.0.1 i.e., as follows
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
If you use version 27 then inside dependencies version should be 1.0.2 and 3.0.2 i.e., as follows
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
If you using Android Studio 3.1.+ or above
just put this in your gradle depedencies:
implementation 'com.android.support:support-annotations:27.1.1'
Overall like this:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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:support-annotations:27.1.1'
}
This is due a conflict of versions, to solve it, just force an update of your support-annotations version, adding this line on your module: app gradle
implementation ('com.android.support:support-annotations:27.1.1')
Hope this solves your issue ;)
Edit
Almost forgot, you can declare a single extra property (https://docs.gradle.org/current/userguide/writing_build_scripts.html#sec:extra_properties) for the version, go to your project (or your top) gradle file, and declare your support, or just for this example, annotation version var
ext.annotation_version = "27.1.1"
Then in your module gradle replace it with:
implementation ("com.android.support:support-annotations:$annotation_version")
This is very similar to the #emadabel solution, which is a good alternative for doing it, but without the block, or the rootproject prefix.
Adding this to build.gradle (Module app) worked for me:
compile 'com.android.support:support-annotations:27.1.1'
Don't worry It is simple:
Go to the "Project" Directory structure and in that go to "Gradle Scripts" and inside it go to "build.gradle (Module:app)" and double click it.
Now -
Scroll down the program and in that go to the dependencies section :
Like below
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
}
Now in this Delete the last two lines of code and rebuild the app and now it will work
The dependencies should be:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
}
REBUILD THE APP AND IT WORKS !!
Go to the build.gradle(Module App) in your project:
Follow the pic and change those version:
compileSdkVersion: 27
targetSdkVersion: 27
and if android studio version 2:
Change the line with this line:
compile 'com.android.support:appcompat-v7:27.1.1'
else
Change the line with this line:
implementation 'com.android.support:appcompat-v7:27.1.1'
and hopefully, you will solve your bug.
Add this to your gradle file.
implementation 'com.android.support:support-annotations:27.1.1'
Another simple way to solve this problem is to edit your build.gradle (app):
Go to android tag and change compileSdkVersion 26 to compileSdkVersion 27
Go to defaultConfig tag and change targetSdkVersion 26 to targetSdkVersion 27
Got to dependencies tag and change implementation 'com.android.support:appcompat-v7:26.1.0' to implementation 'com.android.support:appcompat-v7:27.1.1'
I have the same problem, in build.gradle (Module:app)
add the following line of code inside dependencies:
dependencies
{
...
compile 'com.android.support:support-annotations:27.1.1'
}
It worked for me perfectly
Important Update
Go to project level build.gradle, define global variables
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlinVersion = '1.2.61'
ext.global_minSdkVersion = 16
ext.global_targetSdkVersion = 28
ext.global_buildToolsVersion = '28.0.1'
ext.global_supportLibVersion = '27.1.1'
}
Go to app level build.gradle, and use global variables
app build.gradle
android {
compileSdkVersion global_targetSdkVersion
buildToolsVersion global_buildToolsVersion
defaultConfig {
minSdkVersion global_minSdkVersion
targetSdkVersion global_targetSdkVersion
}
...
dependencies {
implementation "com.android.support:appcompat-v7:$global_supportLibVersion"
implementation "com.android.support:recyclerview-v7:$global_supportLibVersion"
// and so on...
}
some library build.gradle
android {
compileSdkVersion global_targetSdkVersion
buildToolsVersion global_buildToolsVersion
defaultConfig {
minSdkVersion global_minSdkVersion
targetSdkVersion global_targetSdkVersion
}
...
dependencies {
implementation "com.android.support:appcompat-v7:$global_supportLibVersion"
implementation "com.android.support:recyclerview-v7:$global_supportLibVersion"
// and so on...
}
The solution is to make your versions same as in all modules. So that you don't have conflicts.
Important Tips
I felt when I have updated versions of everything- gradle, sdks,
libraries etc. then I face less errors. Because developers are working
hard to make it easy development on Android Studio.
Always have latest but stable versions Unstable versions are alpha, beta and rc, ignore them in developing.
I have updated all below in my projects, and I don't face these errors anymore.
Update Android Studio (Track release)
Project level build.gradle - classpath 'com.android.tools.build:gradle:3.2.0' (Track android.build.gradle release & this)
Have updated buildToolVersion (Track buildToolVersion release)
Have latest compileSdkVersion and targetSdkVersion Track platform release
Have updated library versions, because after above updates, its necessary. (#See How to update)
Happy coding! :)
If changing target sdk version doesn't help then if you have any dependency with version 3.0.2 then change it to 3.0.1.
e.g change
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
to
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.1'
A better solution is explained in the official explanation. I left the answer I have given before under the horizontal line.
According to the solution there:
Use an external tag and write down the following code below in the top-level build.gradle file. You're going to change the version to a variable rather than a static version number.
ext {
compileSdkVersion = 26
supportLibVersion = "27.1.1"
}
Change the static version numbers in your app-level build.gradle file, the one has (Module: app) near.
android {
compileSdkVersion rootProject.ext.compileSdkVersion // It was 26 for example
// the below lines will stay
}
// here there are some other stuff maybe
dependencies {
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
// the below lines will stay
}
Sync your project and you'll get no errors.
You don't need to add anything to Gradle scripts. Install the necessary SDKs and the problem will be solved.
In your case, install the libraries below from Preferences > Android SDK or Tools > Android > SDK Manager
Add this line under the dependencies in your gradle file
compile 'com.android.support:support-annotations:27.1.1'
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.
Why am I getting this error? My repository and Google play services are up to date and I've used all the requires steps for using Firebase like copying firebase code in both build.gradle(Project and app). The intellisence doesn't even show FirebaseAuth but displays other members of Firebase.
Solved the error by adding this to the build.gradle file(for app) -
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
The 2nd dependency is to solve the version conflict error.
Add this dependency to Gradle.Build(Module:App)
compile "com.google.firebase:firebase-auth:9.0.2"
then sync with gradle :)
Add these two dependencies into your build.gradle
as 'compile' is replaced by 'implementation'
dependencies {
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation "com.google.android.gms:play-services-gcm:16.0.0"
}
***For the latest android studio version 3.0 and new ones ***
Same problem. Clean your project with "Build"->"Clean Project".
add the following to the build.gradle (app)
implementation 'com.google.firebase:firebase-auth:9.2.1'
For me this worked with all the firebase extensions:
eg.:
Android studio adds the following line to your gradle file:
implementation 'com.google.firebase:firebase-auth:16.0.1:15.0.0'
You have to change it to:
implementation 'com.google.firebase:firebase-auth:16.0.1'
and add:
kapt 'com.google.firebase:firebase-auth:16.0.1:15.0.0'
I have android studio 3.3.1 installed. Compile is replaced with implementation. So you have to write
implementation 'com.google.firebase:firebase-auth:16.1.0'
You should replace version according to the warning you get.
on dependencies in app gradle
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
this is useful android 3.0 and onwards versions auth:16.0.1 and
core:16.0.1Firebase will work
Solved the error by adding this to the build.gradle file(for app) -
compile 'com.google.firebase:firebase-auth:9.2.1'
compile "com.google.android.gms:play-services-gcm:9.2.1"
You may need to make sure that your activity is importing the Firebase Auth module. In your .java file (eg. Login.java):
import com.google.firebase.auth.FirebaseAuth;
Please add the below line in your build.gradle file:
implementation 'com.google.firebase:firebase-auth:19.3.0'
implementation "com.google.android.gms:play-services-gcm:10.2.1"
In my case, I was using firebase-auth and firebase-messaging with different versions. So After getting an error I kept the same version for both e.g.
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
After sync, my problem was solved. try to keep the version the same for firebase libraries
implementation 'com.google.firebase:firebase-auth:16.0.1'
make sure your firebase and all the dependency are the same versions.