Android java.lang.NoClassDefFoundError导致KitKat设备上的应用程序崩溃:java.nio.charset.StandardCharset
我在它发生的地方使用的代码Android java.lang.NoClassDefFoundError导致KitKat设备上的应用程序崩溃:java.nio.charset.StandardCharset,android,Android,我在它发生的地方使用的代码 Caused by java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets common.HMACSha1Util.sha1 + 66(HMACSha1Util.java:66) network.NetHTTPConnection.postSecureRequest + 122(NetHTTPConnection.java:122) NetHTTPConnection.h
Caused by java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
common.HMACSha1Util.sha1 + 66(HMACSha1Util.java:66)
network.NetHTTPConnection.postSecureRequest + 122(NetHTTPConnection.java:122)
NetHTTPConnection.httpPostRequest + 62(NetHTTPConnection.java:62)
network.AppNetworkController$1.onBackgoundProcess + 68(AppNetworkController.java:68)
at network.AppNetworkController$AsyncRequest.doInBackground + 137(AppNetworkController.java:137)
at network.AppNetworkController$AsyncRequest.doInBackground + 125(AppNetworkController.java:125)
at android.os.AsyncTask$2.call + 287(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run + 234(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run + 230(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1080(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 573(ThreadPoolExecutor.java:573)
at java.lang.Thread.run + 841(Thread.java:841)
公共静态字符串sha1(映射nvps){
试一试{
//从原始密钥字节中获取hmac_sha1密钥
byte[]keyBytes=AppProperties.VERIFICATION\u KEY
.getBytes();
SecretKeySpec signingKey=新的SecretKeySpec(keyBytes,“HmacSHA1”);
//获取hmac_sha1 Mac实例并使用签名密钥初始化
Mac Mac=Mac.getInstance(“HmacSHA1”);
mac.init(签名密钥);
//根据输入数据字节计算hmac
字节[]rawHmac=mac.doFinal(getStringFromMap(nvps)
.getBytes());
//将原始字节转换为十六进制
字节[]hexBytes=新的十六进制().encode(rawHmac);
//将十六进制字节数组转换为字符串
返回新字符串(hexBytes,StandardCharsets.UTF_8);
}捕获(例外e){
}
}
返回新字符串时出错(十六字节,StandardCharsets.UTF_8)
我知道StandardCharset在Kikat中不可用,但需要帮助我如何更改它应在kitkat设备中工作以避免使用
StandardCharset
public static String sha1(Map<String,String> nvps) {
try {
// Get an hmac_sha1 key from the raw key bytes
byte[] keyBytes = AppProperties.VERIFICATION_KEY
.getBytes();
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1");
// Get an hmac_sha1 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
// Compute the hmac on input data bytes
byte[] rawHmac = mac.doFinal(getStringFromMap(nvps)
.getBytes());
// Convert raw bytes to Hex
byte[] hexBytes = new Hex().encode(rawHmac);
// Covert array of Hex bytes to a String
return new String(hexBytes, StandardCharsets.UTF_8);
} catch (Exception e) {
}
}
要避免
标准字符集
使用
public static String sha1(Map<String,String> nvps) {
try {
// Get an hmac_sha1 key from the raw key bytes
byte[] keyBytes = AppProperties.VERIFICATION_KEY
.getBytes();
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1");
// Get an hmac_sha1 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
// Compute the hmac on input data bytes
byte[] rawHmac = mac.doFinal(getStringFromMap(nvps)
.getBytes());
// Convert raw bytes to Hex
byte[] hexBytes = new Hex().encode(rawHmac);
// Covert array of Hex bytes to a String
return new String(hexBytes, StandardCharsets.UTF_8);
} catch (Exception e) {
}
}