【问题标题】:crash using ORMLite on Android with proguard在带有 proguard 的 Android 上使用 ORMLite 崩溃
【发布时间】:2013-01-10 17:54:45
【问题描述】:

我们在我们的 Android 应用中使用 ORMLite。它工作正常,除非我们尝试在开启 proguard 的情况下进行构建。

我已经阅读了各种类似的帖子,到目前为止,我的 proguard-project.txt 中都有

-keep class com.j256.** {
   *;
}

正如以下讨论中的建议http://sourceforge.net/p/proguard/discussion/182456/thread/6765bb69

我有

-keepclassmembers class * { 
  public <init>(android.content.Context);
  public <init>(android.app.Activity,int);
}

正如另一个stackoverflow问题Proguard with OrmLite on Android中所建议的那样

但它仍然无法正常工作。如果我添加

,我 可以 让它运行
-dontobfuscate

但这有点忽略了首先使用 proguard 的意义。

当我跑步时,我得到一个

IllegalStateException: Could not find OpenHelperClass because none of the generic
parameters of class class <our.package.name>.LaunchActivity extends
OrmLiteSqliteOpenHelper.  You should use getHelper(Context, Class) instead.

在哪里

public class LaunchActivity extends OrmLiteBaseActivity<DatabaseHelper>

public class DatabaseHelper extends OrmLiteSqliteOpenHelper

我已经添加了

-keep public class * extends com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper

-keep public class <our.package.name>.LaunchActivity

但仍然没有运气。这个问题似乎以前被问过 (Problems with OrmLite and proguard obfuscation) 但我希望有人 知道解决方案是什么!

【问题讨论】:

  • JVM 崩溃了还是你的服务器崩溃了?或者你的意思是它抛出了一个异常?

标签: android obfuscation proguard ormlite


【解决方案1】:

错误信息中提到了generic 参数,所以ORMLite 很可能是使用反射来检索泛型类型信息。此信息存储在可选的 Signature 属性中(Java 删除泛型类型),ProGuard 默认将其删除。您可以保留它们

-keepattributes Signature

【讨论】:

  • 谢谢你,它解决了我遇到的问题。不过,我确实遇到了一个新问题,我通过添加 -keep class &lt;our.package.name&gt;.db.** { *; } 来解决这个问题,以保持我们所有的 DB 类完好无损。
猜你喜欢
  • 1970-01-01
  • 2016-06-15
  • 2012-04-08
  • 2019-09-25
  • 2015-03-31
  • 2022-08-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多