Java.lang.TypeNotPresentException: Type com.twitter.sdk.android.core.models.Tweet not present

android

#1

I am using Twitter REST API v1.1 to post user status app from our android application with following code after login to twitter using Twitter Official twitter button.

StatusesService service = Twitter.getApiClient().getStatusesService();

service.update(status, null, null, null, null,null,null, null,
new Callback(){
@Override
public void success(Result result){
Log.i(TWEET_SCREEN_TAG, “Tweet Successful”);
Toast.makeText(getApplicationContext(), R.string.share_twitter_tweet_success, Toast.LENGTH_LONG).show();
}
public void failure(TwitterException exception){
String sMessage = exception.getMessage();
Log.e(TWEET_SCREEN_TAG, exception.getMessage());
if(TWEET_DUPLICATE_ERROR.equals(sMessage)){
Toast.makeText(getApplicationContext(), R.string.share_twitter_retweet_failure, Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), R.string.share_twitter_tweet_failure, Toast.LENGTH_LONG).show();
}
}
});

I am using release build to test the app on device,so it is signed with proguard obfuscator enabled.
I am using the following proguard configuration file (proguard-com.twitter.sdk.android.twitter.txt) provided by twitter kit v1.5.1.

Twitter Core proguard configuration
‘-include’ this file in your proguard config
Autogenerated file – Do not modify
Proguard Config for when AppCompat is not a dependency

-dontwarn com.digits.sdk.android.*ActionBarActivity

retrofit specific

-dontwarn com.squareup.okhttp.**
-dontwarn com.google.appengine.api.urlfetch.**
-dontwarn rx.**
-dontwarn retrofit.**
-keepattributes Signature
-keepattributes Annotation
-keep class com.squareup.okhttp.** { ; }
-keep interface com.squareup.okhttp.
* { ; }
-keep class retrofit.
* { ; }
-keepclasseswithmembers class * {
@retrofit.http.
;
}

But at Runtime our app crashed after pressing Tweet button on our activity, which calls the above mentioned code.

The error was:
E/AndroidRuntime(16174): java.lang.TypeNotPresentException: Type com.twitter.sdk.android.core.models.Tweet not present
E/AndroidRuntime(16174): at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:67)
E/AndroidRuntime(16174): at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:76)
E/AndroidRuntime(16174): at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
E/AndroidRuntime(16174): at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
E/AndroidRuntime(16174): at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:75)
E/AndroidRuntime(16174): at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
E/AndroidRuntime(16174): at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
E/AndroidRuntime(16174): at libcore.reflect.Types.getTypeArray(Types.java:50)
E/AndroidRuntime(16174): at java.lang.reflect.Method.getGenericParameterTypes(Method.java:247)
E/AndroidRuntime(16174): at retrofit.RestMethodInfo.parseResponseType(Unknown Source)
E/AndroidRuntime(16174): at retrofit.RestMethodInfo.(Unknown Source)
E/AndroidRuntime(16174): at retrofit.RestAdapter.getMethodInfo(Unknown Source)
E/AndroidRuntime(16174): at retrofit.RestAdapter$RestHandler.invoke(Unknown Source)
E/AndroidRuntime(16174): at java.lang.reflect.Proxy.invoke(Proxy.java:397)
E/AndroidRuntime(16174): at $Proxy11.update(Unknown Source)
E/AndroidRuntime(16174): at com.appalladium.android.dextrlite.share.j.onClick(Unknown Source)
E/AndroidRuntime(16174): at android.view.View.performClick(View.java:4780)
E/AndroidRuntime(16174): at android.view.View$PerformClick.run(View.java:19866)
E/AndroidRuntime(16174): at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime(16174): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(16174): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(16174): at android.app.ActivityThread.main(ActivityThread.java:5254)
E/AndroidRuntime(16174): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(16174): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(16174): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
E/AndroidRuntime(16174): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
E/AndroidRuntime(16174): Caused by: java.lang.ClassNotFoundException: com.twitter.sdk.android.core.models.Tweet
E/AndroidRuntime(16174): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(16174): at java.lang.Class.forName(Class.java:309)
E/AndroidRuntime(16174): at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:65)
E/AndroidRuntime(16174): … 25 more
E/AndroidRuntime(16174): Caused by: java.lang.ClassNotFoundException: Didn’t find class “com.twitter.sdk.android.core.models.Tweet” on path: DexPathList[[zip file "/data/app/co

It got resolved after we added following to the proguard configuration file:
-keep class com.twitter.sdk.android.core.models.Tweet

So we feel this proguard instruction should be mentioned in the official proguard-com.twitter.sdk.android.twitter.txt file of twitter kit while using REST API, so that any one else should not encounter the same issue. This should be mentioned in REST API documentation too.

It must include other similar classes which are loaded dyamically using class.forName() reflection method. We encountered one such class and added it to -keep class list to preserve the class from obfuscation.

Does anybody else encounter similar issues while using REST API V1.1 ?


#2

Moving to the Fabric/Twitter Kit category for attention.


#3

Thanks for the feedback. We will look into add this to the current proguard config.


#4