Upgrading from IMKit 4.X to 5.X
This document outlines the upgrade process from IMKit SDK version 4.X to 5.X.
Key Changes
Note
IMKit SDK 5.x is now open-source. This version has been completely refactored using MVVM architecture and is incompatible with versions 2.x and 4.x. A seamless upgrade is not possible.
Detailed changes include:
1. Dependency Changes
Google introduced AndroidX at Google I/O 2018 as a replacement for the android.support.xxx libraries. Google has officially discontinued support for the legacy support libraries. Therefore, RC IMKit SDK 5.X and later versions now use AndroidX and no longer support the support libraries.
2. Class Path Adjustments
IMKit SDK 5.X has been refactored using MVVM architecture, resulting in changes to many class paths. The table below lists the path changes for publicly exposed classes from versions prior to 5.X:
2.x/4.x Path | 5.x Path |
---|---|
io.rong.imkit.fragment.ConversationListFragment | io.rong.imkit.conversationlist.ConversationListFragment |
io.rong.imkit.fragment.ConversationFragment | io.rong.imkit.conversation.ConversationFragment |
io.rong.imkit.RongExtension | No direct replacement. Follow the IMKit 5.x documentation to re-integrate plugins. |
io.rong.imkit.userInfoCache.RongUserInfoManager | io.rong.imkit.userinfo.RongUserInfoManager |
io.rong.imkit.mention.RongMentionManager | io.rong.imkit.feature.mention.RongMentionManager |
io.rong.imkit.manager.IUnReadMessageObserver | io.rong.imkit.manager.UnReadMessageManager.IUnReadMessageObserver |
io.rong.imkit.RongConfigurationManager | io.rong.imkit.utils.language.RongConfigurationManager |
Notes on path adjustments:
- Refer to the table above and use Android Studio's "Find and Replace" (Command+Shift+R) to globally search for old class paths and replace them with new ones.
io.rong.imkit.RongExtension
cannot be upgraded via replacement. Follow the IMKit 5.x documentation to re-integrate plugins.- If you've deeply customized IMKit SDK, some class path adjustments may not be listed above. After upgrading, Android Studio will highlight unresolved imports. Delete the unresolved import paths and let Android Studio suggest the new paths. For multiple occurrences, use global search and replace as described in step 1.
3. Integration Method Changes
Page navigation has shifted from implicit calls to explicit calls, simplifying and modifying the integration steps. Remove the old IMKit SDK configurations from your AndroidManifest.xml file and refer to the official documentation for re-integration.
4. RongIM Interface Changes
-
Connection interface return value changed:
- The
connect()
method now returnsvoid
instead ofRongIM
.
- The
-
Renamed interfaces:
2.x/4.x Interface 5.x Interface N/A removeOnReceiveMessageListener N/A removeConnectionStatusListener setSendMessageListener setMessageInterceptor sendImageMessage sendMediaMessage setMaxVoiceDurationg setMaxVoiceDuration startConversationList N/A startPublicServiceProfile N/A -
Migrated interfaces: User information-related interfaces have moved from
RongIM
to the standaloneUserDataProvider
class.2.x/4.x Interface 5.x Interface RongIM.UserInfoProvider UserDataProvider.UserInfoProvider RongIM.GroupInfoProvider UserDataProvider.GroupInfoProvider RongIM.GroupUserInfoProvider UserDataProvider.GroupUserInfoProvider -
The following UI-unrelated interfaces have been removed from
RongIM
. Use the corresponding methods in the IMLib core classRongIMClient
instead.Removed Interfaces saveTextMessageDraft setMessageExtra setMessageReceivedStatus setServerInfo setStatisticDomain supportResumeBrokenTransfer searchPublicService searchPublicServiceByType subscribePublicService unsubscribePublicService downloadMedia -
The following interfaces have been removed and are no longer supported:
Interface Name refreshDiscussionCache createDiscussion createDiscussionChat getDiscussion quitDiscussion addMemberToDiscussion recordNotificationEvent isNotificationQuiteHoursConfigured getEncryptedSessionStatus getAllEncryptedConversations quitEncryptedSession isRegisted getHistoryMessages() (deprecated) disconnect() (deprecated) -
Deprecated interfaces from older versions have been removed.
5. Message Display Template Changes
The list page has been upgraded from ListView to the more efficient RecycleView, requiring adjustments to custom message display templates.
- Custom message display templates must now inherit from
BaseMessageItemProvider<>
and implement base class methods. - Remove annotations from old templates. Annotation properties can now be configured by calling methods of the base class member
mConfig
.
import android.content.Context;
import android.text.Spannable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
import io.rong.imkit.R;
import io.rong.imkit.model.UiMessage;
import io.rong.imkit.widget.adapter.IViewProviderListener;
import io.rong.imkit.widget.adapter.ViewHolder;
import io.rong.imlib.model.MessageContent;
public class CustomMessageItemProvider extends BaseMessageItemProvider<CustomMessage> {
public CustomMessageItemProvider(){
mConfig.showSummaryWithName = false; // Configure template properties.
}
/**
* Create ViewHolder
* @param parent Parent ViewGroup
* @param viewType View type
* @return ViewHolder
*/
@Override
protected ViewHolder onCreateMessageContentViewHolder(ViewGroup parent, int viewType) {
View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_message_item, parent, false);
return new ViewHolder(parent.getContext(), rootView);
}
/**
* Set values for views in the message UI
* @param holder ViewHolder
* @param parentHolder Parent ViewHolder
* @param customMessage The message corresponding to this template
* @param uiMessage {@link UiMessage}
* @param position Message position
* @param list List
* @param listener Click event listener for ViewModel. If a sub-view's click event requires ViewModel handling, use this listener callback.
*/
@Override
protected void bindMessageContentViewHolder(ViewHolder holder, ViewHolder parentHolder, CustomMessage customMessage, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
}
/**
* @param holder ViewHolder
* @param customMessage Custom message
* @param uiMessage {@link UiMessage}
* @param position Position
* @param list List data
* @param listener Click event listener for ViewModel. If a sub-view's click event requires ViewModel handling, use this listener callback.
* @return Whether the click event is consumed
*/
@Override
protected boolean onItemClick(ViewHolder holder, CustomMessage customMessage, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
return false;
}
/**
* Determine whether this template should display the message based on its content
*
* @param messageContent Message content
* @return Whether this template handles the message.
*/
@Override
protected boolean isMessageViewType(MessageContent messageContent) {
return messageContent instanceof CustomMessage ;
}
/**
* Content to display in the conversation list when the last message is of this type.
* For example: Image messages should display "Image" in the conversation list.
* @param context Context
* @param customMessage Custom message
* @return String resource to display in the conversation
*/
@Override
public Spannable getSummarySpannable(Context context, CustomMessage customMessage) {
return null;
}
}
6. Extension Area Customization Changes
The input area configuration has changed. The DefaultExtensionConfig
class now provides default plugin lists and emoji lists. Override this class to adjust plugin positions or add/remove items.
7. Local Notification Changes
When the app is in the background, local notifications for multiple messages from the same sender now display individually instead of being collapsed.
8. Internal Implementation Changes
- Resource name changes: IMKit SDK 5.x has standardized resource naming. If you've customized resource files, refer to the official customization documentation to replace corresponding resources.
- EventBus removed: IMKit 5.x no longer uses EventBus for event distribution, replacing it with the observer pattern. If your app uses EventBus from older SDK versions, you'll need to include the dependency separately.
- RongContext class removed: Replace any usage of
RongContext
as context with your app's own context. - Due to the MVVM framework, many business-related interfaces in fragments have been removed. Refer to the official 5.x documentation to re-implement customizations.
4.X Upgrade Guide
1. Migrate to AndroidX
IMKit 5.x no longer supports support libraries.
2. Connection Interface Changes
Change the return type of the connection interface from RongIM
to void
.
3. Adapt ConversationListFragment
-
Remove calls to
setUri()
when integratingConversationListFragment
. Configure the originalsetUri()
parameters using:RongConfigCenter.conversationListConfig().setDataProcessor(new DataProcessor<Conversation>() {
@Override
public Conversation.ConversationType[] supportedTypes() {
return supportedTypes; // Return conversation types supported by the list
}
@Override
public List<Conversation> filtered(List<Conversation> data) {
return data;
}
@Override
public boolean isGathered(Conversation.ConversationType type) {
if (type.equals(Conversation.ConversationType.SYSTEM)) {
return true; // Return true for conversations that should be aggregated
} else {
return false;
}
}
});By default, the SDK supports all conversation types without aggregation. If you have no custom requirements, simply remove the
setUri()
call. -
Register the conversation list activity with the SDK:
RouteUtils.registerActivity(RouteUtils.RongActivityType.ConversationListActivity, CustomConversationListActivity.class);
-
Change the conversation list launch method. Replace:
RongIM.getInstance().startConversationList(Context , supportedConversation);
with:
RouteUtils.routeToConversationListActivity(context,title);
4. Adapt ConversationFragment
-
Register the conversation activity with the SDK:
RouteUtils.registerActivity(RouteUtils.RongActivityType.ConversationActivity, CustomConversationListActivity.class);
5. Set User Information
User information interfaces have moved from RongIM
to the UserDataProvider
class. Remove the parent class RongIM.
from user information interface declarations and let Android Studio import the new paths.
6. Adapt New Customization Methods
Due to architectural changes, many business-related interfaces in fragments have been removed. Refer to the 5.x documentation to re-implement customizations based on your original requirements.