The Android project uses it as a dependency

I believe that everyone has used the form of dependency to add functional code to the project. Among other things, high flexibility is affirmative. Have you ever thought about importing your own project or a certain function into the project in the form of dependency? You don’t have to copy and paste every time you write a new project or use it in other places. You can get it done with one line of code, and others can share your results.

insert image description here

The first thing to know! ! ! When uploading a project to JitPack as a dependency, your project must be able to run normally without reporting an error, otherwise JitPack will not pass the upload

When I first came into contact with the dependency, I thought it was a single function or code. In fact, this dependency is a component of a complete runnable project . We are equivalent to downloading this component to our project through the network (Gradle) , and then use the method in the component

This is the project I uploaded.
insert image description here
I want to use the method in the mybase component, but I need to upload the entire runnable project to github, then package it through github, and convert the package into a dependency for us to use through JitPack

This is the dependency package I downloaded

insert image description here
It can be seen that only the component part is reserved here, so uploading dependencies must first create a component and put the method into the component

How to create a component?

  1. New - New Module - Create a name, etc.
  2. At this time, you find, hey, isn’t it a component? How can it be a module that can run?

don't panic now

id 'com.android.library'insert image description here
The list file should also be deleted. The component should look like a component. Don’t think about making an icon or something. Of course, the new Activity still needs to be declared.
insert image description here

In this way, it becomes a small component. Create the method you want in it. When you need to use this component, just import it.

implementation project(':mybase')
insert image description here
The above are the basic conditions for creating dependencies. Write a good method in the component, reference is no problem, and it is OK to run. At this time, he has the conditions to become a dependency.

Upload the project to github, I won’t say much here, but I still want to mention that this is the first time I use github, when I first cloned the project through the git address, it was an empty folder , enter the folder to create a new file, SourceTree does not sense the file, then run git add . in the folder.

back to normal

After entering github

insert image description here
Create a release file,
insert image description here
insert image description here
just do the above two steps, then open JitPack and put your warehouse name in it

insert image description here
insert image description here
It is only successful when it is green, and nothing else will work. If it is unsuccessful, you can go to the log log, or think about whether there is any problem with the project itself.

Click the small green button
insert image description here
and the version number will appear below, that's it, follow this requirement to reference it in the project!

おすすめ

転載: blog.csdn.net/As_thin/article/details/123800580