Android programming to solve the android-support-v4 packaging problem

If the project introduces the jar class library of android-support-v4, an error message will appear when the project is packaged and confused. For example, you may need to specify additional library jars (using '-libraryjars').

The solution is given here, and later we will explain how to deal with similar situations:

at the end of proguard.cfg, add the following:

[java]  view plain copy  
 
  1. -libraryjars /android-support-v4.jar  
  2. -dontwarn android.support.v4.**  
  3. -keep class android.support.v4.** { *; }  
  4. -keep publicclass * extends android.support.v4.**   
  5. -keep publicclass * extends android.app.Fragment   


Then you pack it again, and the apk installation package should be generated normally.


Packaging error:
Case 1:
 "Class 1 can't find referenced class class 2" literally means that class 1 cannot find a reference to class 2; it will suggest you: "You may need to specify additional library jars (using ' -libraryjars')."; You
need to use -libraryjars plus the third-party library used in the project.
For example: -libraryjars /android-support-v4.jar
Note: The reference method here is the root directory of the current project (other directories can also be configured), that is, you must put the third-party jar in the current directory, otherwise it will be Warning says jar file not found!

Case 2:
For example: can't find superclass or interface android.os.Parcelable$ClassLoaderCreator, in this case, you can use -dontwarn com.xx.yy.** without warning about errors.
Note: If you use this method, make sure you don't use the classes in this library! Otherwise ClassNotFoundException will be thrown!

Case 3:
This class is indeed used in the project, but the above method is still not enough. At this time, we need to add another item: -keep class com.xx.yy.** { *;}, so that the current class is not confused.

Summary:
For the case of referencing third-party packages, you can use the following methods to avoid packaging errors:
-libraryjars /aaa.jar
-dontwarn com.xx.yy.
-keep class com.xx.yy.** { *;}

Finally, the package is successful, and you have to run it on the machine to see if there is any problem.

Guess you like

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