Undo from enable minify after release the app

515 Views Asked by At

At some point of devlopment I changed minifyEnabled to true without any rules in proguard then release the app to google play with v.1.4.0. many of bugs occured to uses when updated the app, I knew the problem because the obfuscated of classes. and some of users removed the app and reinstall to work well partially.

WebView, Camera, Gson, File Picker all this features have problems on version 1.4.0

It was my first experience with minifyEnabled, now I'm knowing that there are alot of rules should I write in the proguard to keep classes.

My question about make undo of minifyEnabled and set it to false, when I debug it, also a new problem occurs and one of them from the code below with NullPointerException.

abstract class LiveCoroutinesViewModel : ViewModel() {

inline fun <T> launchOnViewModelScope(crossinline block: suspend () -> LiveData<T>): LiveData<T> {
    return liveData(viewModelScope.coroutineContext + Dispatchers.IO) {
        emitSource(block())
    }
  }
}

note: I don't need to keep minifyEnabled = true, becuase I have alittle bit experinces and I think there are alot of keeping rules should I understand before I write them and I don't have the time now for that.

So, what is the optimal soultion (strategy) to do minifyEnabled = false for users which already working on minifyEnabled = true

1

There are 1 best solutions below

3
On

The answer is not possible in my way. Because you don't have an option to handle your released app code.

My Suggestion:

Do you think that you have to write rules for Proguard? But not, Android proguard is R8 Guard not proguard. Proguard is another company guard(DexGuard). You can use the R8 guard without adding any rules because these rules are already included in all libraries(read library github and check R8 is included or not). If you enabled R8 guard then just add this line @Keep in your Model class to prevent R8 Guard to shrink that file. Add @Keep which file you don't want to minify.

Like this

@Keep // use to prevent R8 to minify this class.
public class ModelClass {
    String id;
    String text;
    String image;

    public String getImage() {
        return image;
    }

In new version of android, You can test your app by enabling R8 guard in debug mode by adding these below lines in your build.gradle(:app); // in module level

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug { // add this line after release and make ninify true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

It may take some time to build but it is a very good method to test if the app is caching or not (in app build time).

PS

minifyEnabled true helps to reduce app size. Very helpful if you enabled it.

It helps you in the future.