Explore how to use RecyclerView as a jar package import

 Explore how to use RecyclerView as a jar package import

 

      Since the project requires the use of RecyclerView, but the Android system used has been castrated by the company, we can only build our project based on API15. After many investigations, it is found that the current use of RecyclerView is directly in the build.gradle file Configured jar information, and then AS will automatically download the corresponding jar package.

 

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:recyclerview-v7:22.1.1'
    compile 'com.android.support:appcompat-v7:22.1.1'
}

 This method is simpler to use, but has many disadvantages:

 

  (1) Downloading the corresponding jar is very slow, and the jailbreak speed will be faster

  (2) It is very troublesome to download the corresponding jar every time you use it

  (3) Must be built with API > 21SDK version to use

     Our project can only use API15, which is a pain in the ass. . . Knowing the powerful functions of RecyclerView, I can only watch others use it.

     Is there any way to directly import the jar of RecyclerView in the project to run in an environment lower than API15?

I haven't found one that can be successful on Baidu. Even if the version built successfully is at least API >= 21, after many times of climbing the pit,

Finally succeeded, share it with you below.

(1) First download the support package with SDKManager (v7 and v4 packages are required to use RecyclerView)

Download the support package

 

(2) Then you will find the RecyclerView file under \sdk\extras\android\support\V7, which contains the recyclerView jar package and some resource files.

Many people will naturally put android-support-v7-recyclerview.jar under libs in a newly created project, thinking that RecyclerView can be used in this way, but after many attempts, they all failed.

Looking at the source code, the reasons for the failure are:

(1) recyclerView introduces the classes in support V4, and naturally the V4 package must be imported (it's not enough to go to this step)

(2) The R.Styleable class is introduced into the recyclerView. Isn't this the class generated by the custom attribute XML resource? The stupid google didn't help us to automatically load these resources into the jar package. At this time, I finally understood why importing the jar package is not enough. Maybe import the resource files under the RecyclerView folder above, generate the corresponding resource classes, and then Import the main project in the form of a lib library, maybe it will be successful.

 

In order to verify my guess, I created a new RecyclerView lib library, imported the corresponding jar and resource files, and used API15 to build the project. Sure enough, the project ran successfully. ( Note: The package name of the lib library must be android.support.v7.recyclerview to ensure that the generated class is android.support.v7.recyclerview.R.styleable )

 

Summary: recylcerView cannot be imported into the project in the form of a jar alone, because a custom attribute class is introduced into the RecyclerView source code, so it needs to rely on the main project in the form of the model lib library to run successfully.

 

The classmates who need the demo keep me private. I’m a fool. I have failed to upload three times~!

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326879072&siteId=291194637
Recommended