Android programming to solve the problem of android-support-v4 Packaging

Source: Internet
Author: User

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

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

Add the following content after proguard. cfg:
[Java]
-Libraryjars/android-support-v4.jar
-Dontwarn Android. Support. v4 .**
-Keep class android. Support. v4 .**{*;}
-Keep public class * extends Android. Support. v4 .**
-Keep public class * extends Android. App. Fragment

Then you can package it and check that the APK installation package can be generated normally.

Packaging error:
Scenario 1:
"Class 1 can't find referenced class Class 2" literally means Class 1 cannot find the reference of Class 2; It will suggest you: "You may need to specify additional library jars (using '-libraryjars '). ";
You need to use-libraryjars and the third-party libraries used in the project.
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 need to put the third-party jar under the current directory, otherwise, a warning is reported that the JAR file cannot be found!

Scenario 2:
For example, can't find superclass or interface Android. OS. parcelable $ classloadercreator. In this case, you can use-dontwarn com. XX. yy. ** to warn against errors.
Note: to use this method, make sure you do not use the class in this library! Otherwise, the classnotfoundexception will be thrown!

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

Summary:
To reference a third-party package, use the following method 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 on the machine to see if there are any problems.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.