Search code examples
javaandroidgsonandroid-2.2-froyoverifyerror

Android - java.lang.VerifyError on SDK 2.2


I recently launched my application to the Market and I've been in contact with a user who is reporting that when he launches my app, it display the Force Close/Report dialog. I asked the user to report the error so I could see the stack trace of what's happening and I'm getting the java.lang.VerifyError.

From what I've read, this has either something to do with an external library or an incompatibility in some method in java.lang with the targeted Android SDK version.

The user is on Android 2.2.1, but the app currently works on many other 2.2 devices, so I'm trying to figure out where to start digging.

Question: Does anybody have suggestions as to what would be the best thing to start looking into to find the issue? I can provide code or more information if needed, so please let me know.

Here's the Stack Trace:

java.lang.VerifyError: com.app.myapp.MainActivity
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1034)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2749)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2866)
at android.app.ActivityThread.access$2300(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2181)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Thanks in advance!

EDIT
Added per request of Konstantin

MainActivity.java

package com.app.myapp;

//Imports removed

public class MainActivity extends BaseActivity implements Runnable {

private LayoutInflater mInflater;
private SharedPreferences prefs;
private SharedPreferences.Editor prefsEditor;

    ....

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    loadActivity(savedInstanceState);
}

private void loadActivity(Bundle savedInstanceState) {
    setContentView(R.layout.mainlayout);

    ActionBar actionBar = (ActionBar)findViewById(R.id.actionbar);
    actionBar.setTitle("My App");
    actionBar.setHomeAction(new IntentAction(this, null, R.drawable.ic_actionbar_home));
    actionBar.addAction(new SearchAction(this, R.drawable.ic_actionbar_search));

    weatherThread = new Thread(this);
    try {
        ....Unrelated Code....

        //****HERE WAS THE PROBLEM****//
        Gson gson = new Gson();

        ....More Unrelated Code....
    } catch (JsonSyntaxException ex) { }

    initMembers();
    initControls();

    if (savedInstanceState != null) {
        mSelectedLayout = savedInstanceState.getInt("CURRENT_TAB");
        setCurrentTab();
    }
    else
        loadMainLayout();
}

    ....Other unrelated code....

}


Solution

  • There are a few devices which are using GSON internally, but made the library public, causing a namespace conflict when the application attempts to reference its packaged version of gson. A possible workaround is changing the namespace of the gson jar you have included using jarjar.

    Heres a thread on the issue - The thread contains a description of at least one workaround supplied by another developer who encountered the same issue.