The development of a general and specific rules team of third-party libraries

purpose

In that a common wheel reusable, making the wheel to avoid duplication, thereby improving productivity.

General rules

  1. 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.

  2. Carefully designed API

    Normalization methods and class names, note the location of the multi-parameter function parameters, using obsolete API @Deprecatedannotations.

  3. Avoiding the introduction of other libraries

    Use when you need to rely on third-party libraries compileOnlyinstead implementation, to avoid third-party libraries (especially support package) into which the right to choose other third-party libraries to the integrator.

  4. Try to use annotations instead of enumeration

    Notes @IntDef, @StringDef, @Interfaceand @Retentionfind out.

  5. 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 prefix xxx_yyy_.

  6. Provide pluggable dependent program

    The library depends on the assumed load a photo gallery, but I do not know integrators use Picassoor Glideor other images to load the library, then you can use compileOnlythem all dependent on incoming (but not aar scored the final package), then use the code Class.forName()(for catch exceptions) sequentially detecting whether corresponding dependency, there is use it.

  7. The variable parameters of Manifest, by gradle.propertiescontrolling

    // build.gradle
    defaultConfig{
        manifestPlaceholders = [
         XXX_APP_KEY: "${XXX_APP_KEY}",
     ]
    }
    
    // gradle.properties
    #XXX
    XXX_APP_KEY=82d79e3cec5013
  8. 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 retrofit2dependent, 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}"
        ])
    }
  9. When there are two or more dependent need to use the same version number, the extraction ext.versions, the above embodiment retrofitrelies, in order to maintain the release.

  10. Whether to provide no-op on demand considerations

    If the library is only developed in debug mode, for example, leakcanaryonly 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.

  11. Incorporating only code debug mode

    Corresponding to the library to be used only in debug mode, use the debugImplementationcomment.

  12. Use JitPack library to do a managed warehouse

    Simple, fast

  13. Strictly limit the number of library size and method

  14. README Talk clearly purpose and usage

    要回答这几个问题:
    1. 有什么用?
    2. 怎样引入?
    3. 基本用法是什么?
    4. 支不支持自定义?
  15. Quick fix issue, and more and questioner communication

  16. Continuous improvement, adhere to update

Specific to our team

  1. Use third-S3 Maven repository.

  2. Published specification products.

    groupIdUnified com.<group>.android, artifactIdunified prefix<group>-

  3. Layout only XMLwrite associated string value desired color can be extracted from all defined.

  4. Uniform Resource ID to use artifactIdthe -alternative is _prefixed.

  5. To the entire library project consists of two modules: one named appexample module; the second is called the liblibrary dependencies module.

  6. appThe sample module package name com.sample.<库名>, libthe module package name com.<group>.<库名>.

  7. Uniform packaging script placed in the lib/scriptmiddle, 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
  8. 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

reference

  1. Development of third-party library of best practices - Denver

Guess you like

Origin www.cnblogs.com/lshare/p/11334143.html