ADB Server is Out of Date – Eclipse Error
This morning I was unable to install/launch an android app from Eclipse to my test android tablet. I suspected it may have something to do with my having rooted an Android tablet the previous working day – but I can’t find a causal link to that effect.
Anyway, I either repaired the issue or found a work-around – either way I’m up again. Time will tell if this has been resolved… so here’s what I did:
I discovered online that HTC-Sync seems to cause this, and I *do* have an HTC EVO 4G test phone so I opened Task manager and killed the HTC Sync process (To be honest, this has never been an issue previously. I suspect that this step was unnecessary.)
- Next I ran adb kill-server via the command prompt
- I then restarted the server by issuing adb start-server
- Eclipse didn’t like the above two steps so I restarted Eclipse
- … and things seem to be ok atm
I’ll update this post if this continues to happen, else if this is the last sentence here then the problem for me has disappeared…
The solution I found was to physically remove the phonegap js file from the project directory, right click the project root in the File Explorer and hit F5 or right-click and choose “Refresh”. The error should disappear. Add the js back to where it was and refresh the Project Explorer again. Problem solved, my app is now running!
Losing Device Connection in Eclipse
There may come a time where you will encounter an “AdbCommandRejectedException error: device not found” while trying to upload your app to your device from within Eclipse. This message will appear in the console and will be accompanied by this text: “Error during Sync: An established connection was aborted by the software in your host machine”. As a result you will be unable to install your app. Opening DDMS will show that the device is not connected to your computer a it simply doesn’t appear in the device list even though the phone is in fact physically connected.
To further illustrate:
To resolve this without restarting Eclipse you can execute a BAT file that will restart the ADB server. To do this navigate to your Android installation folder and locate the “platform-tools” folder. Within that folder create an appropriately named BAT file, for example, “restart-adb.bat”. Edit the newly created file in a text editor such as Notepad and add the following two lines:
adb kill-server && adb start-server
Save and close. TO restart ADB simply double-click your bat file and the server will be restarted. A command prompt will appear informing you of what is happening:
Thats it, the ADB has been restarted.
Solving “The connection to the server was unsuccessful” Error in Android/PhoneGap
At some point in time you will always have to update your dev environment – and inevitably when doing so you will find that you can’t compile your apps any more for any sort of a number of reasons – doesn’t matter if its iOS or Android (though I find its much, much more common on iOS). Well, today I’ve updated my Android SDK since I’d like for the first time ever to be able to use the AVD as Google has improved performance in that area. However, upon compiling one of my apps I have run into this error:
04-10 10:46:13.672: I/System.out(4057): onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful. URL=file:///android_asset/www/index.html
This can be solved by adding a line to your main activity.java file:
The timeout value itself is arbitrary, here I have it at 7 seconds. Adding this one line above the super.loadUrl resolves the “Connection to the server was unsuccessful” error.
Changing Target Android Version in Eclipse
This one takes care of the “Attribute minSdkVersion(x) is lower that the project target API level(x)” error that you may encounter if attmpeting to change your app’s Android target version after having setup your Eclipse project for Phonegap. The error manifests itself as a build error with this the following description (which illustrates a target of 8 being below the projects API level of 10):
To change the target Android API level you need to do two things:
- Update the Android Manifest
- Update the App Target API Level
See this page for more information on Build Targets and
acceptable values: Android API Level Guide.
First go to your project folder in Eclipse. In the root you should find a file called “AndroidManifest.xml“. Double-click this file. Eclipse will either show you the UI view of the XML document, which looks like this:
Or Eclipse may show you the manifest in source view which would look like this:
In the UI view of the manifest you are looking for the “Min SDK version” filed – set that to the desired SDK version that you want to target. Save the change and then close the manifest. If you cannot locate the Min SDK Version then look under “Manifest Extras” and click on “Uses SDK” – the desired field will appear to the right under the “Attributes for Uses SDK” heading.
If you see the source-code view for the manifest then look for this line:
… and simply change the number (“8” in the above example) to whichever target API Level that you’re going for.
Next, you need to change the Project Build Target. To do so you will locate the root of your project within the Project Explorer (this appears as a directory tree structure), right click the app project root and select “Properties“. You will see the properties panel which looks like this:
At this point simply select the proper build target, apply and close.