[Android Studio] How to remove warnings from created Android Project


Writing time : 2021-12-01 09:25:03

If you create an Android Project in Android Studio and inspect the code using the Inspect Code menu in Analyze, a warning is generated.
Learn how to remove the warnings identified by code inspection.

Apply JUnit5

A warning is generated because the version of junit4 is not specified correctly.

testImplementation 'junit:junit:4.+'  

Change to junit5 and remove the warning by specifying the version.

testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.0"  
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.0"  
testImplementation "org.junit.jupiter:junit-jupiter-params:5.7.0"  
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.7.0"  
testImplementation 'junit:junit:4.13.2'  


delete jcenter

jcenter is added in setting.gradle file.
A warning is generated because jcenter is due to be shut down.

...  
repositories {  
    google()  
    mavenCentral()  
    jcenter() // Warning: this repository is going to shut down soon  
}  

Edit the setting.gradle file and delete the jcenter() line.

...  
repositories {  
    google()  
    mavenCentral()  
}  


Add backup configuration xml file

User data is backed up to Google Cloude according to AndroidManifest settings.
The default setting is a backup of all files.

<application  
    android:allowBackup="true"  
    ...  

A warning is issued if the backup settings are not made clear.
If you change the way to specify the backup file by adding the backup configuration file, the warning is removed.

Add backup configuration XML

Right-click on the Android or res folder in the Project Window.
Select New > Android Resource File menu.

Enter the file name like appbackuprules.xml.
You can change the file name to whatever you want.

In the New Resource File Window, set the Resource type to XML.

Click the OK button to create an xml file.

Modify the generated xml file as follows.

<?xml version="1.0" encoding="utf-8"?>  
<full-backup-content>  
</full-backup-content>  


Add and add fullBackupContent attribute to AndroidManifest.xml file.

<application  
    android:allowBackup="true"  
    android:fullBackupContent="@xml/app_backup_rules"  
    ...