简体   繁体   English

我在保卫规则中做错了什么?

[英]What am I doing wrong in proguard rules?

I've been really trying hard to get the work done in my application. 我一直在努力完成应用程序中的工作。 Everything is set and working but once I want to set proguard rules , my application always crashed. 一切都已设置并且可以正常工作,但是一旦我要设置proguard rules ,我的应用程序总是崩溃。 I checked every library one by one and used all the info they give in the proguard-rules.pro file. 我逐一检查了每个库 ,并使用了它们在proguard-rules.pro文件中提供的所有信息。 Yet, I cannot make it work. 但是,我无法使其工作。

I have 4 activities in total and with these rules only one of them crashes. 我总共进行了4次活动,根据这些规则,只有其中一项崩溃了。 I can enter and exit other 3. 我可以进入和退出其他3。

I enabled debugging because I learnt that if the application works in this mode then it means it is guarded and when I remove it and upload it to play store, it will be decompile-protected. 我启用了调试功能,是因为我了解到,如果应用程序在此模式下运行,则表示它受到保护;当我删除该应用程序并将其上传到Play商店时,它将受到反编译保护。 Warn me if I am wrong. 如果我错了,请警告我。

This is my build.gradle: 这是我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        multiDexEnabled true
        applicationId "com.example.android.rippleblockexplorer"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            shrinkResources true
        }

        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            shrinkResources true
            debuggable true
        }
    }

}

dependencies {
    testImplementation 'junit:junit:4.12'

    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.android.support:design:27.1.1'
    implementation "org.java-websocket:Java-WebSocket:1.3.8"
    implementation 'com.github.curioustechizen.android-ago:library:1.4.0'
    implementation 'com.facebook.shimmer:shimmer:0.1.0@aar'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation "com.android.support:cardview-v7:27.1.1"
    implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'

}

And this is my proguard-rules.pro: 这是我的proguard-rules.pro:

# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions

-ignorewarnings
-keep class * {
    public private *;
}

##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
#-keep class com.google.gson.examples.android.model.** { *; }

# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

##---------------End: proguard configuration for Gson  ----------

# Retain generated class which implement Unbinder.
-keep public class * implements butterknife.Unbinder { public <init>(**, android.view.View); }

# Prevent obfuscation of types which use ButterKnife annotations since the simple name
# is used to reflectively look up the generated ViewBinding.
-keep class butterknife.*
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }

-keep class org.ocpsoft.prettytime.i18n.**


#DEBUGGING ENABLER
-keepattributes SourceFile,LineNumberTable

-keep class com.example.android.rippleblockexplorer.model.** { *; }
-dontwarn kotlin.Unit

I am not sure at all what to add or to remove anymore. 我完全不确定要添加或删除的内容。 Explicit debugging shows an error in somewhere but it completely works when I disable proguard. 显式调试在某处显示错误,但是当我禁用proguard时它完全可以工作。 I do not understand why. 我不理解为什么。

FYI, I am using Java thread (and you know, overriding Runnable etc.); 仅供参考,我正在使用Java thread (并且您知道,覆盖了Runnable等); if this is any of help. 如果有帮助的话。

Anyone has a solution or a suggestion, perhaps? 有人有解决方案或建议吗? Any help is so appreciated. 任何帮助都非常感谢。

In debug mode proguard file doesnot work.It works in release mode.You can follow the developer android site for this. 在调试模式下,proguard文件不起作用。在发布模式下,proguard文件可以工作。

https://developer.android.com/studio/build/shrink-code https://developer.android.com/studio/build/shrink-code

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM