0

I'm trying to add proguard rules. Even if I don't add these rules, some things break in my project the moment I set minifyEnabled to true. For example, the socket structure is broken, while trying to communicate with another device over socket, it receives requests but cannot send a response. Another example is not printing some values while writing xml. All of this happens the moment I set minifyEnabled to true. The project is huge and I'm not sure what caused it.

Can you suggest an idea or alternative tool to find the source of the problem and solve it?

As I said, even if the rules file is empty, even if I just set the minifyEnabled value to true, these problems occur and I have no idea how to prevent these problems by adding them to the rules file.

build.gradle

        release {
            shrinkResources false
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            buildConfigField("String", 'BUNDLE_DATE', '"17.06.2021 09:08"')
            buildConfigField("String", 'BUNDLE_ID', '"13"')
        }
        debug {
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            ext.enableCrashlytics = false
            ext.alwaysUpdateBuildId = false
            aaptOptions {
                cruncherEnabled false
            }

implementations

    implementation 'org.bouncycastle:bcprov-jdk15to18:1.68'
    implementation 'org.owasp.encoder:encoder:1.2.3'

    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':logfilemanager')
    compile files('libs/ormlite-android-4.48.jar')
    compile files('libs/ormlite-core-4.48.jar')
    compile files('libs/zxing.jar')
    compile files('libs/calimero-2.0.4.jar')
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'cat.ereza:customactivityoncrash:2.4.0'
    compile group: 'cz.msebera.android', name: 'httpclient', version: '4.5.8'
    implementation 'com.google.android.gms:play-services-location:20.0.0'
    implementation 'org.kie.modules:org-apache-commons-net:6.5.0.Final'
    implementation 'com.github.bumptech.glide:glide:4.13.2'
    implementation 'com.github.justzak:dilatingdotsprogressbar:1.0.1'
    implementation 'com.google.code.gson:gson:2.9.1'
    implementation "androidx.recyclerview:recyclerview:1.2.1"
    implementation 'org.java-websocket:Java-WebSocket:1.5.3'
    implementation("com.squareup.okhttp3:okhttp:4.10.0")
    implementation group: 'commons-fileupload', name: 'commons-fileupload', version: '1.4'
    implementation 'javax.servlet:javax.servlet-api:4.0.1'
ozgurbyk
  • 75
  • 7

1 Answers1

1

You didn't add any rule for proguard file equals that mix EVERYTHING when compile apks

Here is a normally proguard file

-dontwarn com.android.**
-keep class * extends com.android.View {*;}
-keep public class * extends android.webkit.WebChromeClient
-keep class * implements java.io.Serializable {*;}
-dontwarn okhttp3.**
-dontwarn org.**

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.AppGlideModule

-keep class com.google.** {*;}
-keep class com.facebook.** {*;}
-keep class com.com.appsflyer.** {*;}


-optimizationpasses 5
-dontusemixedcaseclassnames
-verbose
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keepclasseswithmembernames class * {
    native <methods>;
 }
-adaptclassstrings
-keepattributes InnerClasses, EnclosingMethod, Signature, *Annotation*



-keep class androidx.**{*;}

Except those items, you still need add your json convert java bean or data class stuff(That's why your socket structure is broken), and some third party lib need to keep

Godrick
  • 71
  • 5
  • I added what you posted but it didn't work. Is it possible to find out what exactly is causing the error? Or will I have to scan one by one? My proguard-rules.pro file was like this: https://codeshare.io/loLlQd – ozgurbyk Apr 10 '23 at 11:36
  • No, That I post is just a sample, not real code –  Godrick Apr 10 '23 at 12:14
  • I checked your proguard file, A lot of "demo" things in it, read this https://developer.android.com/build/shrink-code –  Godrick Apr 10 '23 at 12:18