Jeff Friesen JavaJeff
BOOK: Effective Java by Joshua Bloch
BOOK:
Java Performance Tuning
by Jack Shirazi
ARTICLE:
Java Best Practices –
String performance and
Exact String Matching
AnDevCon March 2011:
Android for Java Developers 1,
2,
3,
4 (missing an hour).
This is to create a folder path which doesn't have spaces, to avoid issues by Java utilities such as Eclipse.
TIP: Put this at the front of the PATH for slightly faster performance.
The expected reply looks something like this:
java version "1.6.0_31" Java(TM) SE Runtime Environment (build 1.6.0_31-b05) Java HotSpot(TM) 64-bit Server VM (build 20.6-b11, mixed mode)
The alternative is to install in program files but reference it using short names such as PROGRA~1 or PROGRA~2.
This is to avoid issues by Java utilities such as
TOOL:
ProGuard code obscusator.
You can specify %USERPROFILE% for the location Windows creates for the current user logged in:
C:\users\myusername
TIP:
I like to keep all Android-related files (installers, tutorials, software, etc.)
together under a single folder so I can move them without forgetting about files in my personal folder.
Since no one else uses my files, I specify:
C:/ref/Android/.android
TIP:
Download all source files.
During Android development it is often useful to have the Android source code available to see undocumented defaults.
EXCLUSIVE: Example Source
Expanded,
v13 contains 46,790 files in 6,666 folders taking 1.8 GB.
v15 contains 45,797 files in 7,185 folders taking 2.58 GB.
If you prefer using the Eclipse plug-in version rather than the full gui, from Eclipse's Help menu, select Install New Software for the Available Software dialog. Click Add (to the right of the Work with field) for the Add Site dialog. download the zip file (Archive) or https://studio-android.motodevupdate.com/android/3.0
After Eclipse restarts, MOTODEV should appear in the menu bar.
Read their Release Notes fully for known issues.
TEST: To scan apps for compatibility with Motorola smartphones and tablets,
from Windows Explorer drag and drop apk files to Windows desktop program
TOOL:
MotoDev App Validator, whose SDK enable it to be customized.
TOOL: JetBrains IntelliJ IDEA Community Edition (Be sure to include Android option when installing)
Oracle Sun NetBeans
Oracle JDeveloper
I have not messed with
Getting Started Using Eclipse
is thorough and sequenced well.
A great tutorial.
Top 10 Tips for New Eclipse Users
Eclipse version names:
3.8.x (Juno)
3.7.x (Indigo)
3.6.x (Helios)
3.5.x (Galileo)
3.4.x (Ganymede)
3.3.x (Europa)
3.2.x (Callisto)
In the zip file like eclipse-jee-juno-win32.zip is an eclipse folder.
TIP: Some expand this folder within folder C:\bin because Eclipse is not a Windows program.
REMINDER: The default workspace on Windows is C:\Users\%USERNAME%\workspace
TIP: I prefer to keep all files together in folder C:\ref\Android\workspace.
The first time in Eclipse Help > Install New Software > Work with: https://dl-ssl.google.com/android/eclipse/ to Add repository named Android. Select all the Developer Tools DDMS (Dalvik Debug Monitor Server) perspective, Development Tools, Hierarchy Viewer, Traceview. Accept the license and unsigned warning. Restart Eclipse.
Once installed, obtain updates in Help > Update.
Google API Add-ons for Google Maps and Google Cloud to Device Messaging (C2DM) framework for servers in the cloud to send send small amouts of data to devices.
Google has a policy of not releasing source for the newest version until it's "ready".
Plugins to access Android Source code maintained by
Haris Peco at
http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update
and
http://adt-addons.googlecode.com/svn/trunk/binedit/com.android.ide.eclipse.binedit.update
ADT 16.0.0 was written for installation on Eclipse Helios (Version 3.6) or higher
for use with SDK Tools r16, which added
Lint static analysis tool which looks for bugs (common errors) in Android project Java code.
A). If you want to:
Do the following:
http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/
B). If you want to search within source code:
http://repository.grepcode.com/java/ext-eclipse/
Java Decompiler
C). If you want to run a
Java Decompiler (from class files in a jar):
http://java.decompiler.free.fr/jd-eclipse/update
TIP: In the workspace folder, create a Windows shortcut to invoke Eclipse so that it is started with additional parameters. As with all Sun JVMs, by default only 384 MB is allocated and 64 MB to perm. With additional plug-ins, this may not be enough. So to ensure enough memory I right-click the shortcut for the Properties windows to add these settings :
To prevent java compile errors while resolving import of java.util.TimeZone and other such libraries, the -vm argument defines use of the JDK's JRE rather than the one that comes with Eclipse. Alternately, in Eclipse Window > Preferences -> Java -> Installed JREs > Add... > Standard VM > Next Select "Standard VM", Directory, Add JRE > where the JDK is installed on your system. Other fields will be populated for you after you locate the home directory. Finish. OK. Set the JRE associated with the JDK as the default by checking its box.
In Eclipse menu File > New > Other > Android > Android Project.
The projec type "Android Project" was added when (Application Development Tookit) for Eclipse was installed
In the Name field, packages use revserse notation in the format com.company.product.package.
Specify a project name such as "HelloWorld" and select a Android version Target name such as Android 1.6.
An alternative is to open a Windows Run command window and invoke an android.bat command such as:
android create project –t 1 –p HelloWorld –k org.test –a HelloWorld
Arguments:
BLAH:
Unlike files such as *.doc and *.xls which when clicked invokes the appropriate program,
Eclipse files are not recognized by Windows.
BLAH: Eclipse Window > Show View > Navigator only displays folders which contain a .project file in the root (same folder as the AndroidManifest.xml file).
WARNING:
Do not open individual files in Eclipse.
First get projects to display in the Navigator, then files within projects will appear.
The "Open project" option in Eclipse is for opening a project still visible in the project explorer area
but has been closed by Eclipse. This is confusing to Windows users.
WARNING: To avoid error messages, do not manually copy sample Android project code folders into your Eclipse workspace folder.
1. In Windows Explorer, navigate into the source folder (so you see its AndroidManifest.xml), such as
5. If not already active, invoke Eclipse.
6a. If a .project folder DOES NOT have a .project file already:
6b. If a .project folder HAS a .project file already:
WARNING: Watch for errors in the Console and red icons in the Navigator window.
It is very common to see Console message such as:
These messages occur because there common agreement Android API level among different files:
WARNING: When changing API version, some programming changes in the application source may be necessary.
If there are red icons to the side of the project name, determine the target
With the project selected, select from the grey menu bar Project > Properties.
The Java Build Path should show the Android version selected earlier and
com.android.ide.eclipse.adt.LIBRARIES.
WARNING: Do not check "is Library" or you'll get this message when you try to run:
If there is an AndroidManifest.out.xml, right-click on it and select Delete.
This was created if Run was selected when the AndroidManifest.xml was on the right pane (an Eclipse bug).
Remember to clear off all xml files before attempting a Run.
Different directories separate files of different format and function.
Files in directory assets are accessed via the AssetsManager GUI and method getAssets().
In the bin folder is the yourActivity.apk file compiled for installation onto devices. Debug versions yourapp-debug-aligned.apk files were optimized with the zipalign utility to make it run faster.
/bin/yourapp.ap_ contains resources packaged in zip format. These files are compiled from source files in the src and folder. The .dex file in the .apk file is also in the folder.
Source files make reference resource names in the R.java file within the gen folder path for the app. This file is automatically generated based on real files physically stored within the res folder.
Each resource created in the "res" folder are automatically defined in "R.java" (within the gen folder) to access it.
OpenIntents Google Group
OpenIntents Downloads
OpenIntents Screencasts
Setup on Linux
Setup on Windows
To work with the OpenIntents library, one is forced to install SVN to download the file specified in the default.properties file specifying dependencies:
android.library.reference.1=../../distribution/DistributionLibrary/ # Project target. target=android-8
Based on the above, be sure to download and expand the distribution library, then target Andoid API 8.
Getting Started with OI in Eclipse says that SVN is used for downloading the entire WEBSITE: Android OpenIntents library
The installer should add to the end of System Environment Variable PATH the file path where svn. exe is located:
svn checkout http://openintents.googlecode.com/svn/trunk/ openintents
A lot of files should scroll by.
TIP: Downloading from the trunk ensures that library projects are included as well.
Downloading zip files requires manual work to unzip them.
OpenIntents apps. include
OI Color Picker,
Calendar Picker,
Counter,
Barcode,
Crypto,
ShoppingList,
RegistryCloud
Historify event aggregator,
Sensor Simulator, etc.
On Macs, replace Ctrl with the Apple key.
To remove Block comment, press Shift + Ctrl +.
To Toggle Comment, press Shift + Ctrl + C.
To Generate Element Comment, press Shift + Alt + J.
For definitions on something highlighted by the mouse, hold down Ctrl .
So highlight a string, use Refactor > Android > Extract Android String to replace what is highlighted with
a localizable string reference using method getString(R.string.yourString));
containing reference id "R.string.yourString" you specify.
To find a type (class definition) in Eclipse, press
Ctrl+Shift+T.
To load class by name, press
Ctrl-Shift-T.
To load non-class resource by name, press
Ctrl-Shift-R
To show inherited members (methods) and adds or removes imports in Eclipse, press
Ctrl+Shift+O.
To add Import, press Shift + Ctrl + M
To internationalize, highlight text (between quotes), press Alt+Shift+A.
To rename files such as main.xml, use Refactor > Rename
which ensures references to the name is also changed.
To refactor:rename, press Shift-Alt-R
To refactor:move, press Shift-Alt-V
Instead of default setContentView(R.layout.main),
in complex apps,
To reformat source for nesting in Eclipse, menu Source > Format or press Ctrl+Shift+F.
Notice the end tag is not on the same vertical as the opening tag.
To correct Indentation, press
Ctrl + l (for Indentation).
For quick fix, press Ctrl+1.
For recently viewed files, press Ctrl-E.
Highlight a resource name and
press Ctrl+Shift+R in Eclipse to find and open its resource definition.
If an Eclipse Project is set by default,
press Ctrl+S to save, which automatically rebuild.
The file extension Google uses for Android applications (*.apk ) is a .zip file inside.
When running the WinRAR Setup, be sure to check JAR so Windows associates the file extension with WinRar.
Unzip classes.dex to a folder like C:\ref\android\dex2jar-0.0.9.6 (among your other android files).
cd \ cd C:\ref\android\dex2jar-0.0.9.6 dex2jar.bat classes.dex
exit the command window if you see this expected response:
dex2jar version: reader-1.7, translator-0.0.9.6, ir-1.4 dex2jar classes.dex -> classes_dex2jar.jar Done.
Drill down from com or org thru the organization, package, etc. until you reach class files.
REMINDER: Classes with $ in their names are sub-classes.
To read class files, you need to de-compile them.
http://code.google.com/p/android-apktool/
In Eclipse menu File > Open a class file, and notice that it's jumbled because it is compiled output.
To de-compile class files to human-developer-readable java source code:
NOTE: An alternative is JD-Eclipse Java decompiler JD plug-in for Eclipse.
There are also Debug, Directives, Formatting, and Misc. which organize settings described in jad's readme.txt.
Go into Eclipse menu Window > Preferences > expand General > expand Editors > File Associations, click .class, click Class File Editor (default), click Default button.
WARNING: .class files can only be decompiled when inside a .jar file and that .jar file has been added to the Build Path.
TOOL: Crittercism.com
Calls to the Crittercism server are made asynchronously.
A separate APK file needs to be created for the Amazon store so that the compliments button in Amazon's feedback springboard directs to the default marketplace for the device. Thus this is neded for Amazon to approve apps.
The apk file to be uploaded to the Amazon Appstore should include this API call, while the other apk file should not.
boolean shouldUseAmazonMarket = true; Crittercism.setShouldUseAmazonMarket(shouldUseAmazonMarket);
Each apk file is built by combining its classes.dex file with associated resources.
The Android Asset Packaging Tool (aapt) creates .apk files containing binaries and resources of Android applications.
In Motodev right click project name and select Export/ Android/Export Android Application.
This building can also be done from this command line command in the project's folder:
In the package's bin folder, the package created contains an apk file for the app which is installed onto devices.
Keyboards and trackball on Blackberry phones can be recognized on tablets Bridge.
PKI ActivClient like DoD's CAC.
Packaging an APK file combines the Dalvik executable with its resources.
Using Studio for Android, select the project, default location and sign the application.
Each APK is signed.
The debug key is used during development.
Each market has its own policy about using real keys published.
The Dex compiler "dx"
If you build apps outside Eclipse, or if you want to build a release version using the ant build scripts, you need at least version 1.8 of Ant from http://ant.apache.org/bindownload.cgi
Ant to compile and build your Android project into an installable .apk file.
keytool from Android SDK tools is used to generate a keystore holding private key certificates
$ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
Private keys generated by keytool are used by Jarsigner from the JDK to sign .apk files.s