Android库中缺少字段

时间:2016-08-10 20:50:31

标签: android retrofit2 android-proguard

我目前正在使用依赖于OKHttp和Retrofit的外部库(来自gradle中指定的url)。

使用其他库时似乎会中断,但我的应用程序仅在minifyEnabled设置为true时安装并运行,并且指定了一个长的proguard文件。

问题:第一个库中的一个字段据说丢失了,当尝试使用所述库中的方法时,Gson / Retrofit需要并抛出Assertion missing field错误我的onCreate()方法。

Proguard文件:

# Add any project specific keep options here:
-optimizations !code/allocation/variable#, !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-keepattributes SourceFile, LineNumberTable, EnclosingMethod, InnerClasses, Exceptions, Signature#, LocalVariableTable, LocalVariableTypeTable
#-keep,allowshrinking,allowoptimization class * { <methods>; }

# This will break the installation step if minify is enabled.
#-dontobfuscate

-dontoptimize
-dontpreverify

-keep class Voice { Voice.DownloadStatus mDownloadStatus;}

# Retrofit
-dontwarn com.facebook.android.BuildConfig

-dontwarn rx.**

-dontwarn okio.**

-dontwarn com.squareup.okhttp.*

-dontwarn retrofit.appengine.UrlFetchClient

-keepattributes *Annotation*

-keep class retrofit.** { *; }

-dontwarn java.util.zip.*

-dontnote java.util.zip.*

-keepclasseswithmembers class * {
@retrofit.http.* <methods>;
}
# 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.** { *; }
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-dontusemixedcaseclassnames

#-optimizationpasses 5
-allowaccessmodification

我最好的猜测是Proguard在重复/改组的课程中弄得一团糟。

这里是应用程序gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion '24.0.1'
defaultConfig {
    applicationId "com.redacted.redacted"
    minSdkVersion 19
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}
buildTypes {
    release {
        minifyEnabled true
//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        proguardFile 'proguard-rules.txt'
    }
    debug {
        minifyEnabled true
//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        proguardFile 'proguard-rules.txt'
    }
}
dexOptions {
    preDexLibraries = false
    javaMaxHeapSize "4g"
}
productFlavors {
}
}

dependencies {
   compile files('libs/pcr.jar')
   compile 'com.android.support:support-v4:24.1.0'
   compile 'com.android.support:appcompat-v7:24.1.0'
   compile 'com.pebblebee:pb-android-lib-bluetooth:2.0.411'
   compile 'com.euphonyinc:euphonium-library:0.21'
   testCompile 'junit:junit:4.12'
}

0 个答案:

没有答案