1. Android develop Guideline
Index:
Getting start a project
- Environments
- IDE of Android development
- Android SDK version
- Java compiler
- Building system
- Emulator
- Coding Style
- Code Style
- Use Editorconfig
- Reformat code
- Workflow
- Scrum
- Importance of teamwork
- Mindsets
- Sharing
- References
Appendix:
Advance for a project
- Best practices
- Best resources
Training
Getting start a project
Environments
2. IDE of Android development
Android Studio
We use Android Studio as our IDE in Android team and should stay using the newest stable
version. How to Install Android studio please refer Android developer official site. Following is
Android Studio configurations:
- Please turn on `Automatically check updates for Stable Channel`
Config Lint
Android Level Lint
We should use the default Lint configuration (e.g., origami_lint_baseline.xml) in the team.
(https://developer.android.com/studio/write/lint.html)
Java Level Lint:
Since it can be config in Lint configuration that supported by Android we should config manually.
Below those configs we should enable and make it as `warning` or `error` severity.
- Since efficiency issue please turn on `Private member access between outer and inner
classes` in `Editor > Inspections` as Error severity.
4. Live Template
Consider the consistent code style and avoid human error, and it can raise efficient while
coding. We should be used to it.
For example when writing a condition of checking null object (It is not default template).
Type `ifn` then the prompt will show up.
Select it then generate the code template and you should fill up the variables.
5. Hotkeys
Consider the consistent code style and avoid human error, and it can raise efficient while
coding. We should be used to it.
For example,
Lookup the parameter hint of a method.
Press `Command (Ctrl for Windows) + P` on a method calling.
Android SDK version
Minimal SDK version: `Android 4.0.3 (Ice cream sandwich) API15` (but should higher than
dependencies).
Target SDK version: `Always last version` (i.e., Android 7.0 (Nougat) API 24 so far)
Compile SDK version: `Always last version` (i.e., Android 7.0 (Nougat) API 24 so far)
Ref:
https://medium.com/google-developers/picking-your-compilesdkversion-minsdkversion-targetsd
kversion-a098a0341ebd#.we0do6qn7
6. Java compiler
Please keep your Java Development Kit (JDK) version is latest version.
(For Android Library) You should also keep the java compatibility as following configuration:
`Source Compatibility Version: Java Version 1.7`
`Target Compatibility Version: Java Version 1.7`
(For Android Application) Recommended using `Jack`: Since there some issues between
Oracle’s Java compiler and Android Java compiler. And there is no reason Java compiler does
optimize for Android. So in the team, we courage to use a Java compiler that able to optimize
for Android and help our app to get more efficiency.
Jack toolchain:
>>> Jack is a new Android toolchain that compiles Java source into Android dex bytecode. It
replaces the previous Android toolchain, which consists of multiple tools, such as javac,
ProGuard, jarjar, and dx.
(link: https://source.android.com/source/jack.html)
How to enable Jack:
https://developer.android.com/guide/platform/j8-jack.html#configuration
```
android {
...
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
```
7. Building system
According to the default build system in Android Studio is Gradle and we need build variety of
app version for different purposes. You should use Gradle as your build system in Android
development. Please refer `Config you Build`.
Emulator
Two Android emulator.
- Official Android Emulator
- Genymotion Android Emulator - Personal Version in Free
Coding Style
Code Style
Refer to https://source.android.com/source/code-style.html
Above link that includes basic rule of coding and styling of your code. Just considering it as the
common Java coding style so we also follow the rules. Here is examples,
Comments:
```
/**
* Constructs a new String by converting the specified array of
* bytes using the platform's default character encoding.
*/
public String(byte[] bytes) {
...
}
```
Define Fields in Standard Places:
Define fields either at the top of the file or immediately before the methods that use them.
```
class Foo {
String bar;
void func() {
String fields;
}
8. }
```
Limit Variable Scope:
```
// Instantiate class cl, which represents some sort of Set
Set s = null;
try {
s = (Set) cl.newInstance();
} catch(IllegalAccessException e) {
throw new IllegalArgumentException(cl + " not accessible");
} catch(InstantiationException e) {
throw new IllegalArgumentException(cl + " not instantiable");
}
// Exercise the set
s.addAll(Arrays.asList(args));
```
```
for (int i = 0; i < n; i++) {
doSomething(i);
}
```
Use Spaces for Indentation:
We use four (`4`) space indents for blocks and never tabs. When in doubt, be consistent with
the surrounding code.
```
for (Iterator i = c.iterator(); i.hasNext(); ) {
doSomethingElse(i.next());
}
```
We use eight (`8`) space indents for line wraps, including function calls and assignments. For
example, this is correct:
```
Instrument i =
someLongExpression(that, wouldNotFit, on, one, line);
```
9. Follow Field Naming Conventions
- Non-public, non-static field names start with m. (TBD)
- Static field names start with s. (TBD)
- Other fields start with a lower case letter.
- Public static final fields (constants) are ALL_CAPS_WITH_UNDERSCORES.
```
public class MyClass {
public static final int SOME_CONSTANT = 42;
public int publicField;
private static MyClass sSingleton;
int mPackagePrivate;
private int mPrivate;
protected int mProtected;
}
```
Use Standard Brace Style
```
class MyClass {
int func() {
if (something) {
// ...
} else if (somethingElse) {
// ...
} else {
// ...
}
}
}
```
```
if (condition)
body(); // bad!
```
10. Limit Line Length
Each line of text in your code should be at most 100 characters long. While much discussion
has surrounded this rule, the decision remains that 100 characters is the maximum with the
following exceptions:
If a comment line contains an example command or a literal URL longer than 100 characters,
that line may be longer than 100 characters for ease of cut and paste.
Import lines can go over the limit because humans rarely see them (this also simplifies tool
writing).
Use TODO Comments
```
// TODO: Remove this code after the Url Table2 has been checked in.
```
Use Editorconfig
Android Studio (IntelliJ) enable Editorconfig plugin as default and it’s supported by most of
popular IDE. So we use Editorconfig as our code style configuration.
Reformat code
Keep often formatting your code with,
11. Workflow
Scrum
>>> Scrum is an iterative and incremental agile software development framework for managing
product development. It defines "a flexible, holistic product development strategy where a
development team works as a unit to reach a common goal", challenges assumptions of the
"traditional, sequential approach" to product development, and enables teams to self-organize
by encouraging physical co-location or close online collaboration of all team members, as well
as daily face-to-face communication among all team members and disciplines involved.
From Wikipedia
Basically we do each Scrum sprint in two weeks. First, to plan Sprint. Show the progress
everyday and review how the progress and determine release app or not in the second week.
For more detail please see the page.
Software engineering development flow
Design -> Implement -> Test
Importance of teamwork
Teamwork Mindsets
- Communication with members anytime
- Use project tools, i.e., Gitlab. And control the source code.
- Before changing the code, you must discuss with your member who is original author of
the code if the member still be in here.
- Keep discussing if you have not get to understand.
- Keep finding root cause of an issue or a bug. Solve problem permanently is the most
important.
- Rather found error on compile time and not happend error on runtime.
- Found crashes or bugs on develop version (as early as possible) and not release
version.
Sharing
Keep sharing in Android team. If you found any interesting post about Android or you want to
recommend any helpful article you should feel free share it to other members. Or you can
schedule a meeting to give an introduction or explanation.
12. References
- Android Studio
- Picking your SDK version
- Java SE Download
- Jack
- Enable Java 8 Features and the Jack Toolchain
- Gradle
- Android Gradle
- Config your Build
- Android Emulator
- Genymotion
- Code Style for Contributors
- Editorconfig
Advance for a project
Best practices
- Best Practices for Performance
- Best practices in Android development
- Avoiding Memory Leak (Android Memory Leak Pattern)
Best resources
- Must have libraries
- Android Drawables
- Jake Wharton’s presentations
- Awesome Android UI
- Awesome Android Libraries
Training
Official Android Developer site is always the best training sites. Followings are the must read
articles of learning developing with Android.
- Building Your First App
- Supporting Different Devices
- Managing the Activity Lifecycle
- Building a Dynamic UI with Fragments