Hilt: Multiple Application Classes Extending BaseApp for Different App Stores with minifyEnabled True

91 Views Asked by At

I am developing an Android application that targets two different app stores: Google Play Store and Baidu App Store. To configure the application properly for both stores, I've created two separate custom Application classes, both of which extend an abstract class named BaseApp. These custom Application classes are annotated with @HiltAndroidApp.

While the configuration works fine in the debug build, I am encountering an issue when building the release version with minifyEnabled set to true. The error message is as follows:

App must extend android.app.Application [Instantiatable]

<application android:name=".GooglePlayApp">

This error suggests that the Application class extending BaseApp for the Google Play Store version is not recognized as extending android.app.Application.

I need help resolving this issue while keeping minifyEnabled set to true for release builds to optimize APK size and enhance security. Has anyone encountered a similar situation or have insights on how to address this issue with minification enabled?

2

There are 2 best solutions below

0
On

try to exclude the GoogleApp BiduApp and BaseApp classes from the proguard obfuscation. following is an example on how to exclude:

-keep class com.example.myapp.BaseApp
-keep class com.example.myapp.GoogleApp
-keep class com.example.myapp.BiduApp

place this rules in proguard-rules.pro file

0
On

@daya-a-l your suggestion didn’t work properly however I got the idea.

to configure Proguard for Google Play, Baidu, and the base module, I organized the Proguard rules as follows:

Google Play Proguard (proguard-rules-googleplay.pro):

-keep class com.example.myapp.BaseApp
-keep class com.example.myapp.GoogleApp

Baidu Proguard (proguard-rules-baidu.pro):

-keep class com.example.myapp.BaseApp
-keep class com.example.myapp.BaiduApp

Base Module Proguard (proguard-rules-base.pro):

-keep class com.example.myapp.BaseApp

This setup effectively configures Proguard for multiple app store versions, ensuring the necessary classes are preserved as required.