Introduction
Use this guide to migrate your HTTPDNS Android SDK from an older version to the latest version. The guide covers:
-
Version compatibility overview: Compatibility between versions from
1.xto2.6.x, so you can quickly identify incompatible upgrades. -
Incompatible version upgrade guide: Upgrade steps, code examples, and old-to-new API mapping for each incompatible SDK version.
Version compatibility overview
The following table shows the compatibility between HTTPDNS Android SDK versions from 1.x.x to 2.6.x.
|
SDK version |
Compatibility |
|
1.x.x - 2.3.x |
Fully compatible |
|
2.3.5 - 2.4.0 |
Initialization interface adjusted |
|
2.4.0 - 2.5.0 |
Fully compatible |
|
2.5.0 - 2.6.6 |
API level upgraded (Android 4.4) |
Guide to upgrading the SDK to version 2.4.0 or later
Version 2.4.0 is a major milestone that includes a complete architecture refactoring and interface optimization. Key changes:
-
Unified configuration pattern: Replaces scattered runtime configurations with a unified Builder-pattern initialization, resolving configuration timing issues and improving SDK stability.
-
Standardized resolution interfaces: Redesigned resolution interface with three patterns — synchronous blocking, asynchronous, and synchronous non-blocking — to cover different use cases.
-
Modular design: Features such as Log Management are separated into dedicated classes for better separation of responsibilities and maintainability.
-
Performance optimization: Improved resolution performance and resource utilization through interface and internal implementation enhancements.
This is a major, incompatible change. However, you only need to modify the interfaces that your application uses. Follow the upgrade steps and API mapping table below to complete the migration.
Detailed upgrade steps
-
Update the dependency version
dependencies { implementation 'com.aliyun.ams:alicloud-android-httpdns:${httpdnsVersion}' }NoteYou can obtain
httpdnsVersionfrom the Android SDK Release Notes. -
Refactor the initialization code
-
Before the upgrade
// Old version: Scattered configuration HttpDnsService httpdns = HttpDns.getService(this, "your_account_id"); httpdns.setHTTPSRequestEnabled(true); httpdns.setExpiredIPEnabled(true); httpdns.setCachedIPEnabled(true); httpdns.setPreResolveAfterNetworkChanged(true); httpdns.setTimeoutInterval(3000); httpdns.setLogEnabled(true); httpdns.setLogger(new ILogger() { @Override public void log(String message) { Log.d("HTTPDNS", message); } }); httpdns.setDegradationFilter(new DegradationFilter() { @Override public boolean shouldDegradeHttpDNS(String host) { return "example.com".equals(host); } }); // If you use the IP ranking feature List<IPRankingBean> ipProbeList = new ArrayList<>(); ipProbeList.add(new IPRankingBean("example.com", 80)); httpdns.setIPProbeList(ipProbeList); -
After the upgrade
List<IPRankingBean> ipRankingList = new ArrayList<>(); ipRankingList.add(new IPRankingBean("example.com", 80)); // New version: Unified configuration with the Builder pattern InitConfig config = new InitConfig.Builder() .setContext(this) // Required .setEnableHttps(true) // Replaces setHTTPSRequestEnabled .setEnableExpiredIp(true) // Replaces setExpiredIPEnabled .setEnableCacheIp(true) // Replaces setCachedIPEnabled .setPreResolveAfterNetworkChanged(true) // Replaces setPreResolveAfterNetworkChanged .setTimeoutMillis(3000) // Replaces setTimeoutInterval .setIPRankingList(ipRankingList) // Replaces setIPProbeList .setNotUseHttpDnsFilter(new NotUseHttpDnsFilter() { @Override public boolean notUseHttpDns(String host) { return "example.com".equals(host); } }) .buildFor("your_account_id"); HttpDnsService httpdns = HttpDns.getService("your_account_id", config); // Log Management is now separate HttpDnsLog.enable(true); // Replaces setLogEnabled HttpDnsLog.setLogger(new ILogger() { // Replaces setLogger @Override public void log(String message) { Log.d("HTTPDNS", message); } }); } }
-
-
Update the resolution interfaces
-
Before the upgrade
// Synchronous non-blocking, IPv4, single IP String ip = httpdns.getIpByHostAsync(host); // Synchronous non-blocking, IPv4, all IPs String[ ] ips = httpdns.getIpsByHostAsync(host); // Synchronous non-blocking, IPv6, single IP String ipv6 = httpdns.getIPv6ByHostAsync(host); // Synchronous non-blocking, IPv4 and IPv6, all IPs HTTPDNSResult result = httpdns.getAllByHostAsync(host); -
After the upgrade
// Synchronous non-blocking, IPv4, all IPs HTTPDNSResult httpDnsResult = httpdns.getHttpDnsResultForHostSyncNonBlocking(host, RequestIpType.v4) String[ ] ips = httpDnsResult.getIps(); // Synchronous non-blocking, IPv6, all IPs HTTPDNSResult httpDnsResult = httpdns.getHttpDnsResultForHostSyncNonBlocking(host, RequestIpType.v6) String[ ] ipv6s = httpDnsResult.getIpv6s(); // Synchronous non-blocking, IPv4 and IPv6, all IPs HTTPDNSResult httpDnsResult = httpdns.getHttpDnsResultForHostSyncNonBlocking(host, RequestIpType.v6) String[ ] ips = httpDnsResult.getIps(); String[ ] ipv6s = httpDnsResult.getIpv6s();
-
-
Upgrade the interface for setting the HTTPDNS blacklist
-
Before the upgrade
InitConfig config = new InitConfig.Builder() .setDegradationFilter(new DegradationFilter() { @Override public boolean shouldDegradeHttpDNS(String host) { return "example.com".equals(host); } }) .build(); -
After the upgrade
InitConfig config = new InitConfig.Builder() .setNotUseHttpDnsFilter(new NotUseHttpDnsFilter() { @Override public boolean notUseHttpDns(String host) { return "example.com".equals(host); } }) .build();
-
If your application does not use any incompatible APIs, you can skip these steps.
API upgrade mapping table
|
API categorization |
Before upgrade |
After upgrade |
|
Enable HTTPS request |
||
|
Enable expired IP |
||
|
Enable local cache |
||
|
Pre-resolve on network transition |
InitConfig.Builder.setPreResolveAfterNetworkChanged(boolean) |
|
|
Set resolution timeout |
||
|
Enable IP ranking feature |
||
|
Set global parameters for custom resolution |
||
|
Control log output |
||
|
Set log callback interface |
||
|
Enable IP ranking (old version) |
||
|
Synchronous non-blocking interface, IPv4 resolution, returns a single IP |
getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType.v4) |
|
|
Synchronous non-blocking interface, IPv4 resolution, returns a list of IPs |
getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType.v4) |
|
|
Synchronous non-blocking interface, IPv6 resolution, returns a single IP |
getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType.v6) |
|
|
Synchronous non-blocking interface, IPv6 resolution, returns a list of IPs |
getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType.v6) |
|
|
Synchronous non-blocking, IPv4 and IPv6 resolution, returns a list of IPs |
getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType.both) |
|
|
Synchronous non-blocking interface, custom resolution, returns a list of IPv4 addresses |
getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType, Map<String, String>, String) |
|
|
Synchronous non-blocking, custom resolution, returns a list of IPv4 addresses |
getHttpDnsResultForHostAsync(String, Map<String, String> , String) |
getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType, Map<String, String>, String) |
Summary
Version 2.4.0 introduced incompatible API changes. Follow the migration steps and API mapping table in this guide to upgrade your HTTPDNS Android SDK safely and efficiently.