Upgrading from IMKit 2.X to 5.X
This document outlines the upgrade process from IMKit SDK 2.X to 5.X.
Key Changes
IMKit SDK 5.x is now open-source. This version has been completely refactored using the MVVM architecture, making it incompatible with versions 2.x and 4.x. A smooth upgrade is not possible.
Key changes include:
1. Dependency Changes
At Google I/O 2018, AndroidX was introduced as a replacement for the android.support.xxx libraries. Google has officially stated that support libraries will no longer be maintained. Therefore, RC IMKit SDK 5.X and later versions now use AndroidX and no longer support support libraries.
2. Class Path Adjustments
IMKit SDK 5.X has been refactored using the MVVM framework, resulting in changes to many class paths. Below is a comparison of public class paths between versions:
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 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
- Use the table above to globally search and replace old class paths in AndroidStudio (Command+Shift+R).
io.rong.imkit.RongExtension
cannot be replaced directly. Follow IMKit 5.x documentation to re-integrate plugins.- If you've deeply customized IMKit SDK, some class paths may not be listed above. After upgrading, AndroidStudio will flag errors. Delete unresolved import paths and let AndroidStudio suggest new paths. For multiple occurrences, use global search and replace.
3. Integration Method Changes
Page navigation has shifted from implicit to explicit calls, simplifying integration steps. Remove old IMKit SDK configurations from AndroidManifest.xml and refer to the official documentation for re-integration.
4. RongIM Interface Changes
-
Connect Interface Return Value: Changed from RongIM to void.
-
Renamed Interfaces:
2.x/4.x Interface 5.x Interface None removeOnReceiveMessageListener None removeConnectionStatusListener setSendMessageListener setMessageInterceptor sendImageMessage sendMediaMessage setMaxVoiceDurationg setMaxVoiceDuration startConversationList Removed startPublicServiceProfile Removed -
Migrated Interfaces: User info-related interfaces have moved from RongIM to UserDataProvider.
2.x/4.x Interface 5.x Interface RongIM.UserInfoProvider UserDataProvider.UserInfoProvider RongIM.GroupInfoProvider UserDataProvider.GroupInfoProvider RongIM.GroupUserInfoProvider UserDataProvider.GroupUserInfoProvider -
Removed Interfaces: The following UI-unrelated interfaces have been removed. Use RongIMClient from IMLib core instead.
Removed Interfaces saveTextMessageDraft setMessageExtra setMessageReceivedStatus setServerInfo setStatisticDomain supportResumeBrokenTransfer searchPublicService searchPublicServiceByType subscribePublicService unsubscribePublicService downloadMedia -
Deprecated Interfaces: The following interfaces are no longer supported.
Interface Name refreshDiscussionCache createDiscussion createDiscussionChat getDiscussion quitDiscussion addMemberToDiscussion recordNotificationEvent isNotificationQuiteHoursConfigured getEncryptedSessionStatus getAllEncryptedConversations quitEncryptedSession isRegisted getHistoryMessages() (deprecated) disconnect() (deprecated) -
Legacy Deprecated Interfaces: Removed from older versions.
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 templates must now inherit
BaseMessageItemProvider<>
and implement base methods. - Remove old annotations from templates. Configure properties in the new template builder class via
mConfig
methods.
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.
}
@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);
}
@Override
protected void bindMessageContentViewHolder(ViewHolder holder, ViewHolder parentHolder, CustomMessage customMessage, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
// Bind views here.
}
@Override
protected boolean onItemClick(ViewHolder holder, CustomMessage customMessage, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
return false;
}
@Override
protected boolean isMessageViewType(MessageContent messageContent) {
return messageContent instanceof CustomMessage;
}
@Override
public Spannable getSummarySpannable(Context context, CustomMessage customMessage) {
return null;
}
}
6. Extension Area Customization Changes
Input area configuration has changed. The DefaultExtensionConfig
class now provides default plugin and emoji lists. Override this class to adjust plugin order 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 grouped.
8. Internal Implementation Changes
- Resource Name Changes: IMKit SDK 5.x standardizes resource naming. If you've customized resources, refer to the official documentation to update names.
- EventBus Removal: IMKit 5.x no longer uses EventBus for event distribution, switching to the observer pattern. If your app relies on EventBus, add the dependency separately.
- RongContext Removal: Replace any usage of RongContext with your app's context.
- MVVM Refactoring: Many business-related interfaces in fragments have been removed. Refer to the 5.x documentation for re-customization.
2.X Upgrade Guide
1. Migrate to AndroidX
IMKit 5.x no longer supports support libraries.
2. Connect Interface Update
Change the return type of the connect interface from RongIM to void.
3. Adapt ConversationListFragment
-
Remove
setUri()
calls. Configure supported conversation types via:RongConfigCenter.conversationListConfig().setDataProcessor(new DataProcessor<Conversation>() {
@Override
public Conversation.ConversationType[] supportedTypes() {
return supportedTypes; // Return supported conversation types.
}
@Override
public List<Conversation> filtered(List<Conversation> data) {
return data;
}
@Override
public boolean isGathered(Conversation.ConversationType type) {
return type.equals(Conversation.ConversationType.SYSTEM); // Return true for aggregated conversations.
}
});By default, SDK supports all conversation types without aggregation. If no customization is needed, simply remove
setUri()
calls. -
Register the conversation list activity with the SDK:
RouteUtils.registerActivity(RouteUtils.RongActivityType.ConversationListActivity, CustomConversationListActivity.class);
-
Update 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 Info
User info-related interfaces have moved from RongIM to UserDataProvider. Remove the RongIM.
prefix and let AndroidStudio 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 custom features.