应用程序仅在发布时启动时崩溃

时间:2015-11-17 09:39:36

标签: android crash proguard release

我的应用只在发布模式下启动时崩溃了。我把minifyEnabled设为false并且app运行完美但是如果我启用了proguard文件,应用程序崩溃了。这是build.gradle文件的内容:

apply plugin: 'com.android.application'

repositories {
maven {
    url "https://oss.sonatype.org/content/repositories/snapshots"
   }
}

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'

defaultConfig {
    applicationId "com.example.myapp"
    minSdkVersion 9
    targetSdkVersion 23
    versionCode 1
    versionName "1.0.2"
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

compileOptions {
    encoding "ISO-8859-1"
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.github.rey5137:material:1.2.1.6-SNAPSHOT'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.android.gms:play-services-ads:8.1.0'
}

这些是我添加到proguard-rules.pro文件的行:

-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn com.rey.material.**
-keep class com.rey.material.** { *; }
-dontwarn com.google.android.gms.ads.**

这是logcat中出现的错误:

11-17 11:34:37.060 2228-2228/? E/AndroidRuntime: FATAL EXCEPTION: main
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime: Process: com.example.myapp, PID: 2228
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime: java.lang.RuntimeException:    Error receiving broadcast Intent { act=1 flg=0x10 (has extras) } in com.example.myapp.ay@424e2e60
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:782)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:733)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:146)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5602)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:  Caused by: android.os.BadParcelableException: Parcelable protocol requires a Parcelable.Creator object called  CREATOR on class com.example.myapp.DataInfo
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Parcel.readParcelableCreator(Parcel.java:2156)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Parcel.readParcelable(Parcel.java:2097)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Parcel.readValue(Parcel.java:2013)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Parcel.readListInternal(Parcel.java:2343)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Parcel.readArrayList(Parcel.java:1703)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Parcel.readValue(Parcel.java:2034)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Bundle.unparcel(Bundle.java:249)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Bundle.getParcelableArrayList(Bundle.java:1250)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at com.flipaos.tvonline.ay.onReceive(Unknown Source)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:772)
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:733) 
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95) 
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:146) 
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5602) 
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
11-17 11:34:37.060 2228-2228/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515) 

我的类DataInfo如下:

public class DataInfo implements Serializable, Parcelable {
protected int nIdDrawable;
protected String strName;
protected String strDrawable;
protected String strType;

public DataInfo(int nIdDrawable, String strName){
    this.nIdDrawable = nIdDrawable;
    this.strName = strName;
    this.strDrawable = "";
    this.strType = "";
}

public DataInfo(String strName, String strDrawable, String strType){
    this.nIdDrawable = 0;
    this.strName = strName;
    this.strDrawable = strDrawable;
    this.strType = strType;
}


/**
 * Constructs a Question from a Parcel
 * @param parcel Source Parcel
 */
public DataInfo (Parcel parcel) {
    this.nIdDrawable = parcel.readInt();
    this.strName = parcel.readString();
    this.strDrawable = parcel.readString();
    this.strType = parcel.readString();
}


// Method to recreate a Question from a Parcel
public static Parcelable.Creator<DataInfo> CREATOR = new Creator<DataInfo>() {

    @Override
    public DataInfo createFromParcel(Parcel source) {
        return new DataInfo(source);
    }

    @Override
    public DataInfo[] newArray(int size) {
        return new DataInfo[size];
    }

};


@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
    dest.writeInt(nIdDrawable);
    dest.writeString(strName);
    dest.writeString(strDrawable);
    dest.writeString(strType);
}
}

可能是什么问题?我必须在proguard文件中添加更多行吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

尝试添加

-keep class com.example.myapp.** { *; }

到你的proguard配置。这应该将所有应用程序的类留在apk中。