sromku / android-simple-facebook

[Deprecated] Simple Facebook SDK for Android
Other
879 stars 349 forks source link

Getting `java.lang.VerifyError` #418

Closed Fleker closed 8 years ago

Fleker commented 8 years ago

I'm seeing a pretty weird error in an app and I haven't found much documentation on it.

It occurs on two phones, both running Android 4.4

java.lang.VerifyError: com/sromku/simple/fb/SimpleFacebook
at com.myapp.<init>(MyApplication.java:44)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newApplication(Instrumentation.java:1013)
at android.app.Instrumentation.newApplication(Instrumentation.java:998)
at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4393)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

The code in question is:

 SimpleFacebookConfiguration configuration = new SimpleFacebookConfiguration.Builder()
            .setAppId(String.valueOf(R.string.fb_app_id))
            .setNamespace(String.valueOf(R.string.myapp))
            .setPermissions(permissions)
            .build();

SimpleFacebook.setConfiguration(configuration);

Do you have any clue as to where this error is originating? Thanks.

xsorifc28 commented 8 years ago

Before that crash, the log shows:

VFY: unable to find class referenced in signature     
VFY: Ljava/lang/Object; is not instance of Lcom/sromku/simple/fb/listeners/OnPublishListener;
VFY: bad arg 3 (into Lcom/sromku/simple/fb/listeners/OnPublishListener;)
VFY:  rejecting call to Lcom/sromku/simple/fb/SimpleFacebook;.publish (Ljava/lang/String;Lcom/sromku/simple/fb/entities/Publishable;Lcom/sromku/simple/fb/listeners/OnPublishListener;)V
VFY:  rejecting opcode 0x6e at 0x0002
VFY:  rejected Lcom/sromku/simple/fb/SimpleFacebook;.create (Lcom/sromku/simple/fb/entities/Story$StoryObject;Lcom/sromku/simple/fb/listeners/OnCreateStoryObject;)V
Verifier rejected class Lcom/sromku/simple/fb/SimpleFacebook;
sromku commented 8 years ago

@xsorifc28 you are using String.valueOf(R.string.fb_app_id) but instead, you should use: getResources().getString(R.string.fb_app_id) and same for namespace. let me know if it works for you. thanks.

xsorifc28 commented 8 years ago

I will try this. Any ideas as to why this would relate to the verifier error ?

I'm trying to figure out why it says VFY: unable to find class referenced in signature (Lcom/sromku/simple/fb/listeners/OnCreateStoryObject;)

I tried updating the dependencies/libraries of simple-fb but the error continues. The project's sample app seems to work fine, however, I'm having the issue in my app. Wondering if it is due to multidex issues/ I do have multidex enabled.

sromku commented 8 years ago

Are you using Proguard in your app?

xsorifc28 commented 8 years ago

No, minifyEnabled is false.

sromku commented 8 years ago

Indeed, it sounds like multidexing issue. Truly, didn't play too much with multidexing, so it's hard to say, what exactly doesn't play well. But from your log Verifier rejected class looks, like this an indication for runtime issue to come. On SO, I found similar problems. I am not going to dive into multidexing right now, but if you have any enlightenments, please share :)

xsorifc28 commented 8 years ago

SimpleFacebook.setConfiguration(configuration); was inside the constructor for MyApplication(), I moved it to onCreate() within MyApplication, seems to work fine now.

Weird how this was an issue on +/- API 16, but not on >API 21.

I think it was related to the multidex calls.

sromku commented 8 years ago

Wasn't MyApplication your extended application class?

xsorifc28 commented 8 years ago

Previously, what caused the verify error:

public class MyAplication extends Application {

    public MyApplication() {
        super();
        ...
        SimpleFacebook.setConfiguration(configuration);
      }

    @Override
    public onCreate () {
        super.onCreate();

      }
}

The above code worked for API 21+

Now, with error gone:

public class MyAplication extends Application {

    public MyApplication() {
        super();
      }

    @Override
    public onCreate () {
        super.onCreate();
        ...
        SimpleFacebook.setConfiguration(configuration);
      }
}
sromku commented 8 years ago

Cool. It's interesting why would it work on 21+. Since constructor shouldn't be extended and used and still, it worked. nice. Anyway, much thanks for sharing!