Wednesday, September 4, 2019

Android Studio 3.5.0 and Migrate to AndroidX

System requirement:

Android Studio requirement 3.5 or above

At the end of "Project -> Gradle Scripts -> gradle.properties(Project Properties)" add these lines:

    android.useAndroidX=true
    android.enableJetifier=true

At the end of "Project -> Gradle Scripts -> build.gradle(Project:)" add these lines:

...
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {

    repositories {
        jcenter()
        google()
    }
}

Change "Project -> Gradle Scripts -> build.gradle(Module:)" these lines:

androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' -> androidx.test.espresso:espresso-core:3.2.0

implementation 'com.android.support:appcompat-v7:28.0.0' -> androidx.appcompat:appcompat:1.1.0

implementation 'com.android.support.constraint:constraint-layout:1.1.3' -> androidx.constraintlayout:constraintlayout:1.1.3

androidTestImplementation 'com.android.support.test:runner:1.0.2' -> androidx.test:runner:1.2.0

implementation 'com.google.android.gms:play-services-ads:17.2.1' -> com.google.android.gms:play-services-ads:18.2.0

For Example:

...
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    implementation 'com.google.android.gms:play-services-ads:18.2.0'
  
In Java code, change import android.support.v7.app.AppCompatActivity; to import androidx.appcompat.app.AppCompatActivity;

In activity xml, change android.support.v7.widget.Toolbar to androidx.appcompat.widget.Toolbar

References:

No comments:

Post a Comment