0

I have an app which i am updating for new version. The app runs well in debug mode where when i create a signed APK and run it on my device, it crashes. I checked the logcat and following is the stack trace:

java.lang.NoSuchFieldError: BUILD
E/AndroidRuntime(28433):        at java.lang.Class.getDeclaredAnnotation(Native Method)
E/AndroidRuntime(28433):        at java.lang.Class.getAnnotation(Class.java:290)
E/AndroidRuntime(28433):        at org.a.a.a(SourceFile:115)
E/AndroidRuntime(28433):        at com.package.utils.MyApplication.onCreate(SourceFile:42)
E/AndroidRuntime(28433):        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1030)
E/AndroidRuntime(28433):        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4409)
E/AndroidRuntime(28433):        at android.app.ActivityThread.access$1500(ActivityThread.java:139)
E/AndroidRuntime(28433):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
E/AndroidRuntime(28433):        at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(28433):        at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(28433):        at android.app.ActivityThread.main(ActivityThread.java:5086)
E/AndroidRuntime(28433):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(28433):        at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(28433):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime(28433):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/AndroidRuntime(28433):        at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(  861):   Force finishing activity com.package.activities/.SplashActivity

In my MyApplication file looks like this:

package com.package.utils;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.facebook.FacebookSdk;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.StandardExceptionParser;
import com.google.android.gms.analytics.Tracker;
import com.package.activities.R;

import org.acra.ACRA;
import org.acra.ReportField;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;

@ReportsCrashes(formUri = "", mailTo = AppUtils.CRASH_REPORT_EMAIL, customReportContent = {ReportField.BUILD,
    ReportField.USER_APP_START_DATE, ReportField.USER_CRASH_DATE, ReportField.USER_EMAIL, ReportField.APP_VERSION_NAME,
    ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.CUSTOM_DATA, ReportField.STACK_TRACE,
    ReportField.LOGCAT,}, mode = ReportingInteractionMode.TOAST, resToastText = R.string.crashed_report)
public class MyApplication extends Application {

public static final String TAG = MyApplication.class.getSimpleName();

private static MyApplication mInstance;
private static Context context;

public static synchronized MyApplication getInstance() {
    return mInstance;
}

@Override
public void onCreate() {
    super.onCreate();
    FacebookSdk.sdkInitialize(getApplicationContext());
    FacebookSdk.setApplicationId(getResources().getString(R.string.facebook_app_id));
//        MyApplication.context = getApplicationContext();
    //reference: https://github.com/ACRA/acra/wiki/BasicSetup
    //The following line triggers the initialization of ACRA
    ACRA.init(this);

    mInstance = this;

    AnalyticsTrackers.initialize(this);
    AnalyticsTrackers.getInstance().get(AnalyticsTrackers.Target.APP);
}
}

ACRA.init(this) is line no. 42 in this.

How to remove this error?

EDITED: Below is my complete proguead file:

-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
    }

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
    }
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html    #manual/usage.html

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

-keepnames class org.apache.** {*;    }
-keep class org.apache.** {*;    }
-keep class android.support.v4.** { *;     }
-keep interface android.support.v4.app.** { *;     }
-dontnote android.support.v4.**
-keep class org.joda.time.** { *;     }
-keep interface org.joda.time.** { *;    }
-keep class android.support.v7.app.** { *;     }
-keep interface android.support.v7.app.** { *;     }
-keep class org.acra.** { *;     }

# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't necessary
-keep class org.acra.ACRA {
*;
}

# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode {
*;
}

-keepnames class org.acra.sender.HttpSender$** {
*;
}

-keepnames class org.acra.ReportField {
*;
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter{
public void addCustomData(java.lang.String,java.lang.String);
public void putCustomData(java.lang.String,java.lang.String);
public void removeCustomData(java.lang.String);
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter{
public void handleSilentException(java.lang.Throwable);
}

-keepclassmembers class * implements java.io.Serializable{
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}

-keep class com.viewpagerindicator.** { *;     }
-dontskipnonpubliclibraryclassmembers

-dontwarn org.apache.commons.logging.LogFactory
-dontwarn org.apache.http.annotation.ThreadSafe
-dontwarn org.apache.http.annotation.Immutable
-dontwarn org.apache.http.annotation.NotThreadSafe
-dontwarn org.jodatime.time.**
-dontwarn org.joda.convert.**
-dontwarn org.apache.http.**
-dontwarn android.net.**
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify

# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html    #native
-keepclasseswithmembernames class * {
native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html    #beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see     http://proguard.sourceforge.net/manual/examples.html    #enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class **.R$* {
public static <fields>;
}


#    #---------------Begin: proguard configuration for Gson  ----------

# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# Gson specific classes
-keep class sun.misc.Unsafe { *;     }

# Application classes that will be serialized/deserialized over Gson



#    #---------------End: proguard configuration for Gson  ----------
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}

-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

EDIT 2: I don't think anything is wrong with ACRA as i tried signing after removing ACRA from my project but still the error is same.

EDIT 3: After many hit and tries, i figured out that cause of this issue is Google Analytics. When i build APK without Google Analytics(by removing last two line of onCreate in MyApplication, it works fine whereas with those lines it crashes and the logcat remains same as shown above.

Aashish Gulabani
  • 141
  • 6
  • 24
  • What version of ACRA is the stacktrace above? – William May 05 '16 at 23:49
  • The stacktrace was same for 2 versions of ACRA which i tried and those 4.7.0 and 4.8.1. – Aashish Gulabani May 06 '16 at 04:23
  • No. That is **NOT** stacktrace from acra-4.8.1. It does match acra-4.7.0 and it tells me that your progurded code hs been stripped of annotations. – William May 06 '16 at 07:36
  • I am creating a signed APK from android studio for the first time. I am not very well aware of this proguard file. I didn't get what you mean by "your progurded code hs been stripped of annotations." And i was just trying out things and noticed that when i remove ACRA from my project and then build,this error is still there. – Aashish Gulabani May 06 '16 at 07:42
  • If you completely remove ACRA from project and still have this error it means that other library or your own code is stripped by proguard. – Fiil May 06 '16 at 10:12
  • "code is stripped by proguard" means? – Aashish Gulabani May 06 '16 at 12:34
  • If you removed ACRA from your project, you couldn't be getting this exact same error, because the stacktrace of this error almost certainly contains an ACRA class `org.a.a.a` – William May 07 '16 at 04:33
  • After many hit and tries, i figured out that cause of this issue is Google Analytics. When i build APK without Google Analytics(by removing last two line of onCreate in MyApplication, it works fine whereas with those lines it crashes and the logcat remains same as shown above – Aashish Gulabani May 16 '16 at 10:00

1 Answers1

0

I agree with @Fiil, this looks like a proguard error.

I recommend to switch to ACRA 4.8.1 or later, as this contains a proguard configuration file.

Community
  • 1
  • 1
F43nd1r
  • 7,690
  • 3
  • 24
  • 62
  • I changed my ACRA library to 4.8.1, but still error remains the same. I have edited my post to add the complete proguard file. Please have a look and let me know if something is wrong in that. – Aashish Gulabani May 05 '16 at 15:16