我的项目的结构在使用Proguard时出现问题。

huangapple go评论58阅读模式
英文:

My project's structure is broken when using Proguard

问题

我正在尝试添加Proguard规则。即使我不添加这些规则,一旦将minifyEnabled设置为true,我的项目中的一些功能立刻出现问题。例如,套接字结构被破坏,尝试通过套接字与另一设备通信时,它接收请求但无法发送响应。另一个例子是在编写XML时未打印出一些值。所有这些问题都是在我将minifyEnabled设置为true的瞬间发生的。项目很庞大,我不确定是什么引起了这些问题。

您能否提出一个想法或替代工具,以找到问题的源头并解决它?

正如我所说,即使规则文件为空,即使我只是将minifyEnabled值设置为true,这些问题也会发生,我不知道如何通过将它们添加到规则文件中来防止这些问题。

英文:

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'

答案1

得分: 1

你没有为Proguard文件添加任何规则,这会导致在编译APK时混淆一切。

以下是一个通常的Proguard文件:

-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.**{*;}

除了这些规则之外,您仍然需要添加JSON转换Java Bean或数据类的内容(这就是为什么您的套接字结构出现问题),以及一些需要保留的第三方库。

英文:

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

huangapple
  • 本文由 发表于 2023年4月10日 18:50:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75976440.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定