【问题标题】:My app crashes when using proguard with Hyperledger Iroha将 proguard 与 Hyperledger Iroha 一起使用时,我的应用程序崩溃了
【发布时间】:2020-01-23 08:27:57
【问题描述】:

当我尝试在我的 build.gradle 文件中使用以下代码执行 minify enabled true 时,应用程序崩溃了:

代码

buildTypes {
    release {
        debuggable false
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    debug{
        debuggable true
        minifyEnabled true
        shrinkResources false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
  • 当我这样做时:minifyEnabled true 在构建发布 apk:app-release.apk 后,应用程序崩溃了。
  • 当我这样做时:minifyEnabled false 构建发布 apk 后:app-release.apk,构建没问题。

enter image description here

【问题讨论】:

    标签: android proguard hyperledger-iroha


    【解决方案1】:

    如参考资源所示,minifyEnabled 将删除未使用的代码。在您的情况下,可能存在与 JNI 一起使用的方法,否则编译器不知道它已被使用。再次根据 ref,您可以指定要阻止检查内置 minify 的文件(与 proguard 相同)。 The answer is here

    【讨论】:

      【解决方案2】:

      如错误消息中所示,类加载器无法找到类 org.apache.xerces.datatype.DatatypeFactoryImpl

      Proguard 正在更改类名以阻止这种情况发生,您可以添加

      -keep class org.apache.**{ *; }
      

      在您的 progurad-rules.pro 文件中

      【讨论】:

      • 添加这个后你得到的是同样的错误还是不同的错误?
      【解决方案3】:

      将此添加到proguard

      -keep public class jp.co.soramitsu.iroha.android.** {
            public protected *;
            public private *;
      }
      

      【讨论】:

      • 现在我通过添加这个 -keep class org.** { *; } 到 proguard-rules.pro 文件
      猜你喜欢
      • 2016-04-02
      • 1970-01-01
      • 2016-12-06
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多