Android Hilt ViewModel not working when shrinkResources true - android

I'm using Android Hilt ViewModel. It's working fine for debug mode below:
debug {
debuggable true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
but when I change to release mode, Android Hilt not working. Especially when I change shrinkResources to true or debuggable to false, It's will not working. Below is my release mode:
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
Below is my proguard:
-dontwarn com.google.errorprone.annotations.**
-keepnames #dagger.hilt.android.lifecycle.HiltViewModel class * extends androidx.lifecycle.ViewModel
Please help me!

Related

Android project not obfuscating

I want to obfuscate my android code, I have set minifienable true and setup proguard file, but after generating apk and decompile, the code is not obfuscated. This is my proguard :
my proguard file:
-dontwarn com.huawei.**
-dontwarn org.conscrypt.*
-dontwarn org.openjsse.javax.net.ssl.*
-dontwarn org.openjsse.net.ssl.OpenJSSE
my build.gradle file
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug{
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
To enable ProGuard in Android Studio. Below is the sample how to enable default ProGuard in Android Studio.
Go to the build.gradle file of app
enable the proguard minifyEnabled true and useProguard true
enable shrinkResources true to reduce the APK size by shrinking resources.
proguardFiles getDefaultProguardFile('proguard-android.txt') to enable the default one. If you want to use your own proguard file then use the below rules.
release
{
debuggable false
useProguard true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
delete build file
invalidate cache and restart android studio

Signed apk/bundle taking too much of time from my android studio

I am trying to take singed apk build but generating the build getting too much of time (nearly 30 min)
build.gradle:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Set to false these line if you are not using proguard rule file
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

Android debugger does not stop at breakpoints after minifyEnabled false

The debugger does not stop on any breakpoints. I tried clearing all breakpoints and adding them back in but I am seeing debug statements in the console.
According to this answer, Inside build.gradle for your app module, disable minifyEnable for my build variant and change it to false.
debug {
debuggable true
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
I did it also but also but still same problem.
Since you're in debug configuration you don't need to shrink resources or add proguard
debug {
debuggable true
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
change to
debug {
debuggable true
minifyEnabled false
// shrinkResources true
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

Why does Proguard make APK files bigger even when minifier is enabled?

I'm new to Proguard configuration, so please correct me if I'm doing something wrong.
After playing with Gradle and Proguard configuration, I got two main options: either setting useProguard false or deleting that line.
First option:
buildTypes {
release {
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Second option:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
The thing is that in the first case my APK-file size is 8 mb but it is not obfuscated and in the second case it becomes obfuscated but gets more than twice the size: 18 mb.
Proguard rule is the same in both cases:
-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-dontwarn org.codehaus.mojo.animal_sniffer.*
-dontwarn okhttp3.internal.platform.ConscryptPlatform
So how do I make my APK both small and obfuscated?

Debug APK size 25% smaller than Release (both with Proguard)

The debug APK we generated is 30 MB, while on the other hand, the release APK is 40 MB
Both uses the same proguard and gradle config, as below :
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig getSigningConfig()
}
debug {
debuggable true
minifyEnabled true
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig getSigningConfig()
}
}
Please leave a comment if you need more code to analyze this problem
Thanks

Categories

Resources