Android upgrades AGP8, enables R8, uses fastjson, log4j, finds that it cannot be released, and cannot be used normally after being generated

        Developed with Android Studio, R8 optimization is enabled (minifyEnabled true is added in buildtypes.release of build.gradle), and it can be released normally and can run normally.

        After the automatic upgrade, AGP8 was used, and then a bunch of Missing Class errors appeared. Add -ignorewarnings in the proguard-rules.pro file of the project (after AGP7, warnings were upgraded to errors, which made it impossible to continue), and finally a release version was generated. The size of the generated apk is indeed much smaller, compressed by more than half. But when using it, the date of logback.SizeAndTimeBasedRollingPolicy cannot be parsed first, and an exception occurs:

        FileNamePattern xxxx does not contain a valid DateToken

        Without the use of logs, positioning is quite troublesome. Fastjson also has an exception when parsing the json string, and the function is extremely abnormal:

        ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

        Keeping all classes of the two libraries in proguard-rules.pro doesn't work either. In short, the application is dead.

        Reminiscent of the fact that R8 was also enabled before, the optimized release is normal, so it is estimated that some mode of R8 may be enabled, resulting in over-optimization. After checking the Android documentation , I realized that AGP8 enables R8.fullmode by default. According to the documentation, add android.enableR8.fullMode=false to the gradle.properties of the project, disable fullmode, and find that it is ok. The apk has increased by nearly 1M, which is completely acceptable, and it is still nearly half smaller than the previous release. It shows that AGP8 has indeed made great improvements, even if fullMode is not enabled.

Guess you like

Origin blog.csdn.net/flyinmind/article/details/131012012