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

, ,

Cutting-Edge-to-Edge in Android 15: Using Previews and Testing in Jetpack Compose to Manage Insets.

With the advent of Android 15, edge-to-edge design has become the default configuration. Consequently, applications must be capable of accommodating window insets, including the system status bar and navigation bar, as well as supporting drawing…
Watch Video

Cutting-Edge-to-Edge in Android 15: Using Previews and Testing in Jetpack Compose to Manage Insets.

Timo Drick
Lead Android developer
Seven Principles Mobility GmbH

Cutting-Edge-to-Edge in Android 15: Using Previews and Testing in Jetpack Compose to Manage Insets.

Timo Drick
Lead Android develop ...
Seven Principles Mob ...

Cutting-Edge-to-Edge in Android 15: Using Previews and Testing in Jetpack Compose to Manage Insets.

Timo Drick
Lead Android developer
Seven Principles Mobility ...

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
In this article we’ll go through how to own a legacy code that is…
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
Menu