I want to increase the target api level of my app without affecting other libraries that the app depends on, such as firebase and alike. I tried changing it in project structure under app module but this did not work out. Nothing changed in gradle file
My next option is to increase it by editing the gradle file itself and increasing to api level 28. I am however scared of the effects this may have on the other libraries.
Below is my build gradle file, please assist me.
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.chomba.haroldking.kuta"
minSdkVersion 16
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'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
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.3'
implementation 'com.android.support:design:26.1.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.android.volley:volley:1.1.0'
implementation 'com.jakewharton.threetenabp:threetenabp:1.2.1'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.firebaseui:firebase-ui-database:3.1.0'
implementation 'com.android.support:palette-v7:26.1.0'
implementation 'com.wdullaer:materialdatetimepicker:3.1.3'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.google.firebase:firebase-storage:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
Do I need to make changes to the other libraries
To upgrade your targetSdkVersion you should update it in build.gradle together with the compileSdkVersion (you will get an error if you don't update it as well).
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
}
}
Once you update the targetSdkVersion and the compileSdkVersion you'll also need to update the support library versions to 28.0.0, because the support library's major version needs to match the targetSdkVersion. For example:
implementation 'com.android.support:appcompat-v7:28.0.0' // instead of 26.1.0
Version 28.0.0 is the final version of the support library. To keep using the support libraries after you upgrade to API 29 you should migrate to AndroidX.
When updating you should also check if there have been relevant changes in Android 9 that you need to consider.
In your case you cannot update the targetSdkVersion without also updating the dependencies.
I tried changing it in project structure under app module but this did not work out. Nothing changed in gradle file My next option is to increase it by editing the gradle file itself and increasing to api level 28.
Changing it in project structure wouldn't do any magic for you, you still have to follow the same process as you would by changing the gradle file.
I am however scared of the effects this may have on the other libraries
Keep the 3rd party libraries up to date as well, using newer versions of libraries in older sdks will most likely cause issues as newer Android SDKs have behavior changes.
Here are some personal tips for migrating without being overwhelmed by the things it might break:
1. Increment your target api by 1 each time and then fully test it
For example, upgrade to api 27 from 26, test it and then upgrade it to 28 and so on. The reason for this is to narrow down and account for behavior changes in each api since the previous target api. Not only will it be less overwhelming, it would be easier to find solutions for the problems that might occur afterwards. If you migrate to 29 from 26 directly, it would be very difficult to identify the issue.
2. Read Migration Guides for each Android SDK
These pages were really helpful in identifying deprecated classes/features being used even by third party libraries:
Android 8.0 Migration Guide
Android 9.0 Migration Guide
3. If there is a problem in third party library after upgrading, it is most likely in Github Issues page. If it isn't there, create a new issue (following the guidelines listed there). There is no better place to get library specific answers than the repository site where the developers themselves can give you good suggestions.
4. Read the changelog starting from the previous version of libraries that have issues.
Some libraries have outdated documentation and newer versions can cause issues. For example, when I was migrating Dagger, there were some classes that were deprecated on newer versions but weren't documented and I only found out after reading the changelog.
Related
I'm trying to develop a location map for uni. The app itself works on my phone but I can't edit the XML file or preview it
I've already enabled virtualisation and have an i5 processor. I believe the issue lies in the Gradle build but don't know how to fix it.
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-maps:16.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'
And the error message:
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0, 26.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:support-media-compat:26.1.0 less... (Ctrl+F1)
Inspection info: There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion). Issue id: GradleCompatible
It looks like the media-compat:26 should be updated to a newer version but I can't find the code for it or the library and don't know how to download the library. Any help will be appreciated.
You need to set your compileSdkVersion and targetSdkVersion to 28. Because all your support libraries must match to your compileSdkVersion's root number. And, if you add more support libraries like- support:design or support:recyclerview-v7, you must add the same version (here you used 28.0.0). Otherwise, the app can crash at the runtime for mismatching. The full Google repository for android is here http://maven.google.com.
To know more about gradle dependencies of android, please go to official documentation here. For google play service API configuration, go to this link.
Try change implementation 'com.android.support:appcompat-v7:28.0.0' to:
implementation 'com.android.support:appcompat-v7:26.1.0'
compileSdkVersion 26
targetSdkVersion 26
All libraries must have the same version, in the case it looks like a conflict between com.google.android.gms: play-services-maps: 16.0.0 and implementation 'com.android.support: appcompat-v7:28.0.0'.
If you are using compileSdkVersion 28 try to find the latest version of the libraries in the maven repository.
https://mvnrepository.com/artifact/com.android.support/appcompat-v7/28.0.0
The Android Studio 3.1 layout preview fails to find style 'coordinatorLayoutStyle' in the current theme.
Failed to instantiated one or more classes.
Exception shown are :-
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
This happened due to use of alpha version SDK 28
We need to change the android { ... } in "build.gradle" in app file
compileSdkVersion 28 to compileSdkVersion 27
targetSdkVersion 28 to targetSdkVersion 27
Also, try to change implementations like
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' to
implementation 'com.android.support:appcompat-v7:27.1.1'
Hope this works!
For Android Studio v3.1.*, in addition we need change:
implementation 'com.android.support:design:28.0.0-alpha3' to
implementation 'com.android.support:design:27.1.1'
you can fix this issue by adding this script to the app module build.gradle, in the android section
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "27.+"
}
}
}
}
This appears to be a bug in the current version of Android Studio (3.1.3) as I was encountering the same thing. I downloaded the beta build from here and opened my existing project and the errors disappeared.
https://developer.android.com/studio/preview/?utm_source=android-studio
Not exactly a fix but hopefully it will get you back up and running.
Update
1. com.android.support:appcompat stable version 28.0.0 is released. So no need to downgrade version. Just use 28.0.0.
def supportVersion = "28.0.0"
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
You can ignore design library if you don't need it.
2: You also need to update your compileSdkVersion & targetSdkVersion to remove some gradle warnings.
compileSdkVersion 28
targetSdkVersion 28
Never use alpha versions of any library, because alpha, beta and rc
versions may have bugs. And you don't want to face these types of errors often.
Important Suggestion
I suggest you migrate to androidx because android will not update support library after 28.0.0, all updates will be available to androidx package only. Check related answer.
This is fixed in Android Studio 3.2.
Go to app/res/styles and change the Theme.AppCompat.Light.DarkActionBar for this one Base.Theme.AppCompat.Light.DarkActionBar
Trying to implement Firebase in my project.
Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.ghaleh.myapplication"
minSdkVersion 16
targetSdkVersion 27
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:27.1.1'
implementation 'com.android.support:support-media-compat:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
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-messaging:15.0.2'
}
apply plugin: 'com.google.gms.google-services'
And I'm getting this error:
All gms/firebase libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 15.1.0, 15.0.2, 15.0.1, 15.0.0. Examples include com.google.firebase:firebase-iid:15.1.0 and com.google.android.gms:play-services-measurement-base:15.0.2
According to Google's Maven Repository the latest version of firebase-messaging is 15.0.2 and I'm getting error for firebase-iid:15.1.0
So I cannot upgrade the firebase-messaging to a higher version or implement the firebase-iid:15.1.0 to match the versions.
I've already tried other solutions recommended here: 1, 2, 3 but non of them were useful.
I've also tried this (however it doesn't seem to be a proper solution):
implementation ('com.google.firebase:firebase-messaging:15.0.2') {
exclude group: "com.google.android.gms"
}
and I get this error:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForBazaarDebug'.
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Thanks in advance.
You need to update google-service plugin to use:
classpath 'com.google.gms:google-services:3.3.0'
to be able to avoid those errors, also upgrade to android studio 3.1
If you're not using Android Studio 3.1 to develop your app, you will need to upgrade in order to get the correct version checking behavior within the IDE.
more information and steps to follow:
Announcing new SDK versioning
Compilation failed to complete:Program type already present: com.google.android.gms.internal.measurement.zzabn
You may need to update
1.Playservice library
2.build tools
3.gradle wrapper
4.AndroidStudio
5.Migration to androidX
6.build tool version
I finally ended up with a proper build after doing this stuff !!!
This question already has answers here:
Error: fix the version conflict (google-services plugin)
(14 answers)
Closed 5 years ago.
I'm aware this question has been asked before, but I'm new to Android and Java in general. I've gone through the previous questions and tried various solutions but never seems to work.
I'm getting the "all com.android.support libraries must use the exact same version specification" warning in my app gradle file. My dependencies are:
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.tberwick.hishhash"
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:animated-vector-drawable:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
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 "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
implementation "android.arch.lifecycle:extensions:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"
}
The error I was receiving was
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.0.1, 26.1.0. Examples include com.android.support:animated-vector-drawable:27.0.1 and com.android.support:recyclerview-v7:26.1.0 less... (⌘F1)
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion.)
So I added in the specific line implementation 'com.android.support:animated-vector-drawable:26.1.0' but I still see the same error after syncing.
I've noticed that if I view my .idea/libraries folder that the app-compact and vector-drawable xml files in there get created for version 27.0.1 even though my versions are specified as 26.1.0
As I say I know this has been asked before but what I believe the solution should be based on those answers doesn't seem to work. I don't think I should use the versions 27.0.1 either as doing this complains about my targetSdkVersion (which I do understand)
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
Using a variable version like this is risky, in that all of a sudden your build can break, just because Facebook updated their library.
The current latest Facebook SDK version (4.29.0) wants to use 27.0.1 of the support libraries. Gradle uses the latest version requested by any dependency by default, as that is usually the safest course of action.
The best solution is to move to 27.0.1 for the support libraries, which in turn will trigger you to raise your compileSdkVersion to 27.
If something else is forcing you to use 26.1.0... there does not appear to be a Facebook SDK that specifically supports that version, based on a casual inspection of the POM files for their SDK artifacts.
You could replace the above line by:
implementation 'com.facebook.android:facebook-android-sdk:4.28.0'
4.28.0 of the Facebook SDK wants 25.3.1 of the support libraries, and so Gradle will tend to use the 26.1.0 that you are requesting. However:
You may get a variation of the original error, complaining about a mix of 26.1.0 and 25.3.1. That's where the solution that you tried applying — manually requesting the offending artifact for 26.1.0 — will help. You can use that approach to raise the version number that Gradle uses, but not lower it.
It is conceivable that the Facebook SDK will be cranky when using 26.1.0 of the support libraries.
With the following gradle script, I was wondering how to change the minSdkVersion from 7 to 3 (just so my app could run on more devices) without getting the error at the bottom of this post:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "dpark.cellular_automata"
minSdkVersion 3
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
... And then I would get the following error:
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : uses-sdk:minSdkVersion 3 cannot be smaller than version 7 declared in library [com.android.support:appcompat-v7:23.0.1] C:\Users\Dave\AndroidStudioProjects\Cellular_Automata\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.0.1\AndroidManifest.xml
Suggestion: use tools:overrideLibrary="android.support.v7.appcompat" to force usage
... That said, is it even possible to lower my minimum SDK to 3 (version 1.5, Cupcake) if I wanted to publish my app with Google Play? And also, in case you're wondering, I also downloaded the Android Support Library in the SDK manager as follows, and yet it still doesn't work:
Thanks!
That error is telling you that one of your libraries (in this case, AppCompat) only supports back to SDK version 7. Since that library cannot support anything lower than 7 and you use that library, you can't support anything lower than 7.
Your options are either:
Remove AppCompat
Support a minimum of API level 7. Note that SDK version 8 currently has less than 0.1% of the market share globally, and all versions less than 8 have a combined total of 1%. It probably isn't worth your time.
That said, is it even possible to lower my minimum SDK to 3 (version 1.5, Cupcake) if I wanted to publish my app with Google Play?
Absolutely. You could upload an Android app supporting API level 1 if you really wanted to.
And also, in case you're wondering, I also downloaded the Android Support Library in the SDK manager as follows, and yet it still doesn't work:
The support library v4 only supports back to API level 4, so I'm not sure how that would help with supporting API level 3.