Support library dependencies in Android Q - android

In order to test my app for Android Q, I've installed Android Studio 3.5 (canary) and updated my build configuration as described here:
https://developer.android.com/preview/setup-sdk
But what do I do with the support library dependencies? The ones below are all red because:
This support library should not use a different version (28) than the compileSdkVersion (29)
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:gridlayout-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
testImplementation 'junit:junit:4.12') {
transitive = true;
}
Do I just leave them as is until Google releases the new support library? I'm getting a build error but I'm not sure if it's related to this or not.

Support libraries will not be updated past 28. You need to migrate to androidx.
See support library documentation where it says:
Note: With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components.
You can continue to use the support library. Historical artifacts (those versioned 27 and earlier, and packaged as android.support.*) will remain available on Google Maven. However, all new library development will occur in the AndroidX library.

Related

Dependency 'androidx.appcompat:appcompat-resources:1.6.1'

Dependency 'androidx.appcompat:appcompat-resources:1.6.1' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Also, the maximum recommended compile SDK version for Android Gradle
plugin 7.2.1 is 32.
Recommended action: Update this project's version of the Android Gradle
plugin to one that supports 33, then update this project to use
compileSdkVerion of at least 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
How do I fix this android studio roblem?
I clearly had no idea what should I do
This is a dependency version contrast issue just replace your appcompact and ktx with these
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'

How to limit max version of a transitive dependency

I have a problem about how to specify the max version for a transitive dependency. Let me explain this with an example:
My app uses the library library-foo, the problem is that library-foo version 3.0+ introduces breaking changes and my app is not ready yet. So I declare it in my dependencies:
implementation 'com.example:library-foo:(,3.0)'
My problem comes when I introduce a new dependency, lets say library-bar. That library introduces a transitive dependency on library-foo
library-bar 5.0 -depends on-> library-foo 2.2
library-bar 5.5 -depends on-> library-foo 3.1
So, after adding the new dependency:
implementation 'com.example:library-foo:(,3.0)'
implementation 'com.example:library-bar:5.+'
I was hopping the dependency resolution to be smart enough. Gradle included the 5.5 version, introducing the breaking changes in my project.
I know I could also limit the max version of library-bar but in projects with a lot of dependencies, it would be great to declare my max version of the troublesome library (foo in this case) forcing the rest of dependencies to be adapted to this.
Is it possible to do that?
You can use gradle's constraints:
implementation 'com.example:library-foo:3.0'
implementation 'com.example:library-bar:5.+'
constraints {
implementation('com.example:library-foo:3.0') {
because 'Versions greater than 3.0 introduce bugs'
}
}

How to ensure all firebase SDKs are the compatible version?

Currently we have a lot of firebase version.
firebase_core_version = '16.0.6'
firebase_perf_version = '16.2.2'
firebase_messaging_version = '17.3.4'
...
implementation "com.google.firebase:firebase-core:$firebase_core_version"
implementation "com.google.firebase:firebase-perf:$firebase_perf_version"
implementation "com.google.firebase:firebase-messaging:$firebase_messaging_version"
...
But they each have different version number and sometimes they are conflicting or resolved to unexpected versions by transitive includes. Or other module declares different version for same library... That steals my time.
Is there any solutions for this?
Gradle has "BoM" feature that is available from 5.0. and it enables you free from version hell.
implementation platform('com.google.firebase:firebase-bom:20.0.1')
implementation 'com.google.firebase:firebase-perf'
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-appindexing'
implementation 'com.google.firebase:firebase-config'
You may notice that only new import firebase-bom has version and any other libraries don't have version.
This is because BoM dependency contains all firebase version inside it (of course they are compatible!).
So your module always import firebase-bom then version conflict will be gone.
firebase-bom is currently experimental but it works for me.
https://firebase.google.com/docs/android/setup#firebase-bom
I hope androidx (jetpack) also have this!
There is also okhttp-bom available.
https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp-bom

Android Studio - no sources/javadocs for Android core libraries

I recently installed Android Studio 3.3, and I have both Android SDK Platform 28 and Sources for Android 28 (both under Android 9.0) installed. But Android studio does not actually detect the sources for any of the Android library classes, and as such I cannot view their javadocs or read their sources.
To be specific, my app build.gradle looks roughly like this:
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 17
targetSdkVersion 28
}
// other stuff...
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'joda-time:joda-time:2.10'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'org.jsoup:jsoup:1.11.3'
}
The libraries at the bottom like the Kotlin standard library, Glide, OkHttp, FlexBox and so on come with their sources so I have no problem there. But the libraries at the top do not have any sources attached. So the classes in android.app, android.support.v4.app and other Android packages have no javadocs when I click on them, and when I try to view the sources, AS decompiles the class file instead.
Decompiled .class file, bytecode version: 51.0 (Java 7)
Choosing to Download Sources isn't having any effect, and I don't want to have to manually choose the sources, because I never needed to do that before upgrading the IDE. The app still builds without any problems, it's just those missing sources that are the issue. Is there a way to make Android Studio automatically detect the sources and fix this problem?
In android studio click file -> Sync with file system
this should help, try to close the file and reopen after the sync.
if not help try to file -> Invalidate caches and restart

Cannot resolve symbol 'MediaSessionCompat'

I cannot import MediaSessionCompat.
The import statement for importing the whole android.support.v4.media library does not show up in the Android Studio "IntelliSense" and it cannot resolve the symbol for anything inside it.
Do I have to make some kind of extra configuration to get this import, like in app build.gradle?
Add these to your dependencies and sync Gradle:
Pre-AndroidX
implementation 'com.android.support:support-compat:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
Post-AndroidX
implementation 'androidx.core:core:1.8.0'
implementation 'androidx.media:media:1.6.0'
Note from official documentation:
With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components.
You can continue to use the support library. Historical artifacts (those versioned 27 and earlier, and packaged as android.support.*) will remain available on Google Maven. However, all new library development will occur in the AndroidX library.
We recommend using the AndroidX libraries in all new projects. You should also consider migrating existing projects to AndroidX as well.
The latest dependencies are:
implementation 'androidx.core:core:1.1.0'
implementation 'androidx.media:media:1.1.0'
def core_version = "1.9.0"
// Java language implementation
implementation "androidx.core:core:$core_version"
// Kotlin
implementation "androidx.core:core-ktx:$core_version"
implementation "androidx.media:media:1.6.0"

Categories

Resources