Press enter to see results or esc to cancel.

Android APK slimming Android Studio Lint (code review)

Share this

Part I: Introduction to Android APK slimming

Android APK slimming Android Studio Lint (code review). Iteration of the new version of the project is nearing completion, because the historical accumulation of problems, resulting in a lot of ineffective resources have been bloated APK become more swollen, so the company decided to do a Android APK resources thin.

The weight-loss using the Lint review tool, with Android Studio Generate Signed APK package, thin APK before the 17.3M, 15.7M after slimming down the results for the APK reduced the size of 1.6M (9.x%)

1. Exactly the same picture, there are multiple copies of the project (a different developer from the UI resources folder copy out, modified to a different name, the introduction of the project)

2. After many iterations, many XML files are no longer used (including layout files, custom graphic files, animation files, color files, character files strings.xml, units file, etc.).

3. Due to the iterative function, some Activity, Fragment has been invalid (like Android Studio Lint can not investigate this kind of invalid resources)

 Part II: Introduction to weight-loss tools 

1. using the Android Studio tools to do code review (Inspect Code function), in fact, is used to which the Android Lint part

2. Inspect Code configuration (can be individually selected Module ‘app’ part of the individual sense library part of the review is not significant, but for the sake of convenience, I chose the Whole project .. .. But this result is that colleagues red dot keyboard computer Not Inspect … I have more than 150 invalid resources all finished … so it is still the decision whether Fire The Whole bar …)

 Part III: Android Studio Inspect Code Results Introduction 

ZzzZZZ (Inspecting …)

Android APK slimming Android Studio Lint (code review).

1. Since it is thin, that is an invaluable resource reference is the most important thing. Personally think that this part of the module in the Inpsection Android Lint view inside.

First, find Android Lint in the Inspection module

Then, in the Inspection module of Android Lint, scroll down to find Ununsed resources

To look at the unused recources expanded look (sorry, duplicate pictures, invalid xml file, invalid strings.xml and morph.xml have been processed) …

(To talk about a my own “skills” it, for the invalid xml file, to delete it is still too much trouble, because the Android Studio in the xml page does not seem to delete the button ~ ~ I do:

In the Inspect Code Android List results display area, double-click the corresponding xml invalid prompt (for example: The resource ‘R.dimen.spacing_0_5’ appears to be unused this item)

Into the corresponding xml file, delete all the contents … do not be afraid … wrong git can be restored …

Android APK slimming Android Studio Lint (code review).

When you remove the hand when the acid or fear when the Android Studio in the clean about the project [do not understand the Google search: Android Studio Clean project …]

Android Studio in the project after the traversal of all the xml file, there is no content for the xml file, Android Studio will use the red wavy line prompt, and then select all need to delete the xml file, one-time delete … recommended to bring the citation review).

Safe Deleted Reference Review

(Say something to a pit … The reason for this is this: android.content.res.Resources $ NotFoundException

Android Lint vowed to say, R.dimen.spacing_0_5 is useless (in fact his name is R.dimen.spacing_0.5 …) deleted after the preservation of values-1280 × 720 directory diemns.xml Lane R .dimen.spacing_0.5 Definition …

So it should appear in the resolution of 1280 × 720 HTC D816V perfect does not collapse and other resolution may crash … However, HTC D816V that dissatisfied, open the APP after the collapse, then together with the Android Studio prompts single program Dog: Caused by: Android.content.res.Resources $ NotFoundException: File res / drawable / common_btn_grayf10.xml from drawable resource ID # 0x7f0a0018.

Android APK slimming Android Studio Lint (code review).

I find a bit, common_btn_grayf10.xml does exist … HTC you “blind” is not !!! Or Android Studio clever, no preview in the xml preview, but prompt spacing_0.5 not in right format … So spacing_0.5 Revised to spacing_1, the error can not remember in the absence, but the program still crashes… After a long time, try to put spacing_0.5 also values ​​/ morph.xml Lane try to solve the problem.

Summary: When doing adaptation, be sure to ensure that values ​​/ dimensions.xml file is the largest and the whole. That is values ​​/ dimensions = values-aaxbb U values-ccxdd U etc … where U is discrete mathematics And set the meaning (hit me … very wordy right)


2. In fact Android Studio Inspect Code quite powerful, will help you review the invalid LinearLayout, xml layout View too much, onDraw () function in the allocation of memory efficiency of this kind of problem. Give a Code style example ( There is no silent!)

The code is so written:

Intent intent = getIntent ();

If (null! = Intent) {

GoToMainPageFlag = intent.getBooleanExtra (KEY_GO_TO_MAIN_PAGE_FLAG, false);

} Else {

GoToMainPageFlag = false;


Inspect Code Tip:

In other words, Android Studio’s Inspect Code tells you that your code is not elegant … should be replaced with sauce:

Intent intent = getIntent ();
GoToMainPageFlag = (null! = Intent && intent.getBooleanExtra (KEY_GO_TO_MAIN_PAGE_FLAG, false));
Android APK slimming Android Studio Lint (code review).

Conclusion: The six lines of code into two lines, is indeed a good Code Style practice there! Yes, Android Studio Inspect Code function I was the first time, there are too many things, large and small No matter how many things look at the long experience is also very good … although sometimes you may not be in a short time all of a sudden optimization of all options, but will have to optimize the sense of awareness in the code after the practice It will gradually close to the best practice.

How useful was this Lesson?

Click on a star to rate it!

Average rating / 5. Vote count:

Be the first to rate this post.!

As you found this post useful...

Follow us on social media!

We are sorry that this lesson was not useful for you!

Let us improve this lesson!

Tell us how we can improve this lesson?

Share this