Search code examples
androidflutterapkandroid-drawable

Android drawables work in Debug but become black squares in Release


I'm working on an Android app (written in Flutter but I don't think it matters) which uses a drawable called quick_plus.png as shown here:

enter image description here

It works great in debug mode.

But not in release mode, where the quick_plus.png drawable became a black square. After unzipping my APKs I confirmed that's also what they contained, just a black square:

enter image description here

No idea if this is relevant, but I generated those APKs by following the bundletool docs:

bundletool build-apks \
--bundle=build/app/outputs/bundle/release/app-release.aab \
--output=build/app/outputs/bundle/release/app-release.apks \
--ks=... \
--ks-pass=... \
--ks-key-alias=... \
--key-pass=...

bundletool install-apks --apks=build/app/outputs/bundle/release/app-release.apks

Here's my build.gradle release config:

signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
}
buildTypes {
    release {
        signingConfig signingConfigs.release

        minifyEnabled true
        useProguard true

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

and the proguard-rules.pro:

#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-keep class com.dexterous.** { *; }

Has anyone seen this before?


Solution

  • Found the problem!

    It was due to Android shrinking and obfuscating my code. All I had to do was add a file called android/app/src/main/res/raw/keep.xml with this:

    <?xml version="1.0" encoding="utf-8"?>
    <resources xmlns:tools="http://schemas.android.com/tools"
      tools:keep="@drawable/quick_plus" />