【问题标题】:Problems with OrmLite and proguard obfuscationOrmLite 和 proguard 混淆的问题
【发布时间】:2012-09-25 05:29:13
【问题描述】:

当我在带有 OrmLite 的项目中使用 Proguard 时。我收到此错误

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.name/com.package.name.activities.StartActivity}:
java.lang.IllegalStateException: Could not find OpenHelperClass because none of the generic parameters of class class com.package.name.activities.StartActivity extends OrmLiteSqliteOpenHelper.  You should use getHelper(Context, Class) instead.

我已经尝试了来自 Proguard with OrmLite on Android 和其他资源的所有建议,但没有结果

【问题讨论】:

    标签: android proguard ormlite


    【解决方案1】:

    将以下内容放在您的 proguard-project 文件和 proguard-optimization 文件中(如果您使用优化)。

     # Your application may contain more items that need to be preserved; 
     # typically classes that are dynamically created using Class.forName: 
     # ormlite uses reflection 
     -keep class com.j256.** { *; }
     -keep class com.j256.**
     -keepclassmembers class com.j256.**
     -keep enum com.j256.**
     -keepclassmembers enum com.j256.**
     -keep interface com.j256.**
     -keepclassmembers interface com.j256.**
    
    -keepclassmembers class * { 
      public <init>(android.content.Context); 
    } 
    
    -keepattributes *Annotation*
    

    对于每个模型类:

    -keep class com.xyz.components.**
    -keepclassmembers class com.xyz.components.** { *; } 
    

    我有点不喜欢最后一部分,但我厌倦了试图找到更好的解决方案。

    【讨论】:

      【解决方案2】:

      我问了很多同样的问题crash using ORMLite on Android with proguard,答案是添加

      -keepattributes Signature
      

      到 proguard 配置。

      【讨论】:

        【解决方案3】:

        您可以使用以下 proguard 配置来保留 OrmLite 使用的所有模型类

        -keep @com.j256.ormlite.table.DatabaseTable class * {
            @com.j256.ormlite.field.DatabaseField <fields>;
            @com.j256.ormlite.field.ForeignCollectionField <fields>;
            # Add the ormlite field annotations that your model uses here
            <init>();
        }
        

        【讨论】:

          【解决方案4】:

          最新版本 OrmLite 5 的一个小补充。

          您可能希望添加这些行以隐藏一些新警告:

          -dontwarn com.j256.ormlite.android.**
          -dontwarn com.j256.ormlite.logger.**
          -dontwarn com.j256.ormlite.misc.**
          

          在此线程中查找更多详细信息:“how can i write the config of proguard for ormlite?

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多