One of the checks you should make before creating your apk file for testing or uploading to an Android-based app store is the Run Lint command in Eclipse. This is found when you right-click on your project name in the Project Explorer, and select Android Tools > Run Lint…
The Lint Warnings view will show various performance, correctness, security, and other Android-environment-specific problems that may give rise to your app not loading or working in your device. (You would not use Lint to check for the validity of your HTML; you would use Validate for that.)
Here are the issues that arise again and again, some new and some old, when building a PhoneGap project and checking them with Run Lint. I put them here so I can take care of the issues right away instead of figuring them out over and over.
1. Launcher icons should not fill every pixel of their square region; see the design guide for details.
Fix: According the the design guidelines (http://developer.android.com/design/style/iconography.html), when you make an icon png, the outline should be irregular, as though following a shape within a square, such as an open book silhouette. What’s outside the icon shape up to the edge of the square should be transparent. Since you’ll have the app name under the icon, there’s no need to add text to the icon. Replace your icons with these guidelines in view.
2. <uses-sdk> tag appears after <application> tag.
Fix: Open AndroidManifest.xml. Move this line …
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17"/>
… to underneath the last “<uses-permission” line higher up.
3. Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one.
Fix: Open AndroidManifest.xml. You will remove android:debuggable=”true” Change this…
… to this …
4. Found bitmap drawable res/drawable/ic_launcher.png in densityless folder.
Fix: Open res/drawable and delete the icon there.
5. [I18N] Hardcoded string “Hello World, your-app-name-here”, should use @string resource.
Fix: Open main.xml and change …
android:text="Hello World, your-app-name"
… to …
(Note that you do not put your app name in place of “app_name” above, but type it exactly as literally written here.)
6. The resource R.xml.config appears to be unused.
Tentative fix: I suspect we need only open res/xml and delete config.xml. Waiting for confirmation from PG support. Harmless if left as is.
7. The resource R.layout.main appears to be unused.
Tentative fix: I suspect we need only open res/Layout and delete main.xml. Waiting for confirmation from PG support. Harmless if left as is.
8. Should explicitly set android:allowBackup to true or false (it’s true by default, and that can have some security implications for the application’s data).
Fix: Open AndroidManifest.xml and add the following after the <application line:
Read more about whether to set to true or false here: http://developer.android.com/reference/android/R.attr.html#allowBackup
9. The <activity> element must be a direct child of the <application> element.
Fix: This one is difficult to describe because each AndroidManifest will be different. But following is a working, no-error version of my latest manifest. Watch the placement of closing angle brackets. Put the starting and closing <activity> tags above and below the <intent> tags. These are the last lines of my AndroidManifest.xml file:
<application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name="my-app-name-is-here" android:hardwareAccelerated="true" android:allowBackup="true" android:theme="@android:style/Theme.Black.NoTitleBar" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
10. Random inexplicable errors.
Now and then I find errors that halt my app and no amount of searching helps. Before too many days go by, first restart Eclipse to see if that resolves everything, and if not, then create a new project from scratch using the existing PhoneGap files. I have saved potentially days of work by just renaming the old project and creating a new one in its place — error free!