Apu Pavithran
Aug 13, 2018
8:56 pm

Exception while migrating to Knox SDK

Hi

We've migrated to Knox SDK, but we're getting an exception on the createApnSettings (ApnSettings apn) method. Here's the exception:

java.lang.NoSuchFieldError: protocol field from com.samsung.android.knox.net.apn.ApnSettings class is only supported from API level 20 and above (current is 16)
at com.samsung.android.knox.net.apn.ApnSettingsPolicy.createApnSettings(ApnSettingsPolicy.java:18)

Can you let me know why this is happening after it is mentioned in the Knox SDK reference (https://seap.samsung.com/api-references/android/reference/com/samsung/android/knox/net/apn/ApnSettingsPolicy.html#createApnSettings(com.samsung.android.knox.net.apn.ApnSettings)) that this method is supported from API level 2?

We've got a Samsung Galaxy J2 on which we tested, whose Knox version details are as follows:

  • KNOX 2.4.1
  • Standard SDK 5.4.1
  • Premium SDK 2.4.1
  • Customization SDK 2.5.0
  • Container 2.4.1
  • CEP 2.0.1
  • Enterprise Billing 1.2.0
  • OTP 1.1.1
  • SE for Android 2.3.0
  • SSO 2.4.1
  • Shared Devices N/A
  • TIMA 3.0

Edit: We've added (apk files('libs/supportlib.jar')) in gradle to work in Knox v2.9 or earlier.

Jenna Slomowitz
Aug 15, 2018
6:42 pm

Hello Apu,

The error is from using the protocol field. This field is only supported for API level 20 and above which your device does not meet. 

Best regards,

Jenna

 

Comments

Hi

We are setting the protocol for API level 20 and higher. Here's the code:

if (EnterpriseDeviceManager.getAPILevel() >= 20) {
    apnSettings.protocol = this.protocol;
    apnSettings.roamingProtocol = this.roamingProtocol;
}

We are getting these error on apnSettingsPolicy.createApnSettings(apnSettings), not on protocol field.

EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
ApnSettingsPolicy apnSettingsPolicy = edm.getApnSettingsPolicy();

ApnSettings apnSettings = new ApnSettings();
apnSettings.user = this.username;
apnSettings.password = this.password;
apnSettings.name = this.apnName;
apnSettings.apn = this.apn;
apnSettings.server = this.server;
apnSettings.mmsc = this.mmsc;
apnSettings.mmsProxy = this.mmsProxy;
apnSettings.mmsPort = this.mmsPort;
apnSettings.mcc = this.mcc;
apnSettings.mnc = this.mnc;
apnSettings.type = this.type;
apnSettings.proxy = this.proxy;
apnSettings.authType = this.authType;
if (EnterpriseDeviceManager.getAPILevel() >= 20) {
    apnSettings.protocol = this.protocol;
    apnSettings.roamingProtocol = this.roamingProtocol;
}

try {
    long apnId = apnSettingsPolicy.createApnSettings(apnSettings);
    if (apnId != -1) {
        apnSettingsPolicy.setPreferredApn(apnId);
        Log.d(TAG, "APN created");
    } else {
        Log.d(TAG, "APN creation failed");
    }

} catch (SecurityException e) {
    Log.w(TAG, "SecurityException: " + e);
}
Apu PavithranAug 20, 2018 at 1:18 pm
Tobias Schultes
Oct 08, 2018
11:49 am

I faced the same issue.

The problem is that when creating ApnSettings with new ApnSettings(), the fields protocol and roamingProtocol are already set to default values. createApnSettings crashes then, because those values are set.

A workaround would be to set both fields to null for API level < 20.

Can you please provide a bugfix in the next version of Knox SDK / supportlib, so we can remove the workaround? protocol and roamingProtocol should be initialized to null in new ApnSettings(), or NoSuchFieldError be removed.

 

Jenna Slomowitz
Oct 09, 2018
5:07 pm

Hello all,

Our engineering team has gotten back to us. This issue is fixed in the Knox 3.2 release.

Best regards,

Jenna

Afşin Çelik
Jul 25, 2019
8:26 am

Hi,

We are facing the same issue when we are testing on API level 11 device. Knox SDK 3.3 and supportlib is using. The other classes and methods are working. Only ApnSettings is getting error.

Caused by: java.lang.NoSuchFieldError: protocol field from com.samsung.android.knox.net.apn.ApnSettings class is only supported from API level 20 and above (current is 11)
at com.samsung.android.knox.net.apn.ApnSettingsPolicy.createApnSettings(ApnSettingsPolicy.java:18)