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"
Related
I'm trying to implement notifications following the example at https://developer.android.com/training/notify-user/build-notification
However, the guide shows an implementation of
dependencies {
implementation "com.android.support:support-compat:28.0.0"}
But when I try to add the dependency in my gradle file I get this error:
Version 28 (intended for Android Pie and below) is the last version of the legacy support library, so we recommend that you migrate to AndroidX libraries when using Android Q and moving forward. The IDE can help with this: Refactor > Migrate to AndroidX..
So what is the AndroidX version of this library?
That would be
implementation "androidx.core:core:1.3.2"
You can find a list of all the mapping to AndroidX at https://developer.android.com/jetpack/androidx/migrate/artifact-mappings
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
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.
Would you know where to get the latest version for Room ?
On this Android Studio page, it is quoted that the latest Room version is 2.1.0-alpha3 but when I put this version in my build.gradle file, the project cannot compile and the following error is shown :
ERROR: Failed to resolve: android.arch.persistence.room:runtime:2.1.0-alpha3
Show in Project Structure dialog
Affected Modules: app
it is quoted that the latest Room version is 2.1.0-alpha3
It is.
when I put this version in my build.gradle file, the project cannot compile and the following error is shown
Your version is fine. Your artifact is the problem.
All new libraries are AndroidX. Your choices are:
Stick with whatever version you are using right now and keep your android.arch.persistence.room:runtime artifact and its classes, or
Migrate to AndroidX, in which case you would use androidx.room:room-runtime as the artifact, and need to change your code to reference the androidx classes for Room and everything else
The thing is, if you'r using AndroidX then the latest is 2.1.0-alpha3, or, if you are using Support libraries then it's 1.1.1 or whatever is latest and that's what mentioned in the documentation. As mentioned by CommonsWare, it's the artifact, and to find out the mappings, see this mapping documentation. And AndroidX is:
The AndroidX library contains the existing support library and also
includes the latest Jetpack components.
Example using support libraries:
dependencies {
// Other libraries...
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
}
The solution is to check AndroidX when starting a new project in Android Studio, then in the App Module Build.Gradle file the following works perfectly :
def room_version = "2.1.0-alpha03"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version" // use kapt for Kotlin
I'm building a library with jitpack.io I was able to build and compile into the application successfully, but the problem here is that in the library there includes a number of other libraries compiled into
implementation 'com.google.android.gms:play-services-ads:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'com.facebook.android:audience-network-sdk:4.99.1'
implementation 'com.appnext.sdk:banners:2.4.2.472'
implementation 'com.appnext.sdk:ads:2.4.2.472'
implementation 'com.appnext.sdk:native-ads2:2.4.2.472'
implementation 'org.jsoup:jsoup:1.11.3'
so when I compiled the library into my application and called it, it reportedly did not find the class I was including into libraries(org.jsoup., com.appnext., ..). If I want to use I have to re-declare the libraries on again in my application. Is there a way to not do this, as includes the library inside
I was facing the same issue and apparently it's a bug in maven gradle plugin v1.5; problem solved after my plugin version is updated to 2.1.
Issue: https://github.com/dcendents/android-maven-gradle-plugin/issues/61
Related Answer: https://stackoverflow.com/a/51190164/1640033