Blog Infos
Author
Published
Topics
Published
Topics

Intro
Minimal App
<?xml version="1.0" encoding="utf-8"?>
<WebView android:layout_width="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/web"
    android:layout_height="fill_parent"/>
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.am);
        WebView w = (WebView) findViewById(R.id.web);
        w.setWebViewClient(new WebViewClient(){
            //older Android still needs this deprecated function
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }
        });
        w.loadUrl("https://debloat.app");
        w.getSettings().setJavaScriptEnabled(true);
        // This line enables notifications (for full version)
        FirebaseMessaging.getInstance().subscribeToTopic("news");
    }
}
Adding background notifications

Full app content (apkanalyzer)

Full app internals (apktool)

R8 shrinking

Size comparison before vs. after R8 optimisations

R8 minified class/package names

The app size improved by 67%. Moreover, code structure changed dramatically too. Visually, instead of readable package/class/method/variable names, we got short names. Yet, the number of code entities has been greatly reduced too.

Code entities and resources comparison

APK’s resources folder.

Example of ./res/values/strings.xml

Instruction coverage

Full app (1.1 MB) coverage results

R8-optimised app (366KB) coverage results

The actually executed code appears to be just 7.6% for the not optimised app. Yet, it grows to 27.5% for the R8-optimised app. Let’s see how the main package changed.

Main package classes before and after R8 shrinking

Turned out, R8 only left the MainActivity class in the main package. Naturally, this class is referenced in the manifest file. However, the class has changed, too.

MainActivity.onCreate method before and after R8 shrinking.

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

, , ,

Snapshot testing (and more!) with Paparazzi

Unit tests allow you refactor your code with confidence and usually run blazingly fast! But how do you ensure that your UI looks as expected? Espresso tests are hard to set up, prone to flakiness…
Watch Video

Snapshot testing (and more!) with Paparazzi

John Rodriguez
Android engineer
Android

Snapshot testing (and more!) with Paparazzi

John Rodriguez
Android engineer
Android

Snapshot testing (and more!) with Paparazzi

John Rodriguez
Android engineer
Android

Jobs

ACV shrinking

R8 & ACV-shrunk app (277KB), coverage results

R8 & ACV-shrunk app

Total reduction results

Stub methods

This article was originally published on proandroiddev.com on December 26, 2022

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Automation is a key point of Software Testing once it make possible to reproduce…
READ MORE
blog
Every good Android application should be well tested to minimize the risk of error…
READ MORE
blog

Running Instrumented Tests in a Gradle task

During the latest Google I/O, a lot of great new technologies were shown. The…
READ MORE
blog
Notifications are a very important part of Android apps, showing relevant information, informing when…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu