purpose
In that a common wheel reusable, making the wheel to avoid duplication, thereby improving productivity.
General rules
Avoid duplication create the wheel
If you already have a similar idea of the wheel, please complete it and not reinvent the wheel, unless they have been unbearable code maintenance.
Carefully designed API
Normalization methods and class names, note the location of the multi-parameter function parameters, using obsolete API
@Deprecated
annotations.Avoiding the introduction of other libraries
Use when you need to rely on third-party libraries
compileOnly
insteadimplementation
, to avoid third-party libraries (especially support package) into which the right to choose other third-party libraries to the integrator.Try to use annotations instead of enumeration
Notes
@IntDef
,@StringDef
,@Interface
and@Retention
find out.Resource file with a special prefix
Resource file third-party libraries will merge with integrators phase, it is necessary in the unique name. The library is assumed
xxx-yyy
, then all resource files suggested adding a prefixxxx_yyy_
.Provide pluggable dependent program
The library depends on the assumed load a photo gallery, but I do not know integrators use
Picasso
orGlide
or other images to load the library, then you can usecompileOnly
them all dependent on incoming (but not aar scored the final package), then use the codeClass.forName()
(for catch exceptions) sequentially detecting whether corresponding dependency, there is use it.The variable parameters of Manifest, by
gradle.properties
controlling// build.gradle defaultConfig{ manifestPlaceholders = [ XXX_APP_KEY: "${XXX_APP_KEY}", ] } // gradle.properties #XXX XXX_APP_KEY=82d79e3cec5013
A plurality of dependencies, a polymerisation dependent
The object is to rely on the packet, so that the whole group can be introduced when required, the entire group can be deleted when no, not leaving the tail. Below
retrofit2
dependent, for example, be dependent on the packet:ext.versions=[ retrofit:'2.3.0', ] dependencies { implementation([ "com.squareup.retrofit2:retrofit:${versions.retrofit}", "com.squareup.retrofit2:converter-gson:${versions.retrofit}", "com.squareup.retrofit2:adapter-rxjava2:${versions.retrofit}" ]) }
When there are two or more dependent need to use the same version number, the extraction
ext.versions
, the above embodimentretrofit
relies, in order to maintain the release.Whether to provide no-op on demand considerations
If the library is only developed in debug mode, for example,
leakcanary
only a memory leak detection in the test, does not need to contain production feed package, it can provide a method of producing a shell, which is empty achieved.Incorporating only code debug mode
Corresponding to the library to be used only in debug mode, use the
debugImplementation
comment.Use JitPack library to do a managed warehouse
Simple, fast
Strictly limit the number of library size and method
README
Talk clearly purpose and usage要回答这几个问题: 1. 有什么用? 2. 怎样引入? 3. 基本用法是什么? 4. 支不支持自定义?
Quick fix issue, and more and questioner communication
Continuous improvement, adhere to update
Specific to our team
Use third-S3 Maven repository.
Published specification products.
groupId
Unifiedcom.<group>.android
,artifactId
unified prefix<group>-
Layout only
XML
write associated string value desired color can be extracted from all defined.Uniform Resource ID to use
artifactId
the-
alternative is_
prefixed.To the entire library project consists of two modules: one named
app
example module; the second is called thelib
library dependencies module.app
The sample module package namecom.sample.<库名>
,lib
the module package namecom.<group>.<库名>
.Uniform packaging script placed in the
lib/script
middle, and unified:#!/bin/bash SCRIPT_DIR="$(dirname "${BASH_SOURCE:-$0}")" # ROOT_DIR=`readlink "$SCRIPT_DIR/../.."` ROOT_DIR=`python -c 'import os,sys;print os.path.realpath(sys.argv[1])' "$SCRIPT_DIR/../.."` cd $ROOT_DIR # detect gradle command GRADLE=`which gradle` GRADLE="${GRADLE:-$ROOT_DIR/gradlew}" "$GRADLE" clean \ :lib:assembleRelease sleep 2s # wait the file being generated "$GRADLE" :lib:publish
Please published once each marked with the appropriate tag in the code.
If the released version 1.0.1, perform:
git tag v1.0.1 git push origin v1.0.1