A reminder of how to delete logs before releasing an Android app, etc

公開日: 2021年02月28日最終更新日: 2021年10月17日

thumb

I sometimes make a simple application to check the functionality of Android. I also try to release the app on the play store. I haven't been able to do the release process properly, but I would like to write down some things that I want to do at least and tend to forget. These are the following items.

  • Enable log deletion, compression, obfuscation, and optimization.
  • Declare unsupported features.
  • Update app versionCode

Split logs

The log is useful for debugging, but we think it is undesirable to produce extra logs in a release version of the application.

  • It is an extra burden to use the application.
  • It may give hints for attacks, which is not good for security.
  • It is difficult to read because of the flow of other logs.

This is because of these reasons. Therefore, we would like to prevent the log from appearing at the time of release.

This can be achieved by writing a rule in proguard-rules.pro.

First, enable app compression, obfuscation, and optimization of your app by enabling proguard in app's build.gradle with minifyEnabled true.

android {
    ...
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    ...

You can then delete the log by adding the following to proguard-rules.pro

-assumenosideeffects public class android.util.Log {
    public static *** v(...);
    public static *** d(...);
    public static *** i(...);
    public static *** w(...);
    public static *** e(...);
    public static *** wtf(...);
}

Declare unsupported features.

When you create an application in AndroidStudio, AndroidManifest.xml and other necessary files will be generated automatically. And by default, it supports multi-window, picture-in-picture mode, and screen rotation (landscape mode). If your app does not support any of these, you can teach it to the Android framework by defining it in AndroidManifest.xml.

For each, put the following in AndroidManifest.xml(Note: Multi-window support).

  • If multi-window is not supported, use android:resizableActivity="false".
  • If picture-in-picture mode is not supported, use android:supportsPictureInPicture="false".
  • If you want to fix the screen to portrait mode, use android:screenOrientation="portrait"
    <application
        android:resizeableActivity="false"
        android:supportsPictureInPicture="false"
        ...
        <activity
            ...
             android:screenOrientation="portrait"
            ...
        />
        ...
    />

Raising the version code

You may notice that it is pointed out to you when you upload it to the play console. I'm sorry for releasing it in a random way.

If you are releasing an upgraded version, don't forget to raise the versionCode of your app in app's build.gradle.

android {
    ...
    defaultConfig {
        ...
        versionCode 8
        ...
    }