I'm trying to use Coordinator Layout in my xml file and found that it's corresponding libraries doesn't exists.
So i tried to include this in my gradle build file
implementation 'com.android.support:design:28.0.0'
but it's giving the error
Supplied String module notation 'androidx.' is invalid. Example notations: > 'org.gradle:gradle-core:2.2', 'org.mockito:mockito-core:1.9.5:javadoc'.
Then i found all support libraries is deprecated and one need to use androidx library.
How to include this library in my gradle file ?
***My main intention is to use Coordinator Layout in my UI
Click on "Refactor" on the android studio menu bar.
Select "Migrate to Androidx..."
Job Done.
You are correct in saying that the support libraries have been deprecated. The new standard is AndroidX. Here is a link that shows the current mappings from the old support libraries to AndroidX.
Specifically for CoordinatorLayout, it has gone from com.android.support:coordinatorlayout to androidx.coordinatorlayout:coordinatorlayout
Furthermore, I suggest reading this page about migrating to AndroidX. It offers a lot of information and will make your transition to AndroidX much smoother.
Related
hello i want to use androidx library but it's not showing for me and i tried Refactor->Migrate to androidx and it didn't work too
can i get help please..
https://i.stack.imgur.com/xHNJ9.png
Make sure all those dependencies are added to your project. Then still face your problem go to the android studio file->invalid caches and restart.
https://i.stack.imgur.com/cXzGu.png
I want to use androidx library but it's not showing for me and I tried Refactor->Migrate to androidx and it didn't work too
Looking at below picture: https://i.stack.imgur.com/cXzGu.png
You can't use androidx for TextInputEditText because that widget is a property of Google material design. That means, the intellisense autocomplete dialog is showing you the exact and correct code. Check here and see the artifact mapping list of android support library to androidx or android jetpack
But before then, according to this post it reads:
With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting
Refactor > Migrate to AndroidX from the menu bar.
The refactor command makes use of two flags. By default, both of them are set to true in your gradle.properties file:
android.useAndroidX=true
The above ☝️ will allow Android plugin to make use of the appropriate AndroidX library instead of Android Support Library.
android.enableJetifier=true
The above ☝️ Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries.
In conclusion, if above lines of codes are not in your gradle.properties file then you can add them and sync gradle
Note: The built-in Android Studio migration might not handle everything. Depending on your build configuration you may need to update your build scripts and Proguard mappings manually. For example, if you maintain your dependency configuration in a separate build file, use the mapping files mentioned below to review and update your dependencies to the corresponding AndroidX packages.
Android app build in Jenkins show follow.Jenkins run on container inside with Linux :
> Task :app:hiltAggregateDepsDebug
WARNING: [Processor] Library '/root/.gradle/caches/transforms-3/866299741cb63fc82191047ff210aa2e/transformed/core-1.8.0-SNAPSHOT-api.jar' contains references to both AndroidX and old support library. This seems like the library is partially migrated. Jetifier will try to rewrite the library anyway.
Example of androidX reference: 'androidx/core/R$styleable'
Example of support library reference: 'android/support/v4/app/INotificationSideChannel$Default'
I don't know why show this message?
I have Android App that uses support library versions 27.1.2. I want to consume a library written using Android X (api 28).
There are few issues with name spacing of the library versions.
Example ...
The library has a Dialog that I want to use with the api
Dialog.show(androidx.fragment.app.FragmentActivity activity);
However all my activities are using
android.support.v4.app.FragmentActivity
and the compiler does not like this.
Currently it is not an option to upgrade my project to latest version, so please no upgrade answers, unless this is the only solution.
Is there a way to resolve this incompatibility issue?
Thanks in advance.
This is not possible. To use any library that depends on AndroidX, your project must migrate your whole project to AndroidX.
Note that the reverse is supported - you can use libraries built with Support Library in projects that use AndroidX (that's the purpose of the android.enableJetifier=true flag).
AndroidX[About]
Consumer support -> Producer androidX - not compatible.
You should migrate your consumer to use AndroidX. Android Studio menu -> Refactor -> Migrate to AndroidX...
Consumer androidX -> Producer support - compatible.
Consumer's gradle.properties in addition to use androidX should enable Jetifier[About] which converts support to androidX
android.useAndroidX=true
android.enableJetifier=true
[Mix AndroidX and support in a multi-module project]
There is a way
Jetifier tool migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead. But when you put -r flag, it makes him to the exactly reverse process.
From developer.android.com
If you pass the -r flag, the utility runs in reverse mode. In this
mode, the utility converts AndroidX APIs to the support library
equivalents, instead of the other way around. Reverse mode is useful,
for example, if you are developing libraries that use AndroidX APIs,
but also need to distribute versions that use the support library.
Anyway, I will suggest to use it only in a very critical needs.
I just created a new library, Powerful Image View.
My library is a custom AppCompatImageView, so I need the appcompat-v7 library. And here comes the question:
How should I add it to my library?
Should I use 'compile', or 'provided' and let the user add the library to its own dependencies?
And how should i handle different versions of the libraries used, since i'm not depending on a specific version?
I added to the library's gradle file this line:
provided 'com.android.support:appcompat-v7:+'
I'd like to know your thoughts about this :)
Should I use 'compile', or 'provided' and let the user add the library to its own dependencies?
I would use compile and make sure that the developer using your library understands that your library relies upon appcompat-v7, as that in turn places lots of other requirements (e.g., using AppCompatActivity, using Theme.AppCompat).
And how should i handle different versions of the libraries used, since i'm not depending on a specific version?
Well, you are requiring some version. AppCompatImageView does not exist in all versions of appcompat-v7. I recommend depending upon a concrete version (i.e., not +), ideally the latest-and-greatest version.
While developing an Android Library, if I add v7 Support Library as an dependency to use Toolbar class only, then would the final .aar file contain only the methods of Toolbar class and the related classes only, or it will contain that of Entire Support Library which wouldn't be in any use?
It'll contain the entire support library. In order to remove the unused classes and methods you should use ProGuard. Check out the official guide
about code and resource shrinking.
It will be completely included in your aar. In order to do it in right you you should use provided, e.g.:
provided 'com.android.support:appcompat-v7:+'
In that case users of your library will use there own support library and will not have the same code of support library which will go with your lib.