Android studio 3.2 canary Migrate feature - android

I find two new refactor commands, what are the exact functions of
refactor>migrate app to appCompat
refactor>migrate to androidX

Support (compatibility) libraries was changed to AndroidX libraries by Google.
So in the nearest future support libraries won't be supported anymore.
So "migrate to androidX" will do the following:
Android studio will change all imports in your class from android.support. * to androidx. *
Dependencies of your build.gradle will be also changed to relevant androidX libs

Related

What is the AndroidX equivalent of support-compat library?

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

Contains references to both AndroidX and old support library

After upgrating flutter version to Flutter 1.22.0-2.0.pre.78 • channel master I am getting this warning:-
WARNING:
[Processor] Library
'C:\Users....gradle\caches\modules-2\files-2.1\io.flutter\flutter_embedding_debug\1.0.0-b1d9f863db32cb1d6714cf75db4a992ee3765113\b8748b5192a2a0961f5c14f8845331ad5f2225a1\flutter_embedding_debug-1.0.0-b1d9f863db32cb1d6714cf75db4a992ee3765113.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/annotation/VisibleForTesting' Example of support library
reference: 'android/support/annotation/NonNull'`
Is this issue will cause some serious issue in future or not. Thanks in Advance :)
This warning exist because on the latest Flutter versions newly created projects will be created with AndroidX automatically.
Starting from Flutter v1.12.13, new projects created with flutter create -t <project-type> use AndroidX by default.
Projects created prior to this Flutter version must not depend on any
old build
artifact
or old Support
Library
class.
In an app or module project, the file android/gradle.properties or
.android/gradle.properties must contain:
android.useAndroidX=true
android.enableJetifier=true
The warning also stated:
This seems like the library is partially migrated. Jetifier will try to rewrite the library anyway.
This is usually caused by some plugins that was not migrated and Flutter tool uses Jetifier which will automatically migrate those Flutter plugins using the Support Library to AndroidX.
The Flutter tool uses Jetifier to automatically migrate Flutter
plugins using the Support Library to AndroidX, so you can use the same
plugins even if they haven’t been migrated to AndroidX yet.
You can open an issue to GitHub if you've encounter other issues when migrating to AndroidX.

Dependencies cannot be compiled in android studio

When the implementation 'com.karumi:dexter:6.0.0' is added in build.gradle file, Error is shown on line number 24 while implementing appcompat:implementation 'com.android.support:appcompat-v7:26.1.0'
its the build.gradle(Module:app)
Error in Gradle
From your gradle error message, it is seen that your are using the andorid earlier project structure library.
You are trying to implement implementation 'com.karumi:dexter:6.0.0' library which is using the androidx support library structure.
Hence, your are getting that error as you cannot use both the structure as they have been made and organized complete differently.
Solution:
Shift to androidx library structure if you really want to use that library.
Refer this official documentation of Google Android to migrate to andoirdx from android -
Google Developers Documentation
The library you are trying to use is using AndroidX libraries and you are using Andeoid support libraries in your project. Either migrate your project to androidx or ise an older version of the library which use android support libraries.
You should migrate your project AppCopact to AndroidX. For migrating project AppCompact to Androidx Go Refactor -> Migrate to Androidx then tick on BackUp Project and Migrate. After Migration The com.karumi:dexter:6.0.0 library will work perfectly.

How can I make AndroidX the default library for new Android projects?

Google now recommends using the AndroidX libraries over the older support libraries (read here), yet each time I start a new Android project in Android studio, it defaults to the support libraries dependencies. Since AndroidX is what is recommended, I'm guessing there must be some way to default to AndroidX?
Right now I need to manually configure the gradle.properties file for each new project, as below
From the AndroidX Documentation:
If you want to use AndroidX in a new project, you need to set the compile SDK to Android 9.0 (API level 28) or higher and set both of the following Android Gradle plugin flags to true in your gradle.properties file.
android.useAndroidX: When set to true, the Android plugin uses the appropriate AndroidX library instead of a Support Library. The flag is false by default if it is not specified.
android.enableJetifier: When set to true, the Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries. The flag is false by default if it is not specified.
Is there a way to make Android Studio use only AndroidX by default?
AndroidX is enabled by default. In fact, in the latest version of Android Studio, you don't even have the option to deselect the AndroidX dependencies. See here:
The androidx.* artifacts are already selected. If your Android Studio doesn't support this, try updating it or installing it again. Make sure to not import the older preferences from your IDE. It will refresh your IDE.
when u create any new project in android studio in the latest version then it will by default open with androidX library.

How to use an Androidx library in a project which is not migrated to Androidx

My current project is quite stable. Presently I don't want to migrate to Androidx. But I need to use this com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.3 library in my project, which is migrated to Androidx. So when I'm importing this library it causes gradle build failure.
I found many ways for migrating to Androidx but not the other way.
One solution I can think of downloading the library and replace the Androidx libraries with support and then import. Apart form this is there any other way ? Like the reverse of jetifier.

Categories

Resources