Reputation: 369
I am trying to migrate my project to androidX. The project i am trying to migrate is based on android support libraries AppCompat. In the Developer Documentation it says that you can migrate to AndroidX by doing the Following: Android Studio -> Refactor -> Migrate to AndroidX But when i am following these steps, i end up at Refactor, because i only have got the option Migrate to AppCompat. I am not sure what to do.
Additional Info:
Android Studio Version: 3.1.4(Stable Channel)
Android SDK Tools Version: 26.1.1
Thanks for any help!
Upvotes: 14
Views: 12054
Reputation: 391
You can not find Refactor > Migrate to AndroidX option in latest version of android studio(now Ladybug). So follow below options.
android.useAndroidX=true android.enableJetifier=true
2.Make sure build.gradle(:app) had following lines if not, add it
android {
compileSdk 34
compileOptions {
sourceCompatibility JavaVersion.VERSION_17 (add compatible version to your project)
targetCompatibility JavaVersion.VERSION_17
}
namespace 'your app's namespace' (Get it from manifest file like package="com.example.appname")
}
<activity android:name=".MainActivity"
android:exported="true" />
dependencies { classpath 'com.android.tools.build:gradle:8.7.2' (set version until your project compatible) }
Search com.android.support in your project mostly in import section of java/kotlin and xml files and remove them and rewrite that line as Android Studio suggessts you to same class with AndroidX which you need to add. Remove Android Support Dependency from build.gradle(:app) by replacing AndroidX dependancy which is compatible with that dependancy.Below i have provided common dependency for each project, just grab it as per your requirements.
implementation 'androidx.appcompat:appcompat:1.7.0' implementation 'androidx.annotation:annotation:1.9.1' implementation 'androidx.core:core-ktx:1.15.0' androidTestImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.2.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' androidTestImplementation 'androidx.test:core:1.6.1'
If still issue happens paste your questions in comment, I will try to resolve.
Upvotes: 0
Reputation: 689
Android Studio Hedgehog is the last version which has "Refactor to AndroidX" option
Upvotes: 4
Reputation: 1
If you have the same problem after you updated AndroidStudio to 3.2 or later, you can modify your ***.kts
to ***.gradle
. I solved my problem this way.
Upvotes: 0
Reputation: 1005
Switch to "Android" or "Project" tab in the file navigation window. And right click on your parent folder and go to refactor, there listed "Migrate to android" option. It is very simple. In case of any mistakes in migration we can switch back to appcompat version using "migrate to appcompat" under same menu.
Upvotes: 3
Reputation: 3253
"Refactor to AndroidX" option is available for AndroidStudio 3.2 stable and later. https://developer.android.com/studio/
Upvotes: 8