For efficient development of high performance code, you should set up different build profiles for debugging and releasing in your Integrated Development Environment. In NetBeans, you can do this in the following way:
Right click the project and select Properties > Manage Configurations > Add.
Your “Release” or similar-named configuration should include the following performance optimisations:
Check Compile with optimisation to tell javac to improve the code for speed.
Clear the checkbox Generate Debugging Information.
Turn ProGuard ON.
Set the debug block level to Error.
Include similarly optimised and compiled versions of any libraries you use.
In Sources Filtering option, check Exclude Test Sources to remove unit tests from your production build.
You can also include a different image and sound directory in each profile. Depending on your needs and preferences, you may want to generate localised JAR files, or different JAR files for different screen sizes. When you run “Batch Clean and Build”, all profiles for your project will be built at once.
Note that you should not use profiles to build multiple JAR files for older vs. newer phones if the bundles’ images and sounds are the same. Instead, you can use selective enhancement to add newer phone features which are turned on at runtime, since this reduces your code and release fragmentation at almost no performance penalty. For more information and a demo, see Episode 16: Orientation and One Build for Multiple Phones.