Nishant Srivastava
Nishant is a Software Engineer/Founding Team Member (at) OmniLabs, Inc. with 4+ years of experience in Android SDK Engineering and DSP(Audio). He is the Lead Organizer (at) Google Developer Group, New Delhi.
Developing Libraries
Nishant Srivastava
Android Dev/Interaction Designer
Organizer@GDG New Delhi
WHAT ?
WHY ?
HOW ?
To answer the below with respect to Android Libraries
A software library generally consists of pre-written code, classes, procedures, scripts, configuration data and more.
It is designed to assist both the programmer and the programming language compiler in building and executing software.
..hence they reuse code.
..because
..and best of em all being ...
Make people happy..
.. OK , I guess BATMAN doesn't smile anyways.. :P
1.UI
2.Looper/Handler
3.Resources
4.Native Code
..and many more...
Emerge from Build Hell today through Gradle, the modern open source polyglot build automation system..
Fire up your Android Studio and Create a New Project
Create a new module
Go on..
We are going to stick to making an AAR module.
Once selected, my suggestion is to rename
.....and build your awesome library...
void init(ApiSecret apisecret);
void init(String apikey, int refresh, long interval, String type);
public boolean hasPermission(Context context, String permission) {
int result = context.checkCallingOrSelfPermission(permission);
return result == PackageManager.PERMISSION_GRANTED;
}
Minimize Permissions
String feature = PackageManager.FEATURE_BLUETOOTH;
public boolean isFeatureAvailable(Context context, String feature) {
return context.getPackageManager().hasSystemFeature(feature);
}
Minimize Requisites
public boolean isMarshmallow(){
return Build.VERSION.SDK_INT>= Build.VERSION_CODES.M;
}
Support different versions
Make your code Testable
// In code
boolean debuggable = false;
MyAwesomeLibrary.init(debuggable);
// In build.gradle
debuggable = true
Donot log in production
Do not crash silently - Log all exceptions and print them in the logcat
Handle poor network conditions
Reluctance to include large libraries
dependencies {
provided 'com.squareup.okhttp3:okhttp:3.1.2'
}
Donot require libraries
Check in classpath
private boolean hasOKHttpOnClasspath() {
try {
Class.forName("ccom.squareup.okhttp3.OkHttpClient");
return true;
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return false;
}
Simple - Briefly and Clearly expressed
Purposeful - Having or showing resolve
OpenSource - Universal Access, Free license
Idiomatic - Natural to the native environment
Logical - Clear, Sound Reasoning
$ ./gradle build
or
$ ./gradlew build
http://developer.android.com/tools/testing/testing_android.html
$ gradle clean connectedCheck
Readme.md
JavaDocs
Example Apps
Maven Central / Jcenter
Local/Remote Maven Repositories
Local AAR
....So you have built you awesome library, huh !
So the only thing left now is understanding how to use it in another project, right...
If you are not familiar with the way you include a dependency/library in your project via using gradle then here it is :
dependencies {
compile 'com.company.library:myawesomelibrary:23.1.1'
}
Me after this session..literally :P
By Nishant Srivastava
Learn about android libraries and how to build one for yourself.
Nishant is a Software Engineer/Founding Team Member (at) OmniLabs, Inc. with 4+ years of experience in Android SDK Engineering and DSP(Audio). He is the Lead Organizer (at) Google Developer Group, New Delhi.