An exception occurred when running the program after Android obfuscation: Missing type parameter

Source: Internet
Author: User

Obfuscation of programs, package and release the apk, and then test the apk with a real machine. It is found that all pages with network requests cannot display data and view logs, the following exceptions are found:


<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + zfjJz7Lpwcuy6Q = "Missing type parameter" what is the cause of this problem? You can see that this answer is because gson's new typeToken is used in the program. It should be because the classes related to typetoken are obfuscated in the obfuscation file, which makes the runtime program unrecognizable. View

At com a. a. c. a. a (Unknown Source) is a obfuscated and unrecognized class. For the sake of proof, the mapping.txt file generated after the download is used to find out which class of com a. a. c. a corresponds to the program class, such:



It can be determined that it is directed to com. google. gson. reflect. TypeToken


Then add this sentence to the example file proguard-android.txt (the txt I used on Android Studio0.3.7 obfuscated the program, and many previous projects were included in proguard. cfg:

-Keep class com. google. gson. ** {*;} indicates that the proguard operation is not performed on this class.


There are also many solutions available on the Internet, such as the following two

Android obfuscation compilation-problem summary and proguard Missing type parameter on stackoverflow

Add in proguard. cfg

-Dontobfuscate
-Dontoptimize

Or add:

# Gson uses generic type information stored in a class file when working with fields. Proguard# removes such information by default, so configure it to keep all of it.-keepattributes Signature# Gson specific classes-keep class sun.misc.Unsafe { *; }#-keep class com.google.gson.stream.** { *; }# Application classes that will be serialized/deserialized over Gson-keep class com.google.gson.examples.android.model.** { *; }

However, after this configuration, the same error still occurs after the apk is packaged and released, and the problem is not solved.


After the tangle, think about the problem. Since the problem lies in obfuscation of classes that should not be obfuscated and network data retrieval, an error is reported, the problem caused by TypeToken class obfuscation has been ruled out (-keep class com. google. gson. ** {*;} also encountered the Missing Type patamerer problem.) The program encountered a obfuscated class before it was executed to TypeToken, view the code in the program for Obtaining Network Data and converting the json format, and find:

The classes under org.jsonare used in the obtained interface data, but the class is not retained in proguard-android.txt.

Add the following to proguard-android.txt:

-Keep classorg. json .**{*;}

Package and release the apk again. The operation is normal and the problem is solved!




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.