Fabric for Unity - ClassNotFoundException TwitterAuthToken in new project



Hi there.

We are using Unity 5.3.4f1 and want to integrate Twitter into our app. We decided to start with a blank Unity project to smoothen the process of getting tweets working before moving it into the main branch of our project. However we have not been able to successfully tweet. The steps we took to integrate Twitter are:

  • Signup up for Fabric and download the TwitterKit Unity package, as mentioned here https://docs.fabric.io/unity/fabric/overview.html.
  • Open the package in Unity.
  • Follow the Fabric integration steps in Unity by selecting Fabric -> Prepare Fabric, entering Fabric account details and selecting the Twitter Kit.
  • Implemented code as per the instructions on the site provided above.

The error we are getting is:

E/Parcel (22200): Class not found when unmarshalling: com.twitter.sdk.android.core.TwitterAuthToken
E/Parcel (22200): java.lang.ClassNotFoundException: com.twitter.sdk.android.core.TwitterAuthToken
E/Parcel (22200): at java.lang.Class.classForName(Native Method)
E/Parcel (22200): at java.lang.Class.forName(Class.java:309)
E/Parcel (22200): at java.lang.Class.forName(Class.java:273)
E/Parcel (22200): at android.os.Parcel.readParcelableCreator(Parcel.java:2281)
E/Parcel (22200): at android.os.Parcel.readParcelable(Parcel.java:2245)
E/Parcel (22200): at android.os.Parcel.readValue(Parcel.java:2152)
E/Parcel (22200): at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
E/Parcel (22200): at android.os.BaseBundle.unparcel(BaseBundle.java:221)
E/Parcel (22200): at android.os.BaseBundle.getString(BaseBundle.java:918)
E/Parcel (22200): at android.content.Intent.getStringExtra(Intent.java:5247)
E/Parcel (22200): at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1502)
E/Parcel (22200): at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1086)
E/Parcel (22200): at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4347)
E/Parcel (22200): at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:4246)
E/Parcel (22200): at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:144)
E/Parcel (22200): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2791)
E/Parcel (22200): at android.os.Binder.execTransact(Binder.java:446)
E/Parcel (22200): Caused by: java.lang.ClassNotFoundException: Didn’t find class “com.twitter.sdk.android.core.TwitterAuthToken” on path: DexPathList[[directory “.”],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/Parcel (22200): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/Parcel (22200): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/Parcel (22200): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/Parcel (22200): … 17 more
E/Parcel (22200): Suppressed: java.lang.ClassNotFoundException: com.twitter.sdk.android.core.TwitterAuthToken
E/Parcel (22200): at java.lang.Class.classForName(Native Method)
E/Parcel (22200): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/Parcel (22200): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/Parcel (22200): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/Parcel (22200): … 18 more
E/Parcel (22200): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
I/ActivityManager(22200): START u0 {cmp=net.pluginmedia.nationalnumeracyrunner/com.twitter.sdk.android.tweetcomposer.ComposerActivity (has extras)} from uid 10180 on display 0

And the code we are using is:

protected static string cachedImagePath = “”;

public static void ShareImageViaTwitter(string imagePath)
cachedImagePath = imagePath;

  if (!cachedImagePath.StartsWith("file://"))
  	cachedImagePath = "file://" + cachedImagePath;
  if(Twitter.Session == null){
  	Card card = new AppCardBuilder()
  	Twitter.Compose(Twitter.Session, card);


protected static void TwitterResultHandler(TwitterSession currentSession)
if(currentSession != null){

The tweet dialogue successfully appears with our image, but on pressing the “Tweet” button it doesn’t Tweet to the user’s timeline, and we get this error:

E/TweetUploadService(17314): Post Tweet failed
E/TweetUploadService(17314): com.twitter.sdk.android.core.TwitterApiException: 403 Forbidden
E/TweetUploadService(17314): at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:383)
E/TweetUploadService(17314): at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
E/TweetUploadService(17314): at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
E/TweetUploadService(17314): at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
E/TweetUploadService(17314): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
E/TweetUploadService(17314): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/TweetUploadService(17314): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/TweetUploadService(17314): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/TweetUploadService(17314): at java.lang.Thread.run(Thread.java:818)

Is there anything obvious we are missing out? Any help would be much appreciated.




Sorry to reply to my own post but I’d just like to provide a bit more information.

The Android project that is output by Unity correctly contains twitter-core-1.6.4.jar as a library, and its this jar that contains the class com.twitter.sdk.android.core.TwitterAuthToken. This can be seen by inspecting the contents of the jar. Therefore I’m still slightly confused as to why it would be erroring with a ClassNotFoundException.

Does anyone have an idea about this?



Hey @JProvan,

The class not found error is a bit confusing when you see the SDK in the Jar. Is there a build option within Unity that you’re only pulling it in for certain types of builds?

On the second error, that sounds like your Twitter Consumer Key hasn’t been whitelisted for access to Tweet with a card. You may want to request access as well: https://docs.fabric.io/unity/twitter/compose-tweets.html#compose-tweets



Hi @bonnell, thanks for your reply.

Unity does have an option to pull in SDKs for certain platforms, and in our project the Twitter libraries are correctly set up to be pulled in to our Android build. Making a build in Unity by exporting to a Google Android project also shows that the libraries have been correctly copied into the exported project.

We are going to request access to whitelist our app as that could definitely be the reason for the 403 Forbidden error. We will wait for our app to be whitelisted and test it again before looking further into the ClassNotFound exception. Do you think it could be a red herring? Or is there any other steps you can think we may have missed to have caused that?



Anytime @JProvan, the 403 will be solved by whitelisting. I’d recommend waiting before doing more testing, but it’s strange that you’re seeing just a class not found on com.twitter.sdk.android.core.TwitterAuthToken when the com.twitter.sdk.core.TwitterApiException is resolving fine, but giving an appropriate error. That suggests to me that only a portion of the relevant important happened, but not entirely.

If you have a sample or test project laying around, do you experience the same class not found error on that one?


Hi @bonnell. We do have a test Unity project and it is in this project that we get the error. The project is set up using the steps from the link previously mentioned (https://docs.fabric.io/unity/fabric/overview.html) so I would have thought we wouldn’t get the ClassNotFound error.

Either way, we’ll wait for the whitelisting and report back whether it helps us.

Thanks again.


Sounds good @JProvan - sorry for the trouble you’re hitting!


Hi again. Just posting so anyone else who might have come across this problem can see what worked for us in the end.

Whitelisting the app fixed our obvious issue of the 403 Forbidden error, and tweets sent from the app began appearing on my Twitter. The java.lang.ClassNotFoundException: com.twitter.sdk.android.core.TwitterAuthToken error is still appearing, but isn’t preventing tweets from being posted so I’m not overly concerned about it at this stage.

We did think there was still an issue with the app card not properly appearing. Visiting this tweet in browser (https://twitter.com/provan_james/status/778230205408305152) shows the text “Test” with no other content. However, viewing it in the Android Twitter app, the app card renders correctly (thanks to this forum post Unity Fabric AppCard not rendering the for the hint).

@bonnell, is this expected behaviour when using the Unity SDK with the app card builder as per these docs https://docs.fabric.io/unity/twitter/compose-tweets.html? I would have hoped a link to the Google Play store page would have been provided at the least.