Search code examples
android-4.0-ice-cream-sandwichandroid-2.3-gingerbread

How to compile projects from 2.3 to 4.0?


Recently, I was asked to compile some of my Android projects, based on the 2.3, for the new 4.0 versions. So without much knowledge on how to do it, I simply tried to do it myself by making a few changes in the manifest file like the min SDK and targeted SDK. I set the min SDK to 10 and targeted SDK to 15. Hoping that would somehow work, I test run my codes only to see that it doesn't work out the way I hope. Of course, it works really well on the 2.3, both on simulator and device.

Is there a way to upgrade / convert this project to compile and build with the latest version other that redoing it? Can anyone help?

EDIT 1: After hours of troubleshooting, and searching for online clues. I decided to look this a little more deeper. I found out that this line:

DefaultHttpClient client = new MyHttpClient(getApplicationContext());
HttpGet get = new HttpGet(url11);
HttpResponse getResponse = client.execute(get); // 4.0.3 crashes here.... 

Was the cause of the problem. Now I ran the AVD Manager from 2.3.3 and 4.0.3 to test out this problem , and it turns out that this line runs smoothly with no errors on the 2.3.3. Could there be a deprecation or something in the new 4.0.3?


Solution

  • Most probably it's caused by performing network operations on main thread.

    It causes NetworkOnMainThreadException when the targetSdkVersion is 11 or higher on AndroidManifest.xml.

    Move it to the background thread using AsyncTask or AsyncTaskLoader.