Hello,

When I tried to use sdktool to download packages for offline usage my app was crashed with this error:
Code:
java.lang.RuntimeException: WifiLock under-locked my_lock
            at android.net.wifi.WifiManager$WifiLock.release(WifiManager.java:2147)
            at com.skobbler.ngx.sdktools.download.SKToolsDownloadPerformer.releaseResourcesWhenDownloadThreadFinishes(SKToolsDownloadPerformer.java:488)
            at com.skobbler.ngx.sdktools.download.SKToolsDownloadPerformer.run(SKToolsDownloadPerformer.java:347)
I found already this issue here http://stackoverflow.com/questions/2...locked-my-lock and I solved this problem for me.

But I suppose sdktool code has this bug, so I want to share it with you.

In SKToolsDownloadPerformer class WifiLock is created but never acquired.
Code:
if ((downloadListener != null) && (downloadListener instanceof Activity)) {
   WifiManager wifimanager = (WifiManager) ((Activity) downloadListener).getSystemService(Context.WIFI_SERVICE);
   wifiLock = wifimanager.createWifiLock("my_lock");
}
So release() method throws an exception here:
Code:
private void releaseResourcesWhenDownloadThreadFinishes() {
   // release the WI-FI lock
   if (wifiLock != null) {
      wifiLock.release();
   }
The solution is to check isHeld() before do any release(), or to add acquire() right after creating the lock (or both).

Code:
if ((downloadListener != null) && (downloadListener instanceof Activity)) {
   WifiManager wifimanager = (WifiManager) ((Activity) downloadListener).getSystemService(Context.WIFI_SERVICE);
   wifiLock = wifimanager.createWifiLock("my_lock");
   wifiLock.acquire();
}
Code:
private void releaseResourcesWhenDownloadThreadFinishes() {
   // release the WI-FI lock
   if (wifiLock != null) {
      if(wifiLock.isHeld()) {
         wifiLock.release();
      }
   }
P.S. And don't forget to add
HTML Code:
<uses-permission android:name="android.permission.WAKE_LOCK" />
in your Manifest.

Maxim.