All Products
Search
Document Center

HTTPDNS:Android SDK version upgrade guide

Last Updated:Dec 11, 2025

Introduction

This topic provides a detailed API upgrade guide for the HTTPDNS Android software development kit (SDK). This guide helps you migrate smoothly from an older version to the latest version and includes the following information:

  • Version compatibility overview: A comprehensive summary of the compatibility between versions from 1.x to 2.6.x. This helps you quickly identify incompatible version upgrades.

  • Incompatible version upgrade guide: Detailed upgrade steps, code examples, and a mapping table of old and new APIs for each incompatible SDK upgrade.

Version compatibility overview

The HTTPDNS Android SDK has evolved through several major versions. The following table shows the compatibility between 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 for the HTTPDNS Android SDK. This version includes a complete architecture refactoring and interface optimization. The goals of this upgrade are:

  • Unified configuration pattern: This version changes the configuration pattern from scattered runtime configurations to a unified initialization configuration that uses the Builder pattern. This resolves configuration timing issues and improves SDK stability.

  • Standardized resolution interfaces: The resolution interface architecture is redesigned to provide three resolution patterns: synchronous blocking, asynchronous, and synchronous non-blocking. These patterns meet the needs of different scenarios.

  • Modular design: Features such as Log Management are separated into dedicated classes. This achieves better separation of responsibilities and improves code maintainability.

  • Performance optimization: Resolution performance and resource utilization efficiency are improved through interface optimizations and internal implementation enhancements.

This is a major, incompatible change. Although the changes are significant, you only need to modify the interfaces used by your application. Follow the upgrade steps and the API mapping table below to complete this upgrade.

Detailed upgrade steps

  1. Update the dependency version

    dependencies {
        implementation 'com.aliyun.ams:alicloud-android-httpdns:${httpdnsVersion}'
    }
    Note

    You can obtain httpdnsVersion from the Android SDK Release Notes.

  2. Refactor the initialization code

    1. 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);
      
    2. 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);
          }
        });
      }
      }
  3. Update the resolution interfaces

    1. 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);     
    2. 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();
  4. Upgrade the interface for setting the HTTPDNS blacklist

    1. Before the upgrade

      InitConfig config = new InitConfig.Builder()
          .setDegradationFilter(new DegradationFilter() {
              @Override
              public boolean shouldDegradeHttpDNS(String host) {
                  return "example.com".equals(host);
              }
          })
          .build();
    2. After the upgrade

      InitConfig config = new InitConfig.Builder()
          .setNotUseHttpDnsFilter(new NotUseHttpDnsFilter() {
              @Override
              public boolean notUseHttpDns(String host) {
                  return "example.com".equals(host);
              }
          })
          .build();
Note

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

HttpDnsService.setHTTPSRequestEnabled(boolean)

InitConfig.Builder.setEnableHttps(boolean)

Enable expired IP

HttpDnsService.setExpiredIPEnabled(boolean)

InitConfig.Builder.setEnableExpiredIp(boolean)

Enable local cache

HttpDnsService.setCachedIPEnabled(boolean)

InitConfig.Builder.setEnableCacheIp(boolean)

Pre-resolve on network transition

HttpDnsService.setPreResolveAfterNetworkChanged(boolean)

InitConfig.Builder.setPreResolveAfterNetworkChanged(boolean)

Set resolution timeout

HttpDnsService.setTimeoutInterval(int)

InitConfig.Builder.setTimeoutMillis(int)

Enable IP ranking feature

HttpDnsService.setIPRankingList(List<IPRankingBean>)

InitConfig.Builder.setIPRankingList(List<IPRankingBean>)

Set global parameters for custom resolution

HttpDnsService.setSdnsGlobalParams(Map<String, String>)

InitConfig.Builder.setSdnsGlobalParams(Map<String, String>)

Control log output

HttpDnsService.setLogEnabled(boolean)

HttpDnsLog.enable(boolean)

Set log callback interface

HttpDnsService.setLogger(ILogger)

HttpDnsLog.setLogger(ILogger)

Enable IP ranking (old version)

HttpDnsService.setIPProbeList(List<IPRankingBean>)

InitConfig.Builder.setIPRankingList(List<IPRankingBean>)

Synchronous non-blocking interface, IPv4 resolution, returns a single IP

getIpByHostAsync(String)

getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType.v4)

Synchronous non-blocking interface, IPv4 resolution, returns a list of IPs

getIpsByHostAsync(String)

getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType.v4)

Synchronous non-blocking interface, IPv6 resolution, returns a single IP

getIPv6ByHostAsync(String)

getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType.v6)

Synchronous non-blocking interface, IPv6 resolution, returns a list of IPs

getIPv6sByHostAsync(String)

getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType.v6)

Synchronous non-blocking, IPv4 and IPv6 resolution, returns a list of IPs

getAllByHostAsync(String)

getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType.both)

Synchronous non-blocking interface, custom resolution, returns a list of IPv4 addresses

getIpsByHostAsync(String, Map<String,String>, String)

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

The HTTPDNS Android SDK has evolved through several major versions. Version 2.4.0 introduced incompatible upgrades. This guide provides a complete migration path. Follow the migration path and best practices in this guide to safely and efficiently upgrade your version of the HTTPDNS Android SDK.