Android creates its own dependent library, uploads it to Gitee and publishes it to JitPack to provide references

Android creates its own dependent library, uploads it to Gitee and publishes it to JitPack to provide references

illustrate

In many projects, the codes of the communication modules used are the same. In order to avoid excessive CV operations of the code and reduce the bloat of the code; if a project is modified, all projects need to be updated, and it is easy to forget to modify. In order to facilitate the modification and update of this module, and to facilitate the use in different projects, the same communication module in different projects is made into a separate library. Use the following two ways to quote:

  • Method 1 :
  1. Copy the entire module folder to the root directory of the project;
  2. Add a reference to the module in the settings.gradle of the project.
      Change from include ':app' to include ':app', ':xxxx'
  3. Add a reference to the library module in the main module (Module: app) of the project. After
      the implementation project (path: ':xxxx')
      is configured, gradle synchronize can be used.
  • Method 2 :
  1. Upload the module project to gitee;
  2. Release the release version;
  3. Added to JitPack.

gitee generate private token

We use JitPack to quickly publish gitee projects. JitPack needs to obtain the authorization of Code Cloud to publish projects on Code Cloud.

Enter the personal settings page of the gitee homepage, select private tokens ,
insert image description here

Click Generate New Token .
insert image description here
Reminder: Save your own private token. After the page is closed, the private token will no longer be displayed. Be sure to keep it properly.

Set up JitPack

Log in to JitPck with your GitHub account , and select the Settings menu option after logging in.
insert image description here
Set up a private token:
insert image description here

Create a dependency library locally

Create a new Android project, create a new module in the created Android project, select Android Library as the project type, and copy the communication module code into the module.

  1. You need to set the build.gradle file of the project. Note that this is not the gradle file of the module or the gradle file of the app. Add the maven packaging plug-in:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    
    repositories {
    
    
        google()
        jcenter()
        maven {
    
     url 'https://jitpack.io' }
    }
    dependencies {
    
    
        classpath 'com.android.tools.build:gradle:3.5.3'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // 1.自动化maven打包插件
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
    }
}

allprojects {
    
    
    repositories {
    
    
        google()
        jcenter()
        maven {
    
     url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    
    
    delete rootProject.buildDir
}
  1. Add the following code to the module's build.gradle file:
apply plugin: 'com.android.library'
// 添加如下代码
apply plugin: 'com.github.dcendents.android-maven'
group='com.gitee.xxxx'    // com.gitee.你的gitee用户名
  1. Upload project code to gitee.
  2. Create a release distribution.

Publish project to JitPack

Fill in the address of the project into the input box on the home page, and click the Look Up button to publish it automatically. After the project code is uploaded to Gitee to create the release version, it will take a while to display the version after clicking the Look Up button of JitPack, because JitPack needs to obtain the release code zip file from Gitee, and then decompress and compile it, so please be patient Wait tens of seconds.
insert image description here
Click the setting button, if it is in the locked state, the remote cannot be used and accessed, you need to click to unlock, if it is in the 2 state, you can access it remotely.
insert image description here

Click Git it , and then you will see the familiar guidance for adding dependencies. Copy the instructions for adding dependencies from Gradle and Maven to the readme file README.md of the library project on Gittee, and tell others how to use your library.
insert image description here
Reference the dependent library in the project.

Reference:
https://blog.csdn.net/u012800952/article/details/108630037
https://blog.csdn.net/xiaozhude/article/details/109127865
https://blog.csdn.net/android157/article/ details/88912676
https://blog.csdn.net/beibaokongming/article/details/88967646
https://www.freesion.com/article/9683108322/

Guess you like

Origin blog.csdn.net/tracydragonlxy/article/details/119538916